[GRASS-SVN] r68356 - in grass/trunk/lib/python/gunittest: . testsuite/data/samplecode testsuite/data/samplecode/submodule_errors testsuite/data/samplecode/submodule_errors/subsubmodule_errors testsuite/data/samplecode/submodule_errors/subsubmodule_exiting testsuite/data/samplecode/submodule_test_fail testsuite/data/samplecode/testsuite

svn_grass at osgeo.org svn_grass at osgeo.org
Mon May 2 09:08:00 PDT 2016


Author: zarch
Date: 2016-05-02 09:08:00 -0700 (Mon, 02 May 2016)
New Revision: 68356

Modified:
   grass/trunk/lib/python/gunittest/case.py
   grass/trunk/lib/python/gunittest/checkers.py
   grass/trunk/lib/python/gunittest/multireport.py
   grass/trunk/lib/python/gunittest/reporters.py
   grass/trunk/lib/python/gunittest/testsuite/data/samplecode/fake_code.py
   grass/trunk/lib/python/gunittest/testsuite/data/samplecode/submodule_errors/fake_code.py
   grass/trunk/lib/python/gunittest/testsuite/data/samplecode/submodule_errors/subsubmodule_errors/fake_code.py
   grass/trunk/lib/python/gunittest/testsuite/data/samplecode/submodule_errors/subsubmodule_exiting/fake_code.py
   grass/trunk/lib/python/gunittest/testsuite/data/samplecode/submodule_test_fail/fake_code.py
   grass/trunk/lib/python/gunittest/testsuite/data/samplecode/testsuite/test_python_unittest.py
   grass/trunk/lib/python/gunittest/testsuite/data/samplecode/testsuite/test_success.py
Log:
gunittest: update syntax to be python3 ready

Modified: grass/trunk/lib/python/gunittest/case.py
===================================================================
--- grass/trunk/lib/python/gunittest/case.py	2016-05-02 16:07:43 UTC (rev 68355)
+++ grass/trunk/lib/python/gunittest/case.py	2016-05-02 16:08:00 UTC (rev 68356)
@@ -183,9 +183,9 @@
 
         See :func:`check_text_ellipsis` for details of behavior.
         """
-        self.assertTrue(isinstance(actual, basestring), (
+        self.assertTrue(isinstance(actual, str), (
                         'actual argument is not a string'))
-        self.assertTrue(isinstance(reference, basestring), (
+        self.assertTrue(isinstance(reference, str), (
                         'reference argument is not a string'))
         if os.linesep != '\n' and os.linesep in actual:
             actual = actual.replace(os.linesep, '\n')
@@ -220,7 +220,7 @@
         The output of the module should be key-value pairs (shell script style)
         which is typically obtained using ``-g`` flag.
         """
-        if isinstance(reference, basestring):
+        if isinstance(reference, str):
             reference = text_to_keyvalue(reference, sep=sep, skip_empty=True)
         module = _module_from_parameters(module, **parameters)
         self.runModule(module, expecting_stdout=True)
@@ -1194,13 +1194,13 @@
 # some test and documentation add to assertModuleKeyValue
 def _module_from_parameters(module, **kwargs):
     if kwargs:
-        if not isinstance(module, basestring):
+        if not isinstance(module, str):
             raise ValueError('module can be only string or PyGRASS Module')
         if isinstance(module, Module):
             raise ValueError('module can be only string if other'
                              ' parameters are given')
             # allow passing all parameters in one dictionary called parameters
-        if kwargs.keys() == ['parameters']:
+        if list(kwargs.keys()) == ['parameters']:
             kwargs = kwargs['parameters']
         module = SimpleModule(module, **kwargs)
     return module

Modified: grass/trunk/lib/python/gunittest/checkers.py
===================================================================
--- grass/trunk/lib/python/gunittest/checkers.py	2016-05-02 16:07:43 UTC (rev 68355)
+++ grass/trunk/lib/python/gunittest/checkers.py	2016-05-02 16:08:00 UTC (rev 68356)
@@ -82,14 +82,14 @@
     dic = dict(dic)
     for l in lookup:
         import types
