瀏覽代碼

pygrass: add new tests, specially doctests

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@61991 15284696-431f-4ddb-bdfa-cd5b030d7da7
Luca Delucchi 10 年之前
父節點
當前提交
bd83b689b6

+ 39 - 0
lib/python/pygrass/gis/testsuite/test_doctests.py

@@ -0,0 +1,39 @@
+# -*- coding: utf-8 -*-
+"""
+Tests checkers
+"""
+
+import doctest
+
+import grass.gunittest
+import grass.gunittest.utils
+
+import grass.pygrass.gis as pgrass
+
+
+# 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(pgrass))
+    tests.addTests(doctest.DocTestSuite(pgrass.region))
+    return tests
+
+
+if __name__ == '__main__':
+    grass.gunittest.test()

+ 24 - 0
lib/python/pygrass/gis/testsuite/test_gis.py

@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+"""
+Luca Delucchi
+"""
+
+from grass.gunittest import TestCase, test
+
+from grass.pygrass.gis.region import Region
+
+
+class RegionTestCate(TestCase):
+
+    def test_bounds(self):
+        reg1 = Region()
+        reg2 = Region()
+        self.assertTrue(reg1, reg2)
+        north = reg2.north
+        reg2.north = 0
+        self.assertNotEqual(reg1.north, reg2.north)
+        reg2.north = north
+
+
+if __name__ == '__main__':
+    test()

+ 38 - 0
lib/python/pygrass/messages/testsuite/test_doctests.py

@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+"""
+Tests checkers
+"""
+
+import doctest
+
+import grass.gunittest
+import grass.gunittest.utils
+
+import grass.pygrass.messages as gmessages
+
+
+# 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(gmessages))
+    return tests
+
+
+if __name__ == '__main__':
+    grass.gunittest.test()

+ 38 - 0
lib/python/pygrass/modules/grid/testsuite/test_doctests.py

@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+"""
+Tests checkers
+"""
+
+import doctest
+
+import grass.gunittest
+import grass.gunittest.utils
+
+import grass.pygrass.modules as gmodules
+
+
+# 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()
+
+    tests.addTests(doctest.DocTestSuite(gmodules.shortcuts))
+    return tests
+
+
+if __name__ == '__main__':
+    grass.gunittest.test()

+ 41 - 0
lib/python/pygrass/modules/interface/testsuite/test_doctests.py

@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+"""
+Tests checkers
+"""
+
+import doctest
+
+import grass.gunittest
+import grass.gunittest.utils
+
+import grass.pygrass.modules as gmodules
+
+
+# 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(gmodules.interface.flag))
+    tests.addTests(doctest.DocTestSuite(gmodules.interface.module))
+    tests.addTests(doctest.DocTestSuite(gmodules.interface.parameter))
+
+    return tests
+
+
+if __name__ == '__main__':
+    grass.gunittest.test()

+ 42 - 0
lib/python/pygrass/modules/testsuite/test_doctests.py

@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+"""
+Tests checkers
+"""
+
+import doctest
+
+import grass.gunittest
+import grass.gunittest.utils
+
+import grass.pygrass.modules as gmodules
+
+
+# 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(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))
+    return tests
+
+
+if __name__ == '__main__':
+    grass.gunittest.test()

文件差異過大導致無法顯示
+ 1832 - 0
lib/python/pygrass/raster/testsuite/data/geology_cats


+ 45 - 0
lib/python/pygrass/raster/testsuite/test_category.py

