Browse Source

script.array: make it into real doctest

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@64831 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 10 năm trước cách đây
mục cha
commit
fce2f868e7
2 tập tin đã thay đổi với 42 bổ sung6 xóa
  1. 4 6
      lib/python/script/array.py
  2. 38 0
      lib/python/script/testsuite/test_doctests.py

+ 4 - 6
lib/python/script/array.py

@@ -29,7 +29,6 @@ Usage:
 >>> # 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 @@ Usage:
  [ 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 @@ Usage:
   [  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 @@ Usage:
 >>> # 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 @@ Loading floating point data with 8 bytes ... (6x4x3)
   [ 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

+ 38 - 0
lib/python/script/testsuite/test_doctests.py

@@ -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()