-        if not isinstance(dic['unit'], types.StringTypes):
+        if not isinstance(dic['unit'], str):
             for n in range(len(dic['unit'])):
                 if dic['unit'][n] in l:
                     dic['unit'][n] = l[0]
         else:
             if dic['unit'] in l:
                 dic['unit'] = l[0]
-        if not isinstance(dic['units'], types.StringTypes):
+        if not isinstance(dic['units'], str):
             for n in range(len(dic['units'])):
                 if dic['units'][n] in l:
                     dic['units'][n] = l[0]

Modified: grass/trunk/lib/python/gunittest/multireport.py
===================================================================
--- grass/trunk/lib/python/gunittest/multireport.py	2016-05-02 16:07:43 UTC (rev 68355)
+++ grass/trunk/lib/python/gunittest/multireport.py	2016-05-02 16:08:00 UTC (rev 68356)
@@ -400,7 +400,7 @@
             all_results.append(result)
             del result
         except KeyError as e:
-            print 'File %s does not have right values (%s)' % (report, e.message) 
+            print('File %s does not have right values (%s)' % (report, e.message)) 
 
     locations_main_page = open(os.path.join(output, 'index.html'), 'w')
     locations_main_page.write(
@@ -420,7 +420,7 @@
     plot_style = PlotStyle(linestyle='-', linewidth=4.0,
                            success_color='g', fail_color='r', total_color='b')
 
-    for location_type, results in results_in_locations.iteritems():
+    for location_type, results in results_in_locations.items():
         results = sorted(results, key=operator.attrgetter('timestamp'))
         # TODO: document: location type must be a valid dir name
         directory = os.path.join(output, location_type)

Modified: grass/trunk/lib/python/gunittest/reporters.py
===================================================================
--- grass/trunk/lib/python/gunittest/reporters.py	2016-05-02 16:07:43 UTC (rev 68355)
+++ grass/trunk/lib/python/gunittest/reporters.py	2016-05-02 16:08:00 UTC (rev 68356)
@@ -26,7 +26,6 @@
     from StringIO import StringIO
 else:
     from io import StringIO
-    basestring = str
 
 
 # TODO: change text_to_keyvalue to same sep as here
@@ -38,7 +37,7 @@
     items = []
     for key, value in keyvalue.items():
         # TODO: use isep for iterables other than strings
-        if (not isinstance(value, basestring)
+        if (not isinstance(value, str)
                 and isinstance(value, collections.Iterable)):
             # TODO: this does not work for list of non-strings
             value = isep.join(value)

Modified: grass/trunk/lib/python/gunittest/testsuite/data/samplecode/fake_code.py
===================================================================
--- grass/trunk/lib/python/gunittest/testsuite/data/samplecode/fake_code.py	2016-05-02 16:07:43 UTC (rev 68355)
+++ grass/trunk/lib/python/gunittest/testsuite/data/samplecode/fake_code.py	2016-05-02 16:08:00 UTC (rev 68356)
@@ -1 +1 @@
-print "This is file (%s) should not run." % __file__
+print("This is file (%s) should not run." % __file__)

Modified: grass/trunk/lib/python/gunittest/testsuite/data/samplecode/submodule_errors/fake_code.py
===================================================================
--- grass/trunk/lib/python/gunittest/testsuite/data/samplecode/submodule_errors/fake_code.py	2016-05-02 16:07:43 UTC (rev 68355)
+++ grass/trunk/lib/python/gunittest/testsuite/data/samplecode/submodule_errors/fake_code.py	2016-05-02 16:08:00 UTC (rev 68356)
@@ -1 +1 @@
-print "This is file (%s) should not run." % __file__
+print("This is file (%s) should not run." % __file__)

Modified: grass/trunk/lib/python/gunittest/testsuite/data/samplecode/submodule_errors/subsubmodule_errors/fake_code.py
===================================================================
--- grass/trunk/lib/python/gunittest/testsuite/data/samplecode/submodule_errors/subsubmodule_errors/fake_code.py	2016-05-02 16:07:43 UTC (rev 68355)
+++ grass/trunk/lib/python/gunittest/testsuite/data/samplecode/submodule_errors/subsubmodule_errors/fake_code.py	2016-05-02 16:08:00 UTC (rev 68356)
@@ -1 +1 @@
-print "This is file (%s) should not run." % __file__
+print("This is file (%s) should not run." % __file__)

Modified: grass/trunk/lib/python/gunittest/testsuite/data/samplecode/submodule_errors/subsubmodule_exiting/fake_code.py
===================================================================
--- grass/trunk/lib/python/gunittest/testsuite/data/samplecode/submodule_errors/subsubmodule_exiting/fake_code.py	2016-05-02 16:07:43 UTC (rev 68355)
+++ grass/trunk/lib/python/gunittest/testsuite/data/samplecode/submodule_errors/subsubmodule_exiting/fake_code.py	2016-05-02 16:08:00 UTC (rev 68356)
@@ -1 +1 @@
-print "This is file (%s) should not run." % __file__
+print("This is file (%s) should not run." % __file__)

Modified: grass/trunk/lib/python/gunittest/testsuite/data/samplecode/submodule_test_fail/fake_code.py
===================================================================
--- grass/trunk/lib/python/gunittest/testsuite/data/samplecode/submodule_test_fail/fake_code.py	2016-05-02 16:07:43 UTC (rev 68355)
+++ grass/trunk/lib/python/gunittest/testsuite/data/samplecode/submodule_test_fail/fake_code.py	2016-05-02 16:08:00 UTC (rev 68356)
@@ -1 +1 @@
-print "This is file (%s) should not run." % __file__
+print("This is file (%s) should not run." % __file__)

Modified: grass/trunk/lib/python/gunittest/testsuite/data/samplecode/testsuite/test_python_unittest.py
===================================================================
--- grass/trunk/lib/python/gunittest/testsuite/data/samplecode/testsuite/test_python_unittest.py	2016-05-02 16:07:43 UTC (rev 68355)
+++ grass/trunk/lib/python/gunittest/testsuite/data/samplecode/testsuite/test_python_unittest.py	2016-05-02 16:08:00 UTC (rev 68356)
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-
+from __furute__ import print_function
 from unittest import TestCase, main
 
 
@@ -7,10 +7,10 @@
     # pylint: disable=R0904
 
     def setUp(self):
-        print "print from setUp"
+        print("print from setUp")
 
     def tearDown(self):
-        print "print from tearDown"
+        print("print from tearDown")
 
     def test_something(self):
         self.assertTrue(True, msg="This should not fail")
@@ -24,11 +24,11 @@
 
     @classmethod
     def setUpClass(cls):
-        print "print from setUpClass"
+        print("print from setUpClass")
 
     @classmethod
     def tearDownClass(cls):
-        print "print from tearDownClass"
+        print("print from tearDownClass")
 
     def test_something(self):
         self.assertTrue(True, msg="This should not fail")

Modified: grass/trunk/lib/python/gunittest/testsuite/data/samplecode/testsuite/test_success.py
===================================================================
--- grass/trunk/lib/python/gunittest/testsuite/data/samplecode/testsuite/test_success.py	2016-05-02 16:07:43 UTC (rev 68355)
+++ grass/trunk/lib/python/gunittest/testsuite/data/samplecode/testsuite/test_success.py	2016-05-02 16:08:00 UTC (rev 68356)
@@ -1,4 +1,5 @@
 # -*- coding: utf-8 -*-
+from __future__ import print_function
 
 from grass.gunittest.case import TestCase
 from grass.gunittest.main import test
@@ -8,10 +9,10 @@
     # pylint: disable=R0904
 
     def setUp(self):
-        print "print from setUp"
+        print("print from setUp")
 
     def tearDown(self):
-        print "print from tearDown"
+        print("print from tearDown")
 
     def test_something(self):
         self.assertTrue(True)
@@ -22,11 +23,11 @@
 
     @classmethod
     def setUpClass(cls):
-        print "print from setUpClass"
+        print("print from setUpClass")
 
     @classmethod
     def tearDownClass(cls):
-        print "print from tearDownClass"
+        print("print from tearDownClass")
 
     def test_something(self):
         self.assertTrue(True)



More information about the grass-commit mailing list