lib/service/servicedvb.cpp: immediate show ttx subtitles instead of skip them when...
[enigma2.git] / tests / events.py
index 60dd4a5..dde84e2 100644 (file)
@@ -1,4 +1,5 @@
 import time
+import tests
 
 recorded_events = [ ]
 
@@ -24,15 +25,46 @@ def start_log():
        global base_time
        base_time = time.time()
 
-def end_log():
+def end_log(test_name):
        global base_time
+       
+       results = ""
+       
        for (t, self, method, args, kwargs) in get_events():
-               print "%s T+%f: %s::%s(%s, *%s, *%s)"  % (time.ctime(t), t - base_time, str(self.__class__), method, self, args, kwargs)
+               results += "%s T+%f: %s::%s(%s, *%s, *%s)\n"  % (time.ctime(t), t - base_time, str(self.__class__), method, self, args, kwargs)
 
-def log(fnc, base_time = 0, *args, **kwargs):
+       expected = None
+
+       try:
+               f = open(test_name + ".results", "rb")
+               expected = f.read()
+               f.close()
+       except:
+               print "NO TEST RESULT FOUND, creating new"
+               f = open(test_name + ".new_results", "wb")
+               f.write(results)
+               f.close()
+       
+       print results
+       
+       if expected is not None:
+               print "expected:"
+               if expected != results:
+                       open(test_name + ".bogus_results", "wb").write(results)
+                       raise tests.TestError("test data does not match")
+               else:
+                       print "test compared ok"
+       else:
+               print "no test data to compare with."
+
+def log(fnc, base_time = 0, test_name = "test", *args, **kwargs):
        import fake_time
        fake_time.setTime(base_time)
 
        start_log()
-       fnc(*args, **kwargs)
-       end_log()
+       try:
+               fnc(*args, **kwargs)
+               event(None, "test_completed", [], {"test_name": test_name})
+       except tests.TestError,c:
+               event(None, "test_failed", [], {"test_name": test_name, "reason": str(c)})
+       end_log(test_name)