]> git.parisson.com Git - timeside.git/commitdiff
Test: Add test to check processor parameters (Traits)
authorThomas Fillon <thomas@parisson.com>
Tue, 20 Jan 2015 12:58:54 +0000 (13:58 +0100)
committerThomas Fillon <thomas@parisson.com>
Tue, 20 Jan 2015 12:58:54 +0000 (13:58 +0100)
tests/run_all_tests
tests/test_check_processors.py [new file with mode: 0644]
tests/unit_timeside.py

index 34da6c2b9e3635ee2bab37c21acff77b57dffc7a..0e5914c95a2899326397ed6249464a830dae49f8 100755 (executable)
@@ -2,7 +2,6 @@
 import os
 import sys
 
-
 def load_test():
     # get relevant files
     curdir = os.path.dirname(sys.argv[0])
diff --git a/tests/test_check_processors.py b/tests/test_check_processors.py
new file mode 100644 (file)
index 0000000..ab00a07
--- /dev/null
@@ -0,0 +1,59 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+
+
+# Author : Thomas Fillon <thomas at parisson.com>
+
+
+from unit_timeside import unittest, TestRunner
+import timeside.core
+import inspect
+
+
+class TestCheckProcessorsParam(unittest.TestCase):
+    def _check_param_test(self, processor_cls):
+        """Internal function that test if a given processor
+        has Trait parameters as __init__ arguments"""
+
+        argspec = inspect.getargspec(processor_cls.__init__)
+        argspec.args.remove('self')  # remove 'self' from arguments list
+
+        #print argspec.args
+        traits_parameters = processor_cls._Param().editable_traits()
+        #print traits_parameters
+        self.assertSetEqual(set(argspec.args), set(traits_parameters))
+
+
+def _tests_factory(test_class, test_doc, list_processors, skip_reasons={}):
+    """Define a test for each analyzer provided in the list"""
+    for proc in list_processors:
+
+        def test_func_factory(proc):
+            test_func = lambda self: self._check_param_test(proc)
+            test_func.__doc__ = test_doc % proc.__name__
+            return test_func
+
+        test_func_name = "test_%s" % proc.__name__
+        test_func = test_func_factory(proc)
+
+        if proc.__name__ not in skip_reasons:
+            setattr(test_class, test_func_name, test_func)
+        else:  # Decorate with unittest.skip to skip test
+            setattr(test_class, test_func_name,
+                    unittest.skip(skip_reasons[proc.__name__])(test_func))
+
+
+# Define test to skip and corresponding reasons
+skip_reasons = {}
+
+# For each processor in TimeSide, test with constant input
+list_processors = timeside.core.processor.processors(timeside.core.api.IAnalyzer)
+
+_tests_factory(test_class=TestCheckProcessorsParam,
+               test_doc="Check processor %s parameters validity as Traits",
+               list_processors=list_processors,
+               skip_reasons=skip_reasons)
+
+
+if __name__ == '__main__':
+    unittest.main(testRunner=TestRunner())
index 2a985c570b274f8f2045a460cdfa7da0e0870f02..d985a197495c7f0d3d56bd9492e82710f5c51ef1 100644 (file)
@@ -5,6 +5,7 @@ import doctest
 import sys
 import time
 
+import timeside.core
 
 class _TextTestResult(unittest.TestResult):
     """A test result class that can print formatted text results to a stream.