00001
00002 from __future__ import with_statement
00003
00004 import sys
00005 import os.path
00006 import unittest
00007 from GPyUnit.util import DispatchEx
00008
00009 class TestFolderCopy(unittest.TestCase):
00010 def __init__(self, input_file, folder_to_copy, destination_folder, name=None, **kwds):
00011 super(TestFolderCopy, self).__init__('test', **kwds)
00012 self.input_file = input_file
00013 self.folder_to_copy = folder_to_copy
00014 self.destination_folder = destination_folder
00015 name = name if name else os.path.splitext(self.input_file)[0]
00016 self._testMethodDoc = name
00017 self.output_file = name + "-output.mga"
00018 self.correct_file = name + "-correct.mga"
00019
00020 def test(self):
00021 """
00022 Regression test: given self.input_file, move self.folder_to_copy to self.destination_folder. Then check self.output_file against self.correct_file
00023 """
00024 def _adjacent_file(file):
00025 import os.path
00026 return os.path.join(os.path.dirname(os.path.abspath(__file__)), file)
00027 from GPyUnit import util
00028 util.register_xmp(_adjacent_file('GME310ModelRefportTest.xmp'))
00029
00030 with util.disable_early_binding():
00031 self.project = DispatchEx("Mga.MgaProject")
00032 self.project.Open("MGA=" + _adjacent_file(self.input_file))
00033 self.territory = self.project.BeginTransactionInNewTerr()
00034
00035 modelb = self.project.ObjectByPath(self.folder_to_copy)
00036 modelb.Name
00037 tomove = DispatchEx("Mga.MgaFolders")
00038 tomove.Append(modelb)
00039
00040 self.project.RootFolder.CopyFolderDisp(modelb)
00041
00042 self.project.CommitTransaction()
00043 self.project.Save("MGA=" + _adjacent_file(self.output_file))
00044 self.territory.Destroy()
00045 self.project.Close()
00046
00047 import GPyUnit.util.mgadiff as mgadiff
00048 if not mgadiff.compare(_adjacent_file(self.correct_file), _adjacent_file(self.output_file)):
00049 self.fail("Reference file '%s' does not match output '%s'" % (self.correct_file, self.output_file))
00050
00051
00052 class TestRefportAPI(unittest.TestCase):
00053 def __init__(self, *kargs, **kwds):
00054 super(TestRefportAPI, self).__init__(*kargs, **kwds)
00055
00056 def test(self):
00057 def _adjacent_file(file):
00058 import os.path
00059 return os.path.join(os.path.dirname(os.path.abspath(__file__)), file)
00060 from GPyUnit import util
00061 util.register_xmp(_adjacent_file('GME310ModelRefportTest.xmp'))
00062
00063 with util.disable_early_binding():
00064 self.project = DispatchEx("Mga.MgaProject")
00065 self.project.Open("MGA=" + _adjacent_file("test1.mga"))
00066 self.territory = self.project.BeginTransactionInNewTerr()
00067
00068 a = self.project.ObjectByPath("/Test1/Folder1/A")
00069 b = self.project.ObjectByPath("/Test1/Folder1/A/B")
00070 kindAtom = self.project.ObjectByPath("/Test1/Folder1/A/B/KindAtom")
00071 self.assertTrue(kindAtom)
00072 bref = self.project.ObjectByPath("/Test1/Folder1/A/BRef")
00073 brefref = self.project.ObjectByPath("/Test1/Folder1/A/BRefRef")
00074 kindConnection = [c for c in a.ChildFCOs if c.Name == "KindConnection"][0]
00075 c = a.CreateSimpleConnDisp(kindConnection.MetaRole, kindAtom, kindAtom, None, None)
00076 c = a.CreateSimpleConnDisp(kindConnection.MetaRole, kindAtom, kindAtom, bref, brefref)
00077
00078 self.project.CommitTransaction()
00079 self.project.Save("MGA=" + _adjacent_file("TestRefportAPI.mga"))
00080 self.territory.Destroy()
00081 self.project.Close()
00082
00083 def suite():
00084 suite = unittest.TestSuite()
00085 suite.addTest(TestFolderCopy(input_file="test1.mga", folder_to_copy="/Test1", destination_folder=""))
00086 suite.addTest(TestRefportAPI("test"))
00087 return suite
00088
00089 if __name__ == "__main__":
00090 runner = unittest.TextTestRunner()
00091 runner.run(suite())