Commits

astaric  committed 05936ca

Improved regression test.

  • Participants
  • Parent commits a14e130

Comments (0)

Files changed (1)

File Orange/testing/unit/tests/test_regression.py

     import unittest
 import subprocess
 
+import Orange
 from Orange.utils import environ
 from Orange.testing import testing
 
 
 class TestRegression(unittest.TestCase):
-
     PLATFORM = sys.platform
     PYVERSION = sys.version[:3]
     STATES = ["OK", "timedout", "changed", "random", "error", "crash"]
+    maxDiff = None
+
+    def __init__(self, methodName='runTest'):
+        super(TestRegression, self).__init__(methodName)
+        self.orange_dir = os.path.dirname(Orange.__file__)
+        self.orange_dir = os.path.join(self.orange_dir, '..')
+        self.orange_dir = os.path.realpath(self.orange_dir)
 
     def setUp(self):
-        pass
+        sys.path.append(self.orange_dir)
+
+    def tearDown(self):
+        del sys.path[-1]
 
     def test_regression_on(self, roottest, indir, outdir, name):
         for state in TestRegression.STATES:
 
         stdout, stderr = p.communicate()
         rv = stdout.strip().lower()
+        if rv == 'error':
+            self.assertEqual(stderr.split('\n'), [])
+        elif rv == 'changed':
+            expected_results = self.get_expected_results(outdir, name)
+            actual_results = self.get_actual_results(outdir, name)
+            self.assertEqual(actual_results, expected_results)
+
+
         self.assertEqual(rv, "ok", "Regression test %s: %s" % (rv, name) \
                         if stderr == "" else \
                         "Regression test %s: %s\n\n%s" % (rv, name, stderr))
         os.chdir(tmpdir)
 
+    def get_expected_results(self, outputdir, name):
+        expected_results = "%s/%s.%s.%s.txt" % (outputdir, name, sys.platform, sys.version[:3])
+        if not os.path.exists(expected_results):
+            expected_results = "%s/%s.%s.txt" % (outputdir, name, sys.platform)
+            if not os.path.exists(expected_results):
+                expected_results = "%s/%s.txt" % (outputdir, name)
+
+        with open(expected_results, 'r') as results:
+            return results.read().split('\n')
+
+    def get_actual_results(self, outputdir, name):
+        for state in TestRegression.STATES:
+            actual_results = "%s/%s.%s.%s.%s.txt" % (
+                outputdir, name, TestRegression.PLATFORM,
+                TestRegression.PYVERSION, state)
+
+            if os.path.exists(actual_results):
+                with open(actual_results, 'r') as results:
+                    return results.read().split('\n')
+
+
 root = os.path.normpath(os.path.join(environ.install_dir, ".."))
 roottest = os.path.join(root, "Orange/testing/regression")