[GRASS-SVN] r64831 - in grass/trunk/lib/python/script: . testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Mar 10 07:49:46 PDT 2015
Author: annakrat
Date: 2015-03-10 07:49:46 -0700 (Tue, 10 Mar 2015)
New Revision: 64831
Added:
grass/trunk/lib/python/script/testsuite/test_doctests.py
Modified:
grass/trunk/lib/python/script/array.py
Log:
script.array: make it into real doctest
Modified: grass/trunk/lib/python/script/array.py
===================================================================
--- grass/trunk/lib/python/script/array.py 2015-03-10 14:23:00 UTC (rev 64830)
+++ grass/trunk/lib/python/script/array.py 2015-03-10 14:49:46 UTC (rev 64831)
@@ -29,7 +29,6 @@
>>> # This will write the numpy array as GRASS raster map
... # with name map2d_1
... map2d_1.write(mapname="map2d_1", overwrite=True)
- 100%
0
>>>
>>> # We create a new array and read map2d_1 to modify it
@@ -47,7 +46,6 @@
[ 0. 1. 2. 0. 1. 2.]]
>>> # Write the result as new raster map with name map2d_2
... map2d_2.write(mapname="map2d_2", overwrite=True)
- 100%
0
>>>
>>> # Here we create a 3D raster map numpy array
@@ -67,10 +65,12 @@
[ 1. 2. 3. 4. 5. 6.]
[ 2. 3. 4. 5. 6. 7.]
[ 3. 4. 5. 6. 7. 8.]]
+<BLANKLINE>
[[ 1. 2. 3. 4. 5. 6.]
[ 2. 3. 4. 5. 6. 7.]
[ 3. 4. 5. 6. 7. 8.]
[ 4. 5. 6. 7. 8. 9.]]
+<BLANKLINE>
[[ 2. 3. 4. 5. 6. 7.]
[ 3. 4. 5. 6. 7. 8.]
[ 4. 5. 6. 7. 8. 9.]
@@ -78,8 +78,6 @@
>>> # This will write the numpy array as GRASS 3D raster map
... # with name map3d_1
... map3d_1.write(mapname="map3d_1", overwrite=True)
-Loading floating point data with 8 bytes ... (6x4x3)
- 100%
0
>>> # We create a new 3D array and read map3d_1 to modify it
... map3d_2 = garray.array3d()
@@ -94,18 +92,18 @@
[ 1. 2. 0. 1. 2. 0.]
[ 2. 0. 1. 2. 0. 1.]
[ 0. 1. 2. 0. 1. 2.]]
+<BLANKLINE>
[[ 1. 2. 0. 1. 2. 0.]
[ 2. 0. 1. 2. 0. 1.]
[ 0. 1. 2. 0. 1. 2.]
[ 1. 2. 0. 1. 2. 0.]]
+<BLANKLINE>
[[ 2. 0. 1. 2. 0. 1.]
[ 0. 1. 2. 0. 1. 2.]
[ 1. 2. 0. 1. 2. 0.]
[ 2. 0. 1. 2. 0. 1.]]]
>>> # Write the result as new 3D raster map with name map3d_2
... map3d_2.write(mapname="map3d_2", overwrite=True)
-Loading floating point data with 8 bytes ... (6x4x3)
- 100%
0
(C) 2010-2012 by Glynn Clements and the GRASS Development Team
Added: grass/trunk/lib/python/script/testsuite/test_doctests.py
===================================================================
--- grass/trunk/lib/python/script/testsuite/test_doctests.py (rev 0)
+++ grass/trunk/lib/python/script/testsuite/test_doctests.py 2015-03-10 14:49:46 UTC (rev 64831)
@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+"""
+Tests checkers
+"""
+
+import doctest
+
+import grass.gunittest
+import grass.gunittest.utils
+
+import grass.script.array as garray
+
+
+# doctest does not allow changing the base classes of test case, skip test case
+# and test suite, so we need to create a new type which inherits from our class
+# and contains doctest's methods
+# the alternative is to copy 500 from doctest and change what is needed
+# (this might be necessary anyway beacuse of the reports and stdout and stderr)
+doctest.DocFileCase = type('DocFileCase',
+ (grass.gunittest.TestCase,),
+ dict(doctest.DocFileCase.__dict__))
+doctest.SkipDocTestCase = type('SkipDocTestCase',
+ (grass.gunittest.TestCase,),
+ dict(doctest.SkipDocTestCase.__dict__))
+
+
+def load_tests(loader, tests, ignore):
+ # TODO: this must be somewhere when doctest is called, not here
+ # TODO: ultimate solution is not to use _ as a buildin in lib/python
+ # 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(garray))
+ return tests
+
+
+if __name__ == '__main__':
+ grass.gunittest.test()
More information about the grass-commit
mailing list