Kaynağa Gözat

pygrass: fix modules doctests and make the tests indipendent from the mapset/location name

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@65943 15284696-431f-4ddb-bdfa-cd5b030d7da7
Pietro Zambelli 9 yıl önce
ebeveyn
işleme
d487c5340b

+ 16 - 10
lib/python/pygrass/modules/grid/grid.py

@@ -69,20 +69,22 @@ def copy_mapset(mapset, path):
     :returns: the instance of the new Mapset.
 
 
+    >>> from grass.script.core import gisenv
+    >>> mname = gisenv()['MAPSET']
     >>> mset = Mapset()
-    >>> mset.name
-    'user1'
+    >>> mset.name == mname
+    True
     >>> import tempfile as tmp
     >>> import os
     >>> path = os.path.join(tmp.gettempdir(), 'my_loc', 'my_mset')
-    >>> copy_mapset(mset, path)
-    Mapset('user1')
-    >>> sorted(os.listdir(path))
-    [u'PERMANENT', u'user1']
+    >>> copy_mapset(mset, path)                           # doctest: +ELLIPSIS
+    Mapset(...)
+    >>> sorted(os.listdir(path))                          # doctest: +ELLIPSIS
+    [...'PERMANENT'...]
     >>> sorted(os.listdir(os.path.join(path, 'PERMANENT')))
     [u'DEFAULT_WIND', u'PROJ_INFO', u'PROJ_UNITS', u'VAR', u'WIND']
-    >>> sorted(os.listdir(os.path.join(path, 'user1'))) # doctest: +ELLIPSIS
-    [...u'SEARCH_PATH', u'VAR', u'WIND']
+    >>> sorted(os.listdir(os.path.join(path, mname)))   # doctest: +ELLIPSIS
+    [...u'SEARCH_PATH',...u'WIND']
     >>> import shutil
     >>> shutil.rmtree(path)
 
@@ -110,8 +112,12 @@ def read_gisrc(gisrc):
     :returns: a tuple with the mapset, location and gisdbase
 
     >>> import os
-    >>> read_gisrc(os.environ['GISRC'])  # doctest: +ELLIPSIS
-    (u'user1', ...)
+    >>> from grass.script.core import gisenv
+    >>> genv = gisenv()
+    >>> (read_gisrc(os.environ['GISRC']) == (genv['MAPSET'],
+    ...                                      genv['LOCATION_NAME'],
+    ...                                      genv['GISDBASE']))
+    True
     """
     with open(gisrc, 'r') as gfile:
         gis = dict([(k.strip(), v.strip())

+ 2 - 1
lib/python/pygrass/modules/shortcuts.py

@@ -21,11 +21,12 @@ class MetaModule(object):
        >>> g_list.required
        ['type']
        >>> g_list.inputs.type = 'raster'
+       >>> g_list.inputs.mapset = 'PERMANENT'
        >>> g_list.stdout_ = -1
        >>> g_list.run()
        Module('g.list')
        >>> g_list.outputs.stdout                         # doctest: +ELLIPSIS
-       '...basins...soils...'
+       '...basin...soils...'
        >>> r = MetaModule('r')
        >>> what = r.what
        >>> what.description

+ 6 - 6
lib/python/pygrass/modules/testsuite/test_doctests.py

@@ -9,7 +9,7 @@ import grass.gunittest.case
 import grass.gunittest.main
 import grass.gunittest.utils
 
-import grass.pygrass.modules as gmodules
+from grass.pygrass.modules import shortcuts, grid, interface
 
 
 # doctest does not allow changing the base classes of test case, skip test case
@@ -31,11 +31,11 @@ def load_tests(loader, tests, ignore):
     # for now it is the only place where it works
     grass.gunittest.utils.do_doctest_gettext_workaround()
     # this should be called at some top level
-    tests.addTests(doctest.DocTestSuite(gmodules.interface))
-    tests.addTests(doctest.DocTestSuite(gmodules.grid.grid))
-    tests.addTests(doctest.DocTestSuite(gmodules.grid.patch))
-    tests.addTests(doctest.DocTestSuite(gmodules.grid.split))
-    tests.addTests(doctest.DocTestSuite(gmodules.shortcuts))
+    tests.addTests(doctest.DocTestSuite(interface))
+    tests.addTests(doctest.DocTestSuite(grid.grid))
+    tests.addTests(doctest.DocTestSuite(grid.patch))
+    tests.addTests(doctest.DocTestSuite(grid.split))
+    tests.addTests(doctest.DocTestSuite(shortcuts))
     return tests