[GRASS-SVN] r65592 - grass/trunk/lib/python/pygrass/modules/testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jul 15 01:01:09 PDT 2015
Author: zarch
Date: 2015-07-15 01:01:09 -0700 (Wed, 15 Jul 2015)
New Revision: 65592
Added:
grass/trunk/lib/python/pygrass/modules/testsuite/test_import_isolation.py
Log:
pygrass: Add test to verify isolation of pygrass.modules.* from ctypes, thank you to Vaclav to share ideas
Added: grass/trunk/lib/python/pygrass/modules/testsuite/test_import_isolation.py
===================================================================
--- grass/trunk/lib/python/pygrass/modules/testsuite/test_import_isolation.py (rev 0)
+++ grass/trunk/lib/python/pygrass/modules/testsuite/test_import_isolation.py 2015-07-15 08:01:09 UTC (rev 65592)
@@ -0,0 +1,53 @@
+# -*- coding: utf-8 -*-
+"""
+Authors: pietro
+
+Copyright: (C) 2015 pietro
+
+ This program is free software under the GNU General Public
+ License (>=v2). Read the file COPYING that comes with GRASS
+ for details.
+
+Created on Wed Jul 15 11:34:32 2015
+"""
+from __future__ import absolute_import
+
+import sys
+import fnmatch
+
+from grass.gunittest.case import TestCase
+from grass.gunittest.main import test
+
+
+def check(*patterns):
+ """Return a set of the imported libraries that soddisfies several patterns.
+ """
+ result = []
+ imports = sorted(sys.modules.keys())
+ for pattern in patterns:
+ result.extend(fnmatch.filter(imports, pattern))
+ return set(result)
+
+
+class TestImportIsolation(TestCase):
+ patterns = ['grass.lib*']
+
+ def test_import_isolation(self):
+ """Check that modules classes are not using ctypes"""
+ isolate = set()
+ self.assertEqual(isolate, check(*self.patterns),
+ msg="Test isolation before any import.")
+ # same import done in __init__ file
+ from grass.pygrass.modules.interface import Module, ParallelModuleQueue
+ from grass.pygrass.modules import shortcuts
+ self.assertEqual(isolate, check(*self.patterns),
+ msg="Test isolation after import Module.")
+ # test the other way round
+ from grass.pygrass.vector import VectorTopo
+ self.assertNotEqual(isolate, check(*self.patterns),
+ msg=("Test the isolation is broken, therefore "
+ "the defined patterns are correct"))
+
+
+if __name__ == '__main__':
+ test()
Property changes on: grass/trunk/lib/python/pygrass/modules/testsuite/test_import_isolation.py
___________________________________________________________________
Added: svn:mime-type
+ text/x-python
Added: svn:eol-style
+ native
More information about the grass-commit
mailing list