[commit] r1740 - in trunk/Tests/GPyUnit: . util

GMESRC Repository Notifications gme-commit at list.isis.vanderbilt.edu
Fri Dec 9 09:25:05 CST 2011


Author: ksmyth
Date: Fri Dec  9 09:25:05 2011
New Revision: 1740

Log:
Add instance creation test

Added:
   trunk/Tests/GPyUnit/test_instances.py
Modified:
   trunk/Tests/GPyUnit/test_parser.py
   trunk/Tests/GPyUnit/util/__init__.py

Added: trunk/Tests/GPyUnit/test_instances.py
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/Tests/GPyUnit/test_instances.py	Fri Dec  9 09:25:05 2011	(r1740)
@@ -0,0 +1,32 @@
+import unittest
+import os
+import win32com.client
+import GPyUnit.util
+from GPyUnit.util import dec_disable_early_binding
+
+def _adjacent_file(file):
+    import os.path
+    return os.path.join(os.path.dirname(os.path.abspath(__file__)), file)
+
+class TestInstances(unittest.TestCase):
+    def __init__(self, name, **kwds):
+        super(TestInstances, self).__init__(name, **kwds)
+
+    def tearDown(self):
+        if self.project:
+            self.project.Close(True)
+
+    @property
+    def connstr(self):
+        return "MGA=" + _adjacent_file("tmp.mga")
+    
+    @dec_disable_early_binding
+    def test_CreateInstances(self):
+        self.project = GPyUnit.util.parse_xme(self.connstr)
+        self.project.BeginTransactionInNewTerr()
+        for i in range(3): # exponential!
+            for model in self.project.RootFolder.ChildFCOs:
+                self.project.RootFolder.DeriveRootObject(model, True)
+        self.project.CommitTransaction()
+
+GPyUnit.util.MUGenerator(globals(), TestInstances)

Modified: trunk/Tests/GPyUnit/test_parser.py
==============================================================================
--- trunk/Tests/GPyUnit/test_parser.py	Thu Dec  8 09:13:30 2011	(r1739)
+++ trunk/Tests/GPyUnit/test_parser.py	Fri Dec  9 09:25:05 2011	(r1740)
@@ -8,19 +8,9 @@
 
 class TestParser(unittest.TestCase):
     def test_ParseMetaGME(self):
-        testdir = os.path.dirname(os.path.abspath(__file__))
-        inputfile = os.environ['GME_ROOT'] + r"\Paradigms\MetaGME\MetaGME-model.xme"
-        import win32com.client
-        xme = win32com.client.DispatchEx("Mga.MgaParser")
-        (paradigm, parversion, parguid, basename, ver) = xme.GetXMLInfo(inputfile)
-        mga = win32com.client.DispatchEx("Mga.MgaProject")
-
-        mga.Create(self.connstr, paradigm)
-        xme.ParseProject(mga, inputfile)
+        mga = GPyUnit.util.parse_xme(self.connstr)
         mga.Save()
         mga.Close()
-        del(mga)
-        del(xme)
     
     @property
     def connstr(self):

Modified: trunk/Tests/GPyUnit/util/__init__.py
==============================================================================
--- trunk/Tests/GPyUnit/util/__init__.py	Thu Dec  8 09:13:30 2011	(r1739)
+++ trunk/Tests/GPyUnit/util/__init__.py	Fri Dec  9 09:25:05 2011	(r1740)
@@ -3,6 +3,18 @@
 import sys
 import unittest
 
+_Dispatch_x64 = False
+
+def Dispatch(progid):
+    from pythoncom import CLSCTX_ALL, CLSCTX_LOCAL_SERVER
+    CLSCTX_ACTIVATE_32_BIT_SERVER = 0x40000
+    CLSCTX_ACTIVATE_64_BIT_SERVER = 0x80000
+    if _Dispatch_x64:
+        return win32com.client.DispatchEx(progid, clsctx=CLSCTX_LOCAL_SERVER|CLSCTX_ACTIVATE_64_BIT_SERVER)
+    else:
+        return win32com.client.DispatchEx(progid)
+        # return win32com.client.DispatchEx(progid, clsctx=CLSCTX_LOCAL_SERVER|CLSCTX_ACTIVATE_32_BIT_SERVER)
+
 class disable_early_binding(object):
 	def __enter__(self):
 		import win32com.client.gencache
@@ -31,6 +43,20 @@
     import gme
     gme.register_if_not_registered(xmpfile)
 
+def parse_xme(connstr, xme=None, project=None):
+    testdir = os.path.dirname(os.path.abspath(__file__))
+    if xme is None:
+        xme = os.environ['GME_ROOT'] + r"\Paradigms\MetaGME\MetaGME-model.xme"
+    import win32com.client
+    parser = win32com.client.DispatchEx("Mga.MgaParser")
+
+    if project is None:
+        (paradigm, parversion, parguid, basename, ver) = parser.GetXMLInfo(xme)
+        project = win32com.client.DispatchEx("Mga.MgaProject")
+        project.Create(connstr, paradigm)
+    parser.ParseProject(project, xme)
+    return project
+
 # From pathutils by Michael Foord: http://www.voidspace.org.uk/python/pathutils.html
 def onerror(func, path, exc_info):
     """


More information about the gme-commit mailing list