[GRASS-SVN] r68183 - grass/trunk/lib/python/script/testsuite

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Mar 29 06:45:52 PDT 2016


Author: zarch
Date: 2016-03-29 06:45:51 -0700 (Tue, 29 Mar 2016)
New Revision: 68183

Modified:
   grass/trunk/lib/python/script/testsuite/test_utils.py
Log:
script.utils: change tests to avoid decorator

Modified: grass/trunk/lib/python/script/testsuite/test_utils.py
===================================================================
--- grass/trunk/lib/python/script/testsuite/test_utils.py	2016-03-29 09:23:26 UTC (rev 68182)
+++ grass/trunk/lib/python/script/testsuite/test_utils.py	2016-03-29 13:45:51 UTC (rev 68183)
@@ -7,30 +7,29 @@
 from grass.script import utils
 
 
-def change_environ(**envs):
+class EnvironChange(TestCase):
+    env = dict()
     NOT_FOUND = 'Not found!'
-    original_envs = {k: os.environ.get(k, NOT_FOUND) for k in envs.keys()}
 
-    def work_with_env(func):
-        def wrap_func(*args, **kwargs):
-            # modify the environment variables
-            for k, v in envs.items():
+    def setUp(self):
+        self.original_env = {k: os.environ.get(k, self.NOT_FOUND)
+                             for k in self.env.keys()}
+        for k, v in self.env.items():
                 os.environ[k] = v
 
-            # execute
-            func(*args, **kwargs)
-
-            # restore the environment variables
-            for k, v in envs.items():
-                oval = original_envs[k]
-                if oval == NOT_FOUND:
+    def tearDown(self):
+        for k, v in self.env.items():
+                oval = self.original_env[k]
+                if oval == self.NOT_FOUND:
                     os.environ.pop(k)
                 else:
                     os.environ[k] = oval
-        return wrap_func
-    return work_with_env
 
 
+class LcAllC(EnvironChange):
+    env = dict(LC_ALL='C')
+
+
 class TestEncode(TestCase):
     """Tests function `encode` that convert value to bytes."""
 
@@ -40,15 +39,7 @@
     def test_unicode(self):
         self.assertEqual(b'text', utils.encode(u'text'))
 
-    @change_environ(LC_ALL='C')
-    def test_bytes_LC_ALL_C(self):
-        self.assertEqual(b'text', utils.encode(b'text'))
 
-    @change_environ(LC_ALL='C')
-    def test_unicode_LC_ALL_C(self):
-        self.assertEqual(b'text', utils.encode(u'text'))
-
-
 class TestDecode(TestCase):
     """Tests function `encode` that convert value to unicode."""
 
@@ -58,16 +49,14 @@
     def test_unicode(self):
         self.assertEqual(u'text', utils.decode(u'text'))
 
-    @change_environ(LC_ALL='C')
-    def test_bytes_LC_ALL_C(self):
-        self.assertEqual(u'text', utils.decode(b'text'))
 
-    @change_environ(LC_ALL='C')
-    def test_unicode_LC_ALL_C(self):
-        self.assertEqual(u'text', utils.decode(u'text'))
+class TestEncodeLcAllC(TestEncode, LcAllC):
+    pass
 
 
+class TestDecodeLcAllC(TestDecode, LcAllC):
+    pass
 
 
 if __name__ == '__main__':
-    test()
\ No newline at end of file
+    test()



More information about the grass-commit mailing list