[commit] r1523 - trunk/Tests/GPyUnit/GME_297

GMESRC Repository Notifications gme-commit at list.isis.vanderbilt.edu
Mon Sep 12 10:17:03 CDT 2011


Author: ksmyth
Date: Mon Sep 12 10:17:02 2011
New Revision: 1523

Log:
Test for r1522 MoveFCODisp

Added:
   trunk/Tests/GPyUnit/GME_297/test6-correct.mga
      - copied unchanged from r1505, trunk/Tests/GPyUnit/GME_297/test4-correct.mga
Modified:
   trunk/Tests/GPyUnit/GME_297/__init__.py

Modified: trunk/Tests/GPyUnit/GME_297/__init__.py
==============================================================================
--- trunk/Tests/GPyUnit/GME_297/__init__.py	Mon Sep 12 09:42:10 2011	(r1522)
+++ trunk/Tests/GPyUnit/GME_297/__init__.py	Mon Sep 12 10:17:02 2011	(r1523)
@@ -6,7 +6,7 @@
 import win32com.client
 
 class TestRefportConnectionInvariantUnderMoves(unittest.TestCase):
-    def __init__(self, input_file, fco_to_move, destination_model, name=None):
+    def __init__(self, input_file, fco_to_move, destination_model, name=None, use_disp=None):
         unittest.TestCase.__init__(self, 'test')
         self.input_file = input_file
         self.fco_to_move = fco_to_move
@@ -14,6 +14,8 @@
         name = name if name else os.path.splitext(self.input_file)[0]
         self.output_file = name + "-output.mga"
         self.correct_file = name + "-correct.mga"
+        if use_disp:
+            self._move_fcos = self._move_fcos_disp
 
 
     def test(self):
@@ -25,41 +27,41 @@
             return os.path.join(os.path.dirname(__file__), file)
         import util
         util.register_xmp(_adjacent_file('GME297ModelRefportTest.xmp'))
-        # TODO with util.disable_early_binding()
-        # This script depends on late binding. win32com.client.dynamic.Dispatch forces late binding when creating an object,
-        # but early-bound objects may be returned from function calls. Disable late binding completely.
-        import win32com.client.gencache
-        _savedGetClassForCLSID = win32com.client.gencache.GetClassForCLSID
-        win32com.client.gencache.GetClassForCLSID = lambda x: None
-
-        self.project = win32com.client.DispatchEx("Mga.MgaProject")
-        self.project.Open("MGA=" + _adjacent_file(self.input_file))
-        self.territory = self.project.BeginTransactionInNewTerr()
-
-        fco_to_move = self.project.ObjectByPath(self.fco_to_move)
-        OBJTYPE_FOLDER = 6
-        if fco_to_move.ObjType == OBJTYPE_FOLDER:
-            tomove = win32com.client.DispatchEx("Mga.MgaFolders")
-        else:
-            tomove = win32com.client.DispatchEx("Mga.MgaFCOs")
-        tomove.Append(fco_to_move)
-
-        destination = self.project.ObjectByPath(self.destination_model)
-        if destination.ObjType == OBJTYPE_FOLDER:
-            destination.MoveFolders(tomove, None)
-        else:
-            destination.MoveFCOs(tomove, None, None)
-
-        self.project.CommitTransaction()
-        self.project.Save("MGA=" + _adjacent_file(self.output_file))
-        self.territory.Destroy()
-        self.project.Close()
+        with util.disable_early_binding():
+            self.project = win32com.client.DispatchEx("Mga.MgaProject")
+            self.project.Open("MGA=" + _adjacent_file(self.input_file))
+            self.territory = self.project.BeginTransactionInNewTerr()
+
+            fco_to_move = self.project.ObjectByPath(self.fco_to_move)
+            OBJTYPE_FOLDER = 6
+            if fco_to_move.ObjType == OBJTYPE_FOLDER:
+                tomove = win32com.client.DispatchEx("Mga.MgaFolders")
+            else:
+                tomove = win32com.client.DispatchEx("Mga.MgaFCOs")
+            tomove.Append(fco_to_move)
+
+            destination = self.project.ObjectByPath(self.destination_model)
+            if destination.ObjType == OBJTYPE_FOLDER:
+                destination.MoveFolders(tomove, None)
+            else:
+                self._move_fcos(destination, fco_to_move, tomove)
+                #destination.MoveFCOs(tomove, None, None)
+
+            self.project.CommitTransaction()
+            self.project.Save("MGA=" + _adjacent_file(self.output_file))
+            self.territory.Destroy()
+            self.project.Close()
 
-        win32com.client.gencache.GetClassForCLSID = _savedGetClassForCLSID
         import util.mgadiff as mgadiff
         if not mgadiff.compare(_adjacent_file(self.correct_file), _adjacent_file(self.output_file)):
             self.fail("Reference file '%s' does not match output '%s'" % (self.correct_file, self.output_file))
         # print "Reference file '%s' matches output '%s'" % (self.correct_file, self.output_file)
+    
+    def _move_fcos(self, destination, fco_to_move, col_to_move):
+        destination.MoveFCOs(col_to_move, None, None)
+
+    def _move_fcos_disp(self, destination, fco_to_move, col_to_move):
+        destination.MoveFCODisp(fco_to_move, None)
 
 def suite():
     suite = unittest.TestSuite()
@@ -68,6 +70,7 @@
     suite.addTest(TestRefportConnectionInvariantUnderMoves(input_file="test1.mga", fco_to_move="/Test1/Folder1/A/RefB", destination_model="/Test1/Folder2/C", name="test3"))
     suite.addTest(TestRefportConnectionInvariantUnderMoves(input_file="test4.mga", fco_to_move="/Test4/Folder1/A/RefRefB", destination_model="/Test4/Folder2/C"))
     suite.addTest(TestRefportConnectionInvariantUnderMoves(input_file="test5.mga", fco_to_move="/Test4/Folder2", destination_model="/Test4/Folder3"))
+    suite.addTest(TestRefportConnectionInvariantUnderMoves(input_file="test4.mga", fco_to_move="/Test4/Folder1/A/RefRefB", destination_model="/Test4/Folder2/C", name="test6", use_disp=True))
     return suite
 
 if __name__ == "__main__":

Copied: trunk/Tests/GPyUnit/GME_297/test6-correct.mga (from r1505, trunk/Tests/GPyUnit/GME_297/test4-correct.mga)
==============================================================================
Binary file (source and/or target). No diff available.


More information about the gme-commit mailing list