def test(self): """ Regression test: given self.input_file, move self.folder_to_copy to self.destination_folder. Then check self.output_file against self.correct_file """ from GPyUnit import util util.register_xmp(_adjacent_file('GME310ModelRefportTest.xmp')) with util.disable_early_binding(): self.project = DispatchEx("Mga.MgaProject") self.project.Open("MGA=" + _adjacent_file(self.input_file)) self.territory = self.project.BeginTransactionInNewTerr() modelb = self.project.ObjectByPath(self.folder_to_copy) modelb.Name tomove = DispatchEx("Mga.MgaFolders") tomove.Append(modelb) #self.project.ObjectByPath(self.destination_folder).CopyFolders(tomove, None) self.project.RootFolder.CopyFolderDisp(modelb) self.project.CommitTransaction() self.project.Save("MGA=" + _adjacent_file(self.output_file)) self.territory.Destroy() self.project.Close() import GPyUnit.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))
def open(file, mga_to_save=None): if not os.path.isfile(file): raise Exception("'" + file + "' not found") extension = os.path.splitext(file)[1] mga = None if extension == ".mga": mga = DispatchEx("Mga.MgaProject") mga.Open("MGA=" + file) mga_to_save = file elif extension == ".xme": xme = DispatchEx("Mga.MgaParser") (paradigm, parversion, parguid, basename, ver) = xme.GetXMLInfo(file) mga = DispatchEx("Mga.MgaProject") xme = DispatchEx("Mga.MgaParser") if mga_to_save == True: mga_to_save = os.path.splitext(file)[0] + ".mga" elif not mga_to_save: mga_to_save = tempfile.gettempdir() + "gmepy-%s.mga" % os.getpid() create_project(mga, "MGA=" + mga_to_save, paradigm) xme.ParseProject(mga, file) else: raise Exception("Don't know how to open '%s'" % file) p = Project(mga) p.filename = file p.mgafile = mga_to_save return p
def test_run(self): mga = GPyUnit.util.parse_xme( "MGA=" + _adjacent_file("BidirConnection.mga"), _adjacent_file("BidirConnection.xme")) print self.connstr try: mga.Save() selectedobj = DispatchEx("Mga.MgaFCOs") launcher = DispatchEx("Mga.MgaLauncher") #launcher.RunComponent("Mga.Interpreter.MetaInterpreter", mga, None, selectedobj, 128) launcher.RunComponent("Mga.Interpreter.CSharpDSMLGenerator", mga, None, selectedobj, 128) finally: mga.Close() self.assertTrue( os.path.isfile( os.path.join(self.outdir(), "ISIS.GME.Dsml.BidirConnection.Classes.cs"))) self.assertTrue( os.path.isfile( os.path.join(self.outdir(), "ISIS.GME.Dsml.BidirConnection.dll"))) mga = GPyUnit.util.parse_xme( self.connstr, _adjacent_file("BidirConnectionModel.xme")) mga.Save() mga.BeginTransactionInNewTerr() try: self.assertEqual( mga.ObjectByPath("/@NewModel/@Child1").PartOfConns.Count, 2) self.assertEqual( set([ x.ConnRole for x in mga.ObjectByPath("/@NewModel/@Child1").PartOfConns ]), set(['src', 'dst'])) self.assertEqual( set([ x.ConnRole for x in mga.ObjectByPath("/@NewModel/@Child2").PartOfConns ]), set(['src', 'dst'])) finally: mga.AbortTransaction() mga.Close() import subprocess subprocess.check_call( [_adjacent_file(r"DsmlGeneratorTest\.nuget\NuGet.exe"), "restore"], cwd=_adjacent_file("DsmlGeneratorTest")) subprocess.check_call([ r"c:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe", _adjacent_file(r"DsmlGeneratorTest\DsmlGeneratorTest.sln") ]) subprocess.check_call([ _adjacent_file( r"DsmlGeneratorTest\bin\Debug\DsmlGeneratorTest.exe"), self.connstr ])
def runDecorators(self, xme_file): mga = GPyUnit.util.parse_xme(self.connstr, xme_file) mga.Save() mga.Close() self.gme = DispatchEx("GME.Application") self.gme.OpenProject(self.connstr) dumpwmf = DispatchEx("MGA.DumpWMF") dumpwmf.DumpWMFs(self.outdir, self.gme)
def run_interpreter(self, interpreter, focusobj=None, selectedobj=None, param=0): if not selectedobj: selectedobj=DispatchEx("Mga.MgaFCOs") self.commit_transaction() try: launcher = DispatchEx("Mga.MgaLauncher") launcher.RunComponent(interpreter, self.project, focusobj, selectedobj, param) finally: self.begin_transaction()
def test_run(self): mga = GPyUnit.util.parse_xme(self.connstr) try: mga.Save() selectedobj = DispatchEx("Mga.MgaFCOs") launcher = DispatchEx("Mga.MgaLauncher") launcher.RunComponent("Mga.Interpreter.MetaInterpreter", mga, None, selectedobj, 128) launcher.RunComponent("Mga.Interpreter.CSharpDSMLGenerator", mga, None, selectedobj, 128) finally: mga.Close() self.assertTrue(os.path.isfile(os.path.join(self.outdir(), "ISIS.GME.Dsml.MetaGME.Classes.cs"))) self.assertTrue(os.path.isfile(os.path.join(self.outdir(), "ISIS.GME.Dsml.MetaGME.dll")))
def connectRefP(p, cont, s, d, r1, r2, role_str): """ Helper method connecting ports. s: source fco/port d: destination fco/port r1: modelreference, 'containing' s r2: modelreference, 'containing' d r1 or r2 might be 0, when that end of the connection is an fco or modelport (no reference involved) """ z1 = DispatchEx("Mga.MgaFCOs") z2 = DispatchEx("Mga.MgaFCOs") if r1: z1.Append(r1) if r2: z2.Append(r2) return cont.CreateSimpleConn(role(p, cont, role_str), s, d, z1, z2)
def test(self): from GPyUnit import util util.register_xmp('SF') with util.disable_early_binding(): self.project = DispatchEx("Mga.MgaProject") self.project.Open("MGA=" + _adjacent_file('SFDemo_dup_guids.mga')) self.project.BeginTransactionInNewTerr(0) mga = self.project self.assertTrue( mga.ObjectByPath('/@Folder1').GetGuidDisp() == '{8ce2ca06-2729-4e4c-955f-fc88194782cc}' or mga.ObjectByPath('/@Folder2').GetGuidDisp() == '{8ce2ca06-2729-4e4c-955f-fc88194782cc}') self.assertTrue( mga.ObjectByPath('/@Folder1/@System').GetGuidDisp() == '{a57ca6b2-d95e-485c-a768-98c16fd30588}' or mga.ObjectByPath('/@Folder2/@System').GetGuidDisp() == '{a57ca6b2-d95e-485c-a768-98c16fd30588}') self.assertNotEqual( mga.ObjectByPath('/@Folder1').GetGuidDisp(), mga.ObjectByPath('/@Folder2').GetGuidDisp()) self.assertNotEqual( mga.ObjectByPath('/@Folder1/@System').GetGuidDisp(), mga.ObjectByPath('/@Folder2/@System').GetGuidDisp()) self.assertNotEqual( mga.ObjectByPath('/@Folder1/@System/@DBSetup1').GetGuidDisp(), mga.ObjectByPath('/@Folder2/@System/@DBSetup1').GetGuidDisp()) self.project.AbortTransaction() self.project.Save("MGA=" + _adjacent_file(self.output_file), False) self.project.Close(True)
def testA(self): """ testA Create a project Close the project QueryProjectInfo """ # this file will be created: mganame = _adjacent_file("_tc3_A_sf.mga") project = DispatchEx("Mga.MgaProject") try: project.Create("MGA=" + mganame, "SF") except: print "Project Create failed" raise project.Save() project.Close(0) t = list(project.QueryProjectInfo("MGA=" + mganame)) self.assertEqual(t[0], 2) # mgaversion assert t[1] == "SF" # par name assert t[2] == "" # par version assert t[4] == 0 # readonly access ? t3_guid = list(t[3]) # convert binary part to a list t3_cvd = map(ord, t3_guid) isnull = lambda i: (i == 0 and [True] or [False])[0] len1 = filter(isnull, t3_cvd) assert len(len1) != 16
def test_derived(self): from GPyUnit import util util.register_xmp('MetaGME') with util.disable_early_binding(): self.project = DispatchEx("Mga.MgaProject") self.project.Create(self.connstr, "MetaGME") self.project.BeginTransactionInNewTerr() for i in range( 1, self.project.RootMeta.RootFolder.DefinedFCOs.Count + 1): if self.project.RootMeta.RootFolder.DefinedFCOs.Item( i).Name == 'ParadigmSheet': sheet_meta = self.project.RootMeta.RootFolder.DefinedFCOs.Item( i) sheet = self.project.RootFolder.CreateRootObject(sheet_meta) sheet.SetRegistryValueDisp('testcreation', 'testcreate') sheet2 = self.project.RootFolder.DeriveRootObject(sheet, False) sheet3 = self.project.RootFolder.DeriveRootObject(sheet2, False) sheet4 = self.project.RootFolder.DeriveRootObject(sheet3, False) sheet.SetRegistryValueDisp('test123', 'test') self.assertEqual(sheet4.GetRegistryValueDisp('test123'), 'test') sheet3.DetachFromArcheType() self.assertEqual(sheet4.GetRegistryValueDisp('test123'), 'test') self.assertEqual(sheet.GetRegistryDisp(False).Count, 2) self.assertEqual(sheet4.GetRegistryDisp(False).Count, 0) self.assertEqual(sheet3.GetRegistryDisp(False).Count, 3) # detaching adds a regnode "_detachedFrom" self.assertEqual(sheet4.GetRegistryDisp(False).Count, 0) self.assertEqual(sheet4.GetRegistryDisp(False).Count, 0) self.project.CommitTransaction() self.project.Save() self.project.Close()
def test_subtree_removal(self): from GPyUnit import util util.register_xmp('MetaGME') with util.disable_early_binding(): self.project = DispatchEx("Mga.MgaProject") self.project.Create(self.connstr, "MetaGME") self.project.BeginTransactionInNewTerr() for i in range( 1, self.project.RootMeta.RootFolder.DefinedFCOs.Count + 1): if self.project.RootMeta.RootFolder.DefinedFCOs.Item( i).Name == 'ParadigmSheet': sheet_meta = self.project.RootMeta.RootFolder.DefinedFCOs.Item( i) sheet = self.project.RootFolder.CreateRootObject(sheet_meta) #sys.stdin.readline() sheet.SetRegistryValueDisp('test123', 'test') sheet.SetRegistryValueDisp('test123/123', 'test') sheet.SetRegistryValueDisp('test123456', 'test') sheet.SetRegistryValueDisp('test123456/123', 'test') sheet.GetRegistryNodeDisp('test123').RemoveTree() ATTSTATUS_UNDEFINED = -2 self.assertEqual( sheet.GetRegistryNodeDisp('test123').Status(), ATTSTATUS_UNDEFINED) self.assertEqual( sheet.GetRegistryNodeDisp('test123/123').Status(), ATTSTATUS_UNDEFINED) self.assertEqual(sheet.GetRegistryValueDisp('test123456'), 'test') self.assertEqual(sheet.GetRegistryValueDisp('test123456/123'), 'test') self.project.CommitTransaction() self.project.Save() self.project.Close()
def register_old_sf_par(self): curdir = os.path.abspath(os.path.curdir) #curdir = '' par_conn_str = "MGA=" + curdir + "used_paradigms\\SF\\SF_older.mta" par_con2_str = "XML=" + curdir + "used_paradigms\\SF\\SF_older.xmp" ori_conn_str = "MGA=" + curdir + "used_paradigms\\SF\\SF_orig.mta" registrar = DispatchEx("Mga.MgaRegistrar") # 1: user registry # 2: system registry register_in = 1 newname = registrar.RegisterParadigmFromData(par_conn_str, None, register_in) # maybe we have to register the original sf.mta file once again newname = registrar.RegisterParadigmFromData(ori_conn_str, None, register_in) # {5D6FF99D-D6C2-46A5-9208-CCA15D5FA16C} guid of the SF_older.xmp # char_guid = [ '0x9d', '0xf9', '0x6f', '0x5d', '0xc2', '0xd6', '0xa5', '0x46', '0x92', '0x08', '0xcc', '0xa1', '0x5d', '0x5f', '0xa1', '0x6c' ] bin_guid = [ 0x9d, 0xf9, 0x6f, 0x5d, 0xc2, 0xd6, 0xa5, 0x46, 0x92, 0x08, 0xcc, 0xa1, 0x5d, 0x5f, 0xa1, 0x6c ] #return char_guid return bin_guid
def test_Exit(self): import win32com.client gme = DispatchEx("GME.Application") gme.Version gme.Exit() # under _DEBUG, GME.exe does not exit until Release()ed del (gme)
def test(self): from GPyUnit import util util.register_xmp(_adjacent_file('GME310ModelRefportTest.xmp')) with util.disable_early_binding(): self.project = DispatchEx("Mga.MgaProject") self.project.Open("MGA=" + _adjacent_file("test1.mga")) self.territory = self.project.BeginTransactionInNewTerr() a = self.project.ObjectByPath("/Test1/Folder1/A") b = self.project.ObjectByPath("/Test1/Folder1/A/B") kindAtom = self.project.ObjectByPath("/Test1/Folder1/A/B/KindAtom") self.assertTrue(kindAtom) bref = self.project.ObjectByPath("/Test1/Folder1/A/BRef") brefref = self.project.ObjectByPath("/Test1/Folder1/A/BRefRef") kindConnection = [ c for c in a.ChildFCOs if c.Name == "KindConnection" ][0] c = a.CreateSimpleConnDisp(kindConnection.MetaRole, kindAtom, kindAtom, None, None) c = a.CreateSimpleConnDisp(kindConnection.MetaRole, kindAtom, kindAtom, bref, brefref) self.project.CommitTransaction() self.project.Save("MGA=" + _adjacent_file("TestRefportAPI.mga")) self.territory.Destroy() self.project.Close()
def create(mgafile, paradigm): project = DispatchEx("Mga.MgaProject") create_project(project, "MGA=" + mgafile, paradigm) p = Project(project) p.filename = mgafile p.mgafile = mgafile return p
def tearDown(self): self._rm_old_files() registrar = DispatchEx("Mga.MgaRegistrar") if self.old_reg_data is None: registrar.UnregisterParadigm("MetaGME", 1) else: registrar.RegisterParadigm(*self.old_reg_data)
def is_registered(paradigm): registrar = DispatchEx("Mga.MgaRegistrar") paradigms = [] # REGACCESS_USER = 1 paradigms.extend(registrar.GetParadigmsDisp(1)) # REGACCESS_SYSTEM = 2 paradigms.extend(registrar.GetParadigmsDisp(2)) return filter(lambda p: p == paradigm, paradigms)
def _regxmp(xmpfile, regaccess): REG_USER = 1 REG_SYSTEM = 2 REG_BOTH = 3 registrar = DispatchEx("Mga.MgaRegistrar") if os.path.splitext(xmpfile)[1].lower() == ".xmp": registrar.RegisterParadigmFromData("XML=" + os.path.abspath(xmpfile), "", regaccess) else: registrar.RegisterParadigmFromData("MGA=" + os.path.abspath(xmpfile), "", regaccess)
def xxxtestupgrade(self): from GPyUnit import util util.register_xmp('MetaGME') with util.disable_early_binding(): self.project = DispatchEx("Mga.MgaProject") self.project.Open( "MGA=" + r"C:\Users\ksmyth\Documents\META\meta\CyPhyML\CyPhyML.mga") self.project.BeginTransactionInNewTerr() self.project.RootFolder.ChildFolders
def testTerritoryDestroy(self): project = DispatchEx('Mga.MgaProject') project.Create(self.connstr, 'MetaGME') paradigmSheet = project.RootMeta.RootFolder.DefinedFCOByName( 'ParadigmSheet', True) project.BeginTransactionInNewTerr() base = project.RootFolder.CreateRootObject(paradigmSheet) base.CreateChildObject(paradigmSheet.RoleByName('Atom')) for i in range(8): base.ParentFolder.DeriveRootObject(base, True) base_id = base.ID project.CommitTransaction() project.Close(False) project = DispatchEx('Mga.MgaProject') project.Open(self.connstr) assert project.UndoRedoSize() == (0, 0) oldpref = project.Preferences project.Preferences = 0x00000080 terr = project.BeginTransactionInNewTerr() base = project.GetObjectByID(base_id) derived = base.DerivedObjects.Item(2) base.SetRegistryValueDisp('random', 'asdf') base.Name = 'super' project.CommitTransaction() project.Preferences = oldpref terr2 = project.BeginTransactionInNewTerr() terr.Destroy( ) # puts locking in a bad state pre-r2234 (before CoreTerritory gutting) derived = terr2.OpenFCO(derived) derived.DestroyObject() project.AbortTransaction() terr3 = project.BeginTransactionInNewTerr() base = terr3.OpenFCO(base) base.DestroyObject() project.CommitTransaction( ) # crashes here pre-r2234 (before CoreTerritory gutting) project.Close(True)
def test(self): """ Regression test: given self.input_file, move self.fco_to_move to self.destination_model. Then check self.output_file against self.correct_file """ def _adjacent_file(file): import os.path return os.path.join(os.path.dirname(os.path.abspath(__file__)), file) from GPyUnit import util util.register_xmp(_adjacent_file('GME297ModelRefportTest.xmp')) with util.disable_early_binding(): self.project = 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 = DispatchEx("Mga.MgaFolders") else: tomove = DispatchEx("Mga.MgaFCOs") tomove.Append(fco_to_move) destination = self.project.ObjectByPath(self.destination_model) if destination.ObjType == OBJTYPE_FOLDER: destination.MoveFolderDisp(fco_to_move) 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() import GPyUnit.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))
def test_Console(self): import win32com.client registrar = DispatchEx("Mga.MgaRegistrar") old_engine = registrar.GetScriptEngineDisp(1) registrar.SetScriptEngineDisp(1, "JScript") try: def _adjacent_file(file): import os.path return os.path.join(os.path.dirname(os.path.abspath(__file__)), file) self.gme = DispatchEx("GME.Application") self.gme.Version console = filter(lambda p: p.Name == "Console", self.gme.Panels)[0] intf = console.Interface # 'intf.Contents =' fails because python calls Invoke(wFlags=3) instead of DISPATCH_PROPERTYPUT=4 intf.SetContents('magicstring') self.assertEqual(intf.Contents, 'magicstring') jscode = 'gme.ConsoleMessage("magic2string", 0);\n' with open(_adjacent_file('_console_utf16.js'), 'wb') as file: file.write('\xFF\xFE') file.write(unicode(jscode).encode('utf-16le')) intf.LoadScript(_adjacent_file('_console_utf16.js')) intf.RunLoadedScript() self.assertTrue( intf.Contents.find('magic2string') != -1, 'Console contents: "' + intf.Contents + '"') with open(_adjacent_file('_console_ansi.js'), 'wb') as file: file.write(jscode.replace('magic2string', 'magic3string')) intf.LoadScript(_adjacent_file('_console_ansi.js')) intf.RunLoadedScript() self.assertTrue( intf.Contents.find('magic3string') != -1, 'Console contents: "' + intf.Contents + '"') finally: registrar.SetScriptEngineDisp(1, old_engine)
def test_ParseMetaGME(self): testdir = os.path.dirname(os.path.abspath(__file__)) inputfile = os.environ[ 'GME_ROOT'] + r"\Paradigms\MetaGME\MetaGME-model.xme" xme = DispatchEx("Mga.MgaParser") (paradigm, parversion, parguid, basename, ver) = xme.GetXMLInfo(inputfile) mga = DispatchEx("Mga.MgaProject") mga.Create("MGA=tmp.mga", paradigm) terr = mga.BeginTransactionInNewTerr() # GME-371: this would crash self.assertRaises(com_error, xme.ParseProject, mga, inputfile) return mga.CommitTransaction() terr.Destroy() mga.Save() mga.Close() del (terr) del (mga) del (xme)
def creaP(mganame, parad): from GPyUnit import util util.register_xmp(parad) project = DispatchEx("Mga.MgaProject") # may delete old file if exists # if os.path.isfile( mganame): # os.remove( mganame) project.Create("MGA=" + mganame, parad) project.BeginTransactionInNewTerr(0) return project
def test_AttributeOrdering(self): mga = GPyUnit.util.parse_xme(self.connstr) try: mga.Save() selectedobj = DispatchEx("Mga.MgaFCOs") launcher = DispatchEx("Mga.MgaLauncher") launcher.RunComponent("Mga.Interpreter.MetaInterpreter", mga, None, selectedobj, 128) finally: mga.Close() with open(os.path.join(self.outdir(), "MetaGME.xmp")) as xmp: lines = xmp.readlines() atomattributes = "IsAbstract InRootFolder GeneralPreferences DisplayedName IsTypeShown Icon IsNameEnabled PortIcon SubTypeIcon NamePosition InstanceIcon Decorator NameWrapNum IsHotspotEnabled IsResizable AutoRouterPref HelpURL IsGradientFillEnabled GradientFillColor GradientFillDirection IsShadowCastEnabled ShadowColor ShadowThickness ShadowDirection IsRoundRectangleEnabled RoundRectangleRadius" self.assertTrue(atomattributes in "".join(lines), filter(lambda x: '<atom name = "Atom"' in x, lines)) metaproj = DispatchEx("Mga.MgaMetaProject") metaproj.Open("MGA=" + os.path.join(self.outdir(), "MetaGME.mta")) try: atomattrs = [attr.Name for attr in metaproj.RootFolder.DefinedFCOByName("Atom", True).Attributes] self.assertEqual(atomattrs, list(atomattributes.split())) finally: metaproj.Close()
def get_paradigm_file(paradigm, regaccess=3): "Returns the .mta file for a given registered paradigm" registrar = DispatchEx("Mga.MgaRegistrar") guid = registrar.GetParadigmGUIDStringDisp(regaccess, paradigm) import uuid if platform.system() != 'Java': buf = buffer(uuid.UUID(guid).bytes_le, 0, 16) else: buf = str(uuid.UUID(guid).bytes_le[0:16]) (connstr, guid) = registrar.QueryParadigm(paradigm, None, buf, regaccess) # >>> constr # "MGA=....mta" return connstr[4:]
def createLibProject(): lib_project = DispatchEx("Mga.MgaProject") lib_project.Create(lib_path, "MetaGME") paradigmSheet = lib_project.RootMeta.RootFolder.DefinedFCOByName( 'ParadigmSheet', True) lib_project.BeginTransactionInNewTerr() base = lib_project.RootFolder.CreateRootObject(paradigmSheet) base.Name = "PS" atom = base.CreateChildObject(paradigmSheet.RoleByName('Atom')) atom.Name = "Atom" lib_project.CommitTransaction() lib_project.Save() lib_project.Close()
def test_RemoveArchetypeConnpoint(self): self.project = GPyUnit.util.parse_xme(self.connstr) self.project.BeginTransactionInNewTerr() aspects = self.project.RootFolder.GetObjectByPathDisp("/@Aspects") allproxy = self.project.RootFolder.GetObjectByPathDisp( "/@Aspects/@AllRef") subtype = self.project.RootFolder.DeriveRootObject(aspects, False) allrefNew = subtype.CreateChildObject(allproxy.MetaRole) stc = aspects.GetObjectByPathDisp("@SourceToConnector") model = aspects.GetObjectByPathDisp("@Model") stc.SetSrc(DispatchEx("Mga.MgaFCOs"), model) self.project.CommitTransaction()
def testCloseWithOpenTx(self): project = DispatchEx('Mga.MgaProject') project.Create(self.connstr, 'MetaGME') paradigmSheet = project.RootMeta.RootFolder.DefinedFCOByName( 'ParadigmSheet', True) terr = project.BeginTransactionInNewTerr() base = project.RootFolder.CreateRootObject(paradigmSheet) base.CreateChildObject(paradigmSheet.RoleByName('Atom')) for i in range(8): base.ParentFolder.DeriveRootObject(base, True) base_id = base.ID # don't: project.CommitTransaction() project.Close(True) del (terr)
def testNestedTxRollback(self): from pythoncom import com_error project = DispatchEx('Mga.MgaProject') project.Create(self.connstr, 'MetaGME') paradigmSheet = project.RootMeta.RootFolder.DefinedFCOByName( 'ParadigmSheet', True) project.BeginTransactionInNewTerr() model = project.RootFolder.CreateRootObject(paradigmSheet) atom = model.CreateChildObject(paradigmSheet.RoleByName('Atom')) conn = model.CreateChildObject(paradigmSheet.RoleByName('Connection')) conn.Name = 'Connection' connProxy = model.CreateChildObject( paradigmSheet.RoleByName('ConnectionProxy')) connProxy.Name = 'ConnectionProxy' connProxy.Referred = conn self.assertRaises(com_error, setattr, connProxy, 'Referred', atom) # this triggers a nested tx rollback atom.Name = 'Atom' project.CommitTransaction() def check(): terr = project.BeginTransactionInNewTerr() atom_ = terr.OpenFCO(atom) self.assertEqual('Atom', atom_.Name) conn_ = terr.OpenFCO(conn) self.assertEqual('Connection', conn_.Name) connProxy_ = terr.OpenFCO(connProxy) self.assertEqual('ConnectionProxy', connProxy_.Name) self.assertEqual(conn_, connProxy_.Referred) project.CommitTransaction() check() terr = project.BeginTransactionInNewTerr() model = terr.OpenFCO(model) atom = terr.OpenFCO(atom) atom.Name = '' self.assertRaises(com_error, getattr(model, 'CreateSimpleConnDisp'), paradigmSheet.RoleByName('ReferTo'), atom, atom, None, None) atom.Name = 'Atom' project.CommitTransaction() check() project.Close(False) del (terr)