@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Mon Sep 15 17:09:40 2014
+
+@author: lucadelu
+"""
+
+from grass.gunittest import TestCase, test
+
+from grass.pygrass.raster import RasterRow
+from grass.pygrass.raster.category import Category
+from grass.script.core import tempfile
+
+
+class RasterCategoryTestCate(TestCase):
+
+    name = 'geology'
+    catsname = ''
+
+    def testCategory(self):
+        r = RasterRow(self.name)
+        r.open()
+        cats = r.cats
+        cats1 = Category(self.name)
+        cats1.read()
+        # this is not working, I don't know why
+        self.assertEqual(cats, cats1)
+        r.close()
+
+    def testFirstCat(self):
+        cat0 = ('Zml', 1, None)
+        cats = Category(self.name)
+        cats.read()
+        self.assertEqual(cats[0], cat0)
+
+    def testWrite(self):
+        tmpfile = tempfile(False)
+        cats = Category(self.name)
+        cats.read()
+        cats.write_rules(tmpfile)
+        self.assertFilesEqualMd5(tmpfile, 'data/geology_cats')
+
+
+if __name__ == '__main__':
+    test()

+ 41 - 0
lib/python/pygrass/raster/testsuite/test_doctests.py

@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+"""
+Tests checkers
+"""
+
+import doctest
+
+import grass.gunittest
+import grass.gunittest.utils
+
+import grass.pygrass.raster as pgrass
+
+
+# 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(pgrass))
+    tests.addTests(doctest.DocTestSuite(pgrass.abstract))
+    tests.addTests(doctest.DocTestSuite(pgrass.category))
+    tests.addTests(doctest.DocTestSuite(pgrass.history))
+    return tests
+
+
+if __name__ == '__main__':
+    grass.gunittest.test()

+ 33 - 0
lib/python/pygrass/raster/testsuite/test_history.py

@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Mon Sep 15 17:09:40 2014
+
+@author: lucadelu
+"""
+
+from grass.gunittest import TestCase, test
+
+from grass.pygrass.raster import RasterRow
+from grass.pygrass.raster.history import History
+
+
+class RasterHistoryTestCate(TestCase):
+
+    name = 'geology'
+
+    def testHistory(self):
+        r = RasterRow(self.name)
+        r.open()
+        hist = r.hist
+        hist1 = History(self.name)
+        hist1.read()
+        # this is not working, I don't know why
+        #self.assertEqual(hist, hist1)
+        self.assertEqual(hist.creator, hist1.creator)
+        hist1.creator = 'markus'
+        self.assertNotEqual(hist.creator, hist1.creator)
+        r.close()
+
+
+if __name__ == '__main__':
+    test()

+ 41 - 0
lib/python/pygrass/raster/testsuite/test_raster.py

@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Mon Sep 15 13:37:24 2014
+
+@author: lucadelu
+"""
+
+from grass.gunittest import TestCase, test
+
+from grass.pygrass.raster import RasterRow
+
+
+class RasterRowTestCate(TestCase):
+
+    name = 'elevation'
+
+    def test_type(self):
+        eletype = 'FCELL'
+        r = RasterRow(self.name)
+        r.open()
+        self.assertTrue(r.mtype, eletype)
+        r.close()
+
+    def test_isopen(self):
+        r = RasterRow(self.name)
+        self.assertFalse(r.is_open())
+        r.open()
+        self.assertTrue(r.is_open())
+        r.close()
+
+    def test_name(self):
+        r = RasterRow(self.name)
+        r.open()
+        self.assertEqual(r.name, self.name)
+        fullname = "{name}@{mapset}".format(name=r.name, mapset=r.mapset)
+        self.assertEqual(r.fullname(), fullname)
+        r.close()
+
+
+if __name__ == '__main__':
+    test()

+ 39 - 0
lib/python/pygrass/shell/testsuite/test_doctests.py

@@ -0,0 +1,39 @@
+# -*- coding: utf-8 -*-
+"""
+Tests checkers
+"""
+
+import doctest
+
+import grass.gunittest
+import grass.gunittest.utils
+
+import grass.pygrass.shell as gshell
+
+
+# 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(gshell.conversion))
+    tests.addTests(doctest.DocTestSuite(gshell.show))
+    return tests
+
+
+if __name__ == '__main__':
+    grass.gunittest.test()

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

@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+"""
+Tests checkers
+"""
+
+import doctest
+
+import grass.gunittest
+import grass.gunittest.utils
+
+import grass.pygrass.functions as gfunctions
+
+
+# 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(gfunctions))
+    return tests
+
+
+if __name__ == '__main__':
+    grass.gunittest.test()

+ 44 - 0
lib/python/pygrass/vector/testsuite/test_doctests.py

@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+"""
+Tests checkers
+"""
+
+import doctest
+
+import grass.gunittest
+import grass.gunittest.utils
+
+import grass.pygrass.vector as gvector
+
+
+# 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(gvector))
+    tests.addTests(doctest.DocTestSuite(gvector.abstract))
+    tests.addTests(doctest.DocTestSuite(gvector.basic))
+    tests.addTests(doctest.DocTestSuite(gvector.find))
+    tests.addTests(doctest.DocTestSuite(gvector.geometry))
+    tests.addTests(doctest.DocTestSuite(gvector.sql))
+    tests.addTests(doctest.DocTestSuite(gvector.table))
+    return tests
+
+
+if __name__ == '__main__':
+    grass.gunittest.test()