[MOAB-dev] r2931 - in MOAB/trunk/tools/iMesh/python: . pkg test

jvporter at wisc.edu jvporter at wisc.edu
Fri Jun 5 01:16:37 CDT 2009


Author: jvporter
Date: 2009-06-05 01:16:36 -0500 (Fri, 05 Jun 2009)
New Revision: 2931

Added:
   MOAB/trunk/tools/iMesh/python/pkg/
   MOAB/trunk/tools/iMesh/python/pkg/__init__.py
   MOAB/trunk/tools/iMesh/python/pkg/helpers.py
Removed:
   MOAB/trunk/tools/iMesh/python/itaps/
   MOAB/trunk/tools/iMesh/python/pkg/__init__.py
Modified:
   MOAB/trunk/tools/iMesh/python/setup.py
   MOAB/trunk/tools/iMesh/python/test/adj.py
   MOAB/trunk/tools/iMesh/python/test/basic.py
   MOAB/trunk/tools/iMesh/python/test/entset.py
   MOAB/trunk/tools/iMesh/python/test/iter.py
   MOAB/trunk/tools/iMesh/python/test/tags.py
Log:
* Integrate unit tests into PyTAPS setup
* Move itaps/* to pkg/* to resolve "import itaps" confusion when in root 
  directory


Copied: MOAB/trunk/tools/iMesh/python/pkg (from rev 2880, MOAB/trunk/tools/iMesh/python/itaps)


Property changes on: MOAB/trunk/tools/iMesh/python/pkg
___________________________________________________________________
Name: svn:mergeinfo
   + 

Deleted: MOAB/trunk/tools/iMesh/python/pkg/__init__.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/itaps/__init__.py	2009-05-06 20:22:48 UTC (rev 2880)
+++ MOAB/trunk/tools/iMesh/python/pkg/__init__.py	2009-06-05 06:16:36 UTC (rev 2931)
@@ -1,2 +0,0 @@
-import iBase
-from iMesh import *

Copied: MOAB/trunk/tools/iMesh/python/pkg/__init__.py (from rev 2919, MOAB/trunk/tools/iMesh/python/itaps/__init__.py)
===================================================================
--- MOAB/trunk/tools/iMesh/python/pkg/__init__.py	                        (rev 0)
+++ MOAB/trunk/tools/iMesh/python/pkg/__init__.py	2009-06-05 06:16:36 UTC (rev 2931)
@@ -0,0 +1 @@
+__all__ = ['iBase', 'iMesh', 'helpers']

Copied: MOAB/trunk/tools/iMesh/python/pkg/helpers.py (from rev 2921, MOAB/trunk/tools/iMesh/python/itaps/helpers.py)
===================================================================
--- MOAB/trunk/tools/iMesh/python/pkg/helpers.py	                        (rev 0)
+++ MOAB/trunk/tools/iMesh/python/pkg/helpers.py	2009-06-05 06:16:36 UTC (rev 2931)
@@ -0,0 +1,49 @@
+class AdjacencyList:
+    def __init__(self, adj, offsets):
+        self.adj = adj
+        self.offsets = offsets
+
+    def __getitem__(self, key):
+        if isinstance(key, tuple):
+            if self.length(key[0]) <= key[1]:
+                raise IndexError
+            return self.adj[ self.offsets[key[0]] + key[1] ]
+        else:
+            return self.adj[ self.offsets[key]:self.offsets[key+1] ]
+
+    def length(self, i = None):
+        if i == None:
+            return len(self.offsets)-1
+        else:
+            return self.offsets[i+1] - self.offsets[i]
+
+    def __len__(self):
+        return self.length()
+
+
+class IndexedAdjacencyList:
+    def __init__(self, entities, adj, indices, offsets):
+        self.entities = entities
+        self.adj = adj
+        self.indices = indices
+        self.offsets = offsets
+
+    def __getitem__(self, key):
+        return self.adj[ self.index(key) ]
+
+    def index(self, key):
+        if isinstance(key, tuple):
+            if self.length(key[0]) <= key[1]:
+                raise IndexError
+            return self.indices[ self.offsets[key[0]] + key[1] ]
+        else:
+            return self.indices[ self.offsets[key]:self.offsets[key+1] ]
+
+    def length(self, i = None):
+        if i == None:
+            return len(self.offsets)-1
+        else:
+            return self.offsets[i+1] - self.offsets[i]
+
+    def __len__(self):
+        return self.length()

Modified: MOAB/trunk/tools/iMesh/python/setup.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/setup.py	2009-06-05 03:13:56 UTC (rev 2930)
+++ MOAB/trunk/tools/iMesh/python/setup.py	2009-06-05 06:16:36 UTC (rev 2931)
@@ -1,7 +1,10 @@
-from distutils.core import setup, Extension
+from distutils.core import setup, Extension, Command
 from distutils.sysconfig import parse_makefile
+from distutils.errors import DistutilsOptionError
+from unittest import TextTestRunner, TestLoader
 import re
 import os
+import sys
 
 # this is an enormous hack because distutils won't let me specify libraries in
 # 'extra_link_args' for unknown reasons
@@ -38,13 +41,49 @@
                              'iMesh_tag.c']
                   )
 
+class test(Command):
+    description = 'Execute tests'
+    user_options = [
+        ('verbosity=', 'v', 'verbosity level')
+        ]
 
+    def initialize_options(self):
+        self.verbosity = 1
+
+    def finalize_options(self):
+        try:
+            self.verbosity = int(self.verbosity)
+        except ValueError:
+            raise DistutilsOptionError('"verbosity" option must be an integer')
+
+    def run(self):
+        root = os.path.normpath(os.path.join(
+                os.path.abspath(sys.argv[0]), '../test'))
+        old = os.getcwd()
+        tests = []
+        regex = re.compile(r'^(.*).py$')
+
+        os.chdir(root)
+        for file in os.listdir('.'):
+            match = regex.search(file)
+            if match != None:
+                tests.append( 'test.' + match.group(1) )
+
+        TextTestRunner(verbosity=self.verbosity).run(
+            TestLoader().loadTestsFromNames(tests) )
+        os.chdir(old)
+
+
 setup(name = 'PyTAPS',
       version = '1.0b1',
       description = 'Python bindings for iBase and iMesh interfaces',
       author = 'Jim Porter',
       author_email = 'jvporter at wisc.edu',
+
+      package_dir = {'itaps': 'pkg'},
       packages = ['itaps'],
       ext_modules = [iBase, iMesh],
-      py_modules = ['itaps.helpers']
+      py_modules = ['itaps.helpers'],
+
+      cmdclass = {'test' : test}
       )

Modified: MOAB/trunk/tools/iMesh/python/test/adj.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/test/adj.py	2009-06-05 03:13:56 UTC (rev 2930)
+++ MOAB/trunk/tools/iMesh/python/test/adj.py	2009-06-05 06:16:36 UTC (rev 2931)
@@ -103,5 +103,6 @@
         self.assert_( (adj.index(2) == [1,2]).all() )
         self.assert_( (adj.index(3) == [2,3]).all() )
 
-suite = unittest.TestLoader().loadTestsFromTestCase(TestAdj)
-unittest.TextTestRunner(verbosity=2).run(suite)
+if __name__ == '__main__':
+    unittest.main()
+

Modified: MOAB/trunk/tools/iMesh/python/test/basic.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/test/basic.py	2009-06-05 03:13:56 UTC (rev 2930)
+++ MOAB/trunk/tools/iMesh/python/test/basic.py	2009-06-05 06:16:36 UTC (rev 2931)
@@ -113,6 +113,5 @@
         coords = mesh.getVtxCoords(ents, iBase.StorageOrder.interleaved)
         self.assert_( (coords == [1,2,3]).all() )
 
-
-suite = unittest.TestLoader().loadTestsFromTestCase(TestBasic)
-unittest.TextTestRunner(verbosity=2).run(suite)
+if __name__ == '__main__':
+    unittest.main()

Modified: MOAB/trunk/tools/iMesh/python/test/entset.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/test/entset.py	2009-06-05 03:13:56 UTC (rev 2930)
+++ MOAB/trunk/tools/iMesh/python/test/entset.py	2009-06-05 06:16:36 UTC (rev 2931)
@@ -119,7 +119,7 @@
         self.assertTrue(union.contains(ents[0]))
         self.assertTrue(union.contains(ents[1]))
 
+if __name__ == '__main__':
+    unittest.main()
 
-suite = unittest.TestLoader().loadTestsFromTestCase(TestEntSet)
-unittest.TextTestRunner(verbosity=2).run(suite)
 

Modified: MOAB/trunk/tools/iMesh/python/test/iter.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/test/iter.py	2009-06-05 03:13:56 UTC (rev 2930)
+++ MOAB/trunk/tools/iMesh/python/test/iter.py	2009-06-05 06:16:36 UTC (rev 2931)
@@ -44,6 +44,5 @@
         self.assertEqual(count, 1)
         iter.reset()
 
-
-suite = unittest.TestLoader().loadTestsFromTestCase(TestIter)
-unittest.TextTestRunner(verbosity=2).run(suite)
+if __name__ == '__main__':
+    unittest.main()

Modified: MOAB/trunk/tools/iMesh/python/test/tags.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/test/tags.py	2009-06-05 03:13:56 UTC (rev 2930)
+++ MOAB/trunk/tools/iMesh/python/test/tags.py	2009-06-05 06:16:36 UTC (rev 2931)
@@ -182,5 +182,5 @@
         self.assertEqual(tags[1].name, self.dtag.name)
         
 
-suite = unittest.TestLoader().loadTestsFromTestCase(TestTags)
-unittest.TextTestRunner(verbosity=2).run(suite)
+if __name__ == '__main__':
+    unittest.main()



More information about the moab-dev mailing list