[commit] r1985 - in trunk/Tests/GPyUnit/Regr/Mga: . utils
GMESRC Repository Notifications
gme-commit at list.isis.vanderbilt.edu
Wed Aug 1 10:58:38 CDT 2012
Author: ksmyth
Date: Wed Aug 1 10:58:37 2012
New Revision: 1985
Log:
Specify full path for MGA files: x64 tests run with COM objects out-of-proc, and dllhost does not share the same working directory
Modified:
trunk/Tests/GPyUnit/Regr/Mga/tc1.py
trunk/Tests/GPyUnit/Regr/Mga/tc2.py
trunk/Tests/GPyUnit/Regr/Mga/tc3.py
trunk/Tests/GPyUnit/Regr/Mga/tc4.py
trunk/Tests/GPyUnit/Regr/Mga/tc5.py
trunk/Tests/GPyUnit/Regr/Mga/tc6.py
trunk/Tests/GPyUnit/Regr/Mga/tc7.py
trunk/Tests/GPyUnit/Regr/Mga/utils/Builder.py
Modified: trunk/Tests/GPyUnit/Regr/Mga/tc1.py
==============================================================================
--- trunk/Tests/GPyUnit/Regr/Mga/tc1.py Mon Jul 30 18:39:32 2012 (r1984)
+++ trunk/Tests/GPyUnit/Regr/Mga/tc1.py Wed Aug 1 10:58:37 2012 (r1985)
@@ -7,6 +7,10 @@
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 TestCase1( unittest.TestCase ):
"""
avoid if possible the overriding of __init__, yet if you override use the following form:
@@ -57,7 +61,7 @@
ReferencedBy([out, retval] IMgaFCOs **pVal)
"""
- mganame = "_tc1_A_me.mga"
+ mganame = _adjacent_file("_tc1_A_me.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "MetaGME")
@@ -154,7 +158,7 @@
MemberOfSets([out, retval] IMgaFCOs **pVal)
"""
- mganame = "_tc1_B_me.mga"
+ mganame = _adjacent_file("_tc1_B_me.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "MetaGME")
@@ -299,7 +303,7 @@
References([out, retval] IMgaFCOs **pVal)
"""
- mganame = "_tc1_C_me.mga"
+ mganame = _adjacent_file("_tc1_C_me.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "MetaGME")
@@ -504,7 +508,7 @@
References([out, retval] IMgaFCOs **pVal)
"""
- mganame = "_tc1_D_sf.mga"
+ mganame = _adjacent_file("_tc1_D_sf.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "SF")
Modified: trunk/Tests/GPyUnit/Regr/Mga/tc2.py
==============================================================================
--- trunk/Tests/GPyUnit/Regr/Mga/tc2.py Mon Jul 30 18:39:32 2012 (r1984)
+++ trunk/Tests/GPyUnit/Regr/Mga/tc2.py Wed Aug 1 10:58:37 2012 (r1985)
@@ -7,6 +7,10 @@
bd = utils.Builder
from GPyUnit.util import DispatchEx
+def _adjacent_file(file):
+ import os.path
+ return os.path.join(os.path.dirname(os.path.abspath(__file__)), file)
+
"""
tests properties of IMgaProject
"""
@@ -17,7 +21,7 @@
def setUp( self ): ## hook method: creates a new mga file all the times, and deletes one if existing
self.project = DispatchEx("Mga.MgaProject")
- self.mganame = "_tc2_all_sf.mga"
+ self.mganame = _adjacent_file("_tc2_all_sf.mga")
try:
os.remove( self.mganame)
Modified: trunk/Tests/GPyUnit/Regr/Mga/tc3.py
==============================================================================
--- trunk/Tests/GPyUnit/Regr/Mga/tc3.py Mon Jul 30 18:39:32 2012 (r1984)
+++ trunk/Tests/GPyUnit/Regr/Mga/tc3.py Wed Aug 1 10:58:37 2012 (r1985)
@@ -7,6 +7,9 @@
from GPyUnit.util import DispatchEx
bd = utils.Builder
+def _adjacent_file(file):
+ import os.path
+ return os.path.join(os.path.dirname(os.path.abspath(__file__)), file)
class TestCase3( unittest.TestCase ):
def setUp( self ): ## hook method
@@ -25,7 +28,7 @@
"""
# this file will be created:
- mganame = "_tc3_A_sf.mga"
+ mganame = _adjacent_file("_tc3_A_sf.mga")
project = DispatchEx("Mga.MgaProject")
try:
@@ -63,7 +66,7 @@
"""
# this file will be created:
- mganame = "_tc4_B_sf.mga"
+ mganame = _adjacent_file("_tc4_B_sf.mga")
project = DispatchEx("Mga.MgaProject")
try:
Modified: trunk/Tests/GPyUnit/Regr/Mga/tc4.py
==============================================================================
--- trunk/Tests/GPyUnit/Regr/Mga/tc4.py Mon Jul 30 18:39:32 2012 (r1984)
+++ trunk/Tests/GPyUnit/Regr/Mga/tc4.py Wed Aug 1 10:58:37 2012 (r1985)
@@ -10,6 +10,10 @@
from GPyUnit.util import DispatchEx
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 TestCase4( unittest.TestCase ):
#avoid if possible the overriding of __init__, yet if you override use the following form:
#def __init__(self, methodName='runTest'):
@@ -53,7 +57,7 @@
"""
- mganame = "_tc4_A_sf.mga"
+ mganame = _adjacent_file("_tc4_A_sf.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "SF")
@@ -139,7 +143,7 @@
"""
- mganame = "_tc4_B_sf.mga"
+ mganame = _adjacent_file("_tc4_B_sf.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "SF")
@@ -230,7 +234,7 @@
"""
- mganame = "_tc4_C_sf.mga"
+ mganame = _adjacent_file("_tc4_C_sf.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "SF")
@@ -375,7 +379,7 @@
"""
- mganame = "_tc4_D_sf.mga"
+ mganame = _adjacent_file("_tc4_D_sf.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "SF")
@@ -573,7 +577,7 @@
Open for a readonly project
"""
- mganame = "_tc4_E1_readonly_sf.mga"
+ mganame = _adjacent_file("_tc4_E1_readonly_sf.mga")
# if file exists from previous testing remove its readonly flag and delete the file
if os.path.isfile( mganame):
@@ -620,7 +624,7 @@
Close( abort )
"""
- mganame = "_tc4_E2_sf.mga"
+ mganame = _adjacent_file("_tc4_E2_sf.mga")
self.project = project = DispatchEx("Mga.MgaProject")
@@ -689,8 +693,8 @@
SaveAs under a different name, with "Don't keep oldname" option
"""
- mganame = "_tc4_E3_sf.mga"
- mganame_SavedAs = "_tc4_E3_savedAs_sf.mga"
+ mganame = _adjacent_file("_tc4_E3_sf.mga")
+ mganame_SavedAs = _adjacent_file("_tc4_E3_savedAs_sf.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "SF")
@@ -743,8 +747,8 @@
SaveAs under a different name, with "Don't keep oldname" option
Apply changes after the SaveAs operation
"""
- mganame = "_tc4_E4_sf.mga"
- mganame_SavedAs = "_tc4_E4_savedAs_sf.mga"
+ mganame = _adjacent_file("_tc4_E4_sf.mga")
+ mganame_SavedAs = _adjacent_file("_tc4_E4_savedAs_sf.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "SF")
@@ -845,8 +849,8 @@
SaveAs under a different name, with "Keep oldname" option
"""
- mganame = "_tc4_E5_sf.mga"
- mganame_SavedAs = "_tc4_E5_savedAs_sf.mga"
+ mganame = _adjacent_file("_tc4_E5_sf.mga")
+ mganame_SavedAs = _adjacent_file("_tc4_E5_savedAs_sf.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "SF")
@@ -915,8 +919,8 @@
SaveAs under a different name, with "Keep oldname" option
Apply changes after the SaveAs operation
"""
- mganame = "_tc4_E6_sf.mga"
- mganame_SavedAs = "_tc4_E6_savedAs_sf.mga"
+ mganame = _adjacent_file("_tc4_E6_sf.mga")
+ mganame_SavedAs = _adjacent_file("_tc4_E6_savedAs_sf.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "SF")
@@ -1052,7 +1056,7 @@
"""
- mganame = "_tc4_F_sf.mga"
+ mganame = _adjacent_file("_tc4_F_sf.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "SF")
if not project:
@@ -1187,7 +1191,7 @@
"""
- mganame = "_tc4_G_sf.mga"
+ mganame = _adjacent_file("_tc4_G_sf.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "SF")
if not project:
@@ -1311,7 +1315,7 @@
"""
- mganame = "_tc4_H_sf.mga"
+ mganame = _adjacent_file("_tc4_H_sf.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "SF")
if not project:
@@ -1401,7 +1405,7 @@
"""
- mganame = "_tc4_I_sf.mga"
+ mganame = _adjacent_file("_tc4_I_sf.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "SF")
if not project:
@@ -1486,7 +1490,7 @@
"""
- mganame = "_tc4_J_sf.mga"
+ mganame = _adjacent_file("_tc4_J_sf.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "SF")
if not project:
Modified: trunk/Tests/GPyUnit/Regr/Mga/tc5.py
==============================================================================
--- trunk/Tests/GPyUnit/Regr/Mga/tc5.py Mon Jul 30 18:39:32 2012 (r1984)
+++ trunk/Tests/GPyUnit/Regr/Mga/tc5.py Wed Aug 1 10:58:37 2012 (r1985)
@@ -9,6 +9,10 @@
from GPyUnit.util import DispatchEx
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 TestCase5( unittest.TestCase ):
"""
avoid if possible the overriding of __init__, yet if you override use the following form:
@@ -60,7 +64,7 @@
CreateCollection([in,out] IMgaFCOs **pVal)
"""
- mganame = "_tc5_B_sf.mga"
+ mganame = _adjacent_file("_tc5_B_sf.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "SF")
@@ -180,7 +184,7 @@
it should return the first object which is in the hierarchy ( below folders )
"""
- mganame = "_tc5_C_sf.mga"
+ mganame = _adjacent_file("_tc5_C_sf.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "SF")
if not project:
Modified: trunk/Tests/GPyUnit/Regr/Mga/tc6.py
==============================================================================
--- trunk/Tests/GPyUnit/Regr/Mga/tc6.py Mon Jul 30 18:39:32 2012 (r1984)
+++ trunk/Tests/GPyUnit/Regr/Mga/tc6.py Wed Aug 1 10:58:37 2012 (r1985)
@@ -10,623 +10,627 @@
from GPyUnit.util import DispatchEx
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 TestCase6( unittest.TestCase ):
- def __init__(self, methodName='runTest'):
- unittest.TestCase.__init__(self, methodName)
- self.project = None
-
- def setUp( self ): ## hook method
- pass
-
- def tearDown( self ): ## hook method
- if self.project:
- self.project.Close( 0 )
-
- def populate6A(self, p):
- f1 = bd.newFolder( p, p.RootFolder, 'Folder')
- f1.Name = 'NewFolder'
-
- c1 = bd.newObjInFold( p, p.RootFolder, 'Compound')
- c1.Name = 'NewCompound'
-
- p1 = bd.newObjInFold( p, f1, 'Primitive')
- p1.Name = 'NewPrimitive'
-
- @dec_disable_early_binding
- def testA( self ):
-
- """ testA
- test properties of IMgaObject such as
- Name
- ID
- AbsPath
- GetParent
- ObjType
- MetaBase
- Project
- Territory
-
- methods such as
- ObjectByPath
- IsEqual
- """
-
- mganame = "_tc6_A_sf.mga"
- project = bd.creaP( mganame, "SF")
- if not project:
- self.fail("Create failed")
- try:
- self.populate6A( project)
- except:
- bd.saveP( project)
- raise
- bd.saveP( project)
-
-
- # open the created project
- self.project = project
- try:
- project.Open( "MGA=" + mganame )
- except:
- project.Close(0)
- raise
-
- terr = project.CreateTerritory( None, None, None)
- trans = project.BeginTransaction( terr)
-
- rf = project.RootFolder
-
- fol = rf.ObjectByPath( "@NewFolder|kind=Folder")
- assert fol.Name == "NewFolder"
- assert fol.AbsPath == "/@NewFolder|kind=Folder|relpos=0"
-
- fco = rf.ObjectByPath( "@NewFolder|kind=Folder/@NewPrimitive|kind=Primitive")
- assert fco.Name == "NewPrimitive"
- assert fco.AbsPath == "/@NewFolder|kind=Folder|relpos=0/@NewPrimitive|kind=Primitive|relpos=0"
- assert fco.GetParent() == ( fol, 6 ) # a tuple with parent and its type: OBJTYPE_FOLDER = 6
-
- # use ObjectByPath with NewFolder as root
- fcp = fol.ObjectByPath( "@NewPrimitive|kind=Primitive")
- assert fcp.Name == "NewPrimitive"
- assert fcp.Name == fco.Name
- assert fcp.AbsPath == fco.AbsPath
-
- # the object pointer should be equal (they are in the same territory)
- assert fco == fcp
- # this must be True regardless of territories
- assert fco.IsEqual( fcp)
-
- fc2 = rf.ObjectByPath( "@NewCompound|kind=Compound")
- assert fc2.Name == "NewCompound"
- assert fc2.AbsPath == "/@NewCompound|kind=Compound|relpos=0"
- assert fc2.GetParent() == ( rf, 6) # a tuple with parent and its type: OBJTYPE_FOLDER = 6
-
- fco.Name = "OldPrimitive"
- fc2.Name = "OldCompound"
- fol.Name = "OldFolder"
-
- t_fol = rf.ObjectByPath( "@OldFolder|kind=Folder")
- assert t_fol.Name == "OldFolder"
-
- t_fco = rf.ObjectByPath( "@OldFolder|kind=Folder/@OldPrimitive|kind=Primitive")
- assert t_fco.Name == "OldPrimitive"
-
- t_fc2 = rf.ObjectByPath( "@OldCompound|kind=Compound")
- assert t_fc2.Name == "OldCompound"
-
- # test IsEqual for "should be false" cases
- assert ~t_fc2.IsEqual( t_fco)
- assert ~t_fc2.IsEqual( t_fol)
-
- assert t_fol.IsEqual( fol)
- assert t_fol.ID == fol.ID
- assert t_fol.MetaBase == fol.MetaBase
- assert t_fol.MetaBase.Name == "Folder"
- assert t_fol.ObjType == fol.ObjType
- assert t_fol.ObjType == 6 # OBJTYPE_FOLDER
-
- assert t_fco.IsEqual( fco)
- assert t_fco.ID == fco.ID
- assert t_fco.MetaBase == fco.MetaBase
- assert t_fco.MetaBase.Name == "Primitive"
- assert t_fco.ObjType == fco.ObjType
- assert t_fco.ObjType == 1 # OBJTYPE_MODEL
-
- assert t_fc2.IsEqual( fc2)
- assert t_fc2.ID == fc2.ID
- assert t_fc2.MetaBase == fc2.MetaBase
- assert t_fc2.MetaBase.Name == "Compound"
- assert t_fc2.ObjType == fc2.ObjType
- assert t_fc2.ObjType == 1 # OBJTYPE_MODEL
-
- fco.Name = "NewPrimitive"
- fc2.Name = "NewCompound"
- fol.Name = "NewFolder"
-
- assert fco.Project == project
- assert fco.Territory == terr
-
- assert fc2.Project == project
- assert fc2.Territory == terr
-
- assert fol.Project == project
- assert fol.Territory == terr
-
- # commit trans
- project.CommitTransaction()
-
- # create another territory
- ter2 = project.CreateTerritory( None, None, None)
- tran2 = project.BeginTransaction( ter2)
-
- a_rf = project.RootFolder
- # the objects must be equal in spite of different territories
- assert a_rf.IsEqual( rf)
-
- a_fco = a_rf.ObjectByPath( "@NewFolder|kind=Folder/@NewPrimitive|kind=Primitive")
- assert a_fco.Name == "NewPrimitive"
- assert a_fco != fco
- assert a_fco.IsEqual( fco)
-
- # commit tran2
- project.CommitTransaction()
-
-
- project.Save()
- project.Close(0)
-
-
- pass
-
- def populate6C(self, p):
- c1 = bd.newObjInFold( p, p.RootFolder, 'Compound')
- c1.Name = 'NewCompound'
-
- p1 = bd.new( p, c1, 'PrimitiveParts')
- p1.Name = 'NewPrimitiveParts'
-
- @dec_disable_early_binding
- def testC( self ):
- """ testC
-
- for a READ-ONLY project test methods like:
- IsLibObject
- IsWritable
- Status
-
- then
-
- create another project
- AttachLibrary attach the prev project as a library
- IsLibObject, IsWritable check on its objects
- """
-
- mg1name = "_tc6_C_readonly_sf.mga"
-
- # if file exists from previous testing remove its readonly flag and delete the file
- for file in (mg1name, mg1name + "tmp"):
- if os.path.isfile(file):
- # revert to read/write permission in order to delete it seamlessly
- os.chmod(file, stat.S_IWUSR)
- #delete:
- #os.remove( mg1name)
-
-
- # create the project with the needed kinds
- project1 = bd.creaP( mg1name, "SF")
- if not project1:
- self.fail("Create failed")
- try:
- self.populate6C( project1)
- except:
- bd.saveP( project1)
- raise
- bd.saveP( project1)
-
- self.project = project1
-
- # make the file read-only and
- # ... open the created project
- try:
- # make the file read-only
- os.chmod( mg1name, stat.S_IRUSR)
-
- readonly = project1.Open( "MGA=" + mg1name )
- # assert readonly
- except:
- project1.Close(0)
- raise
-
- self.project = project1
-
- terr1 = project1.CreateTerritory( None, None, None)
- # begin transaction as TRANSACTION_READ_ONLY = 1
- trans1 = project1.BeginTransaction( terr1, 1)
- rf = project1.RootFolder
-
- obj = rf.ObjectByPath( "#1")
- assert obj.IsWritable # though the project is ReadOnly, the object itself is writable
- assert not obj.IsLibObject # not a lib object
- assert obj.Status == 0 # OBJECT_EXISTS defd in Mga.idl
-
- # commit trans
- project1.CommitTransaction()
-
- # begin a regular transaction
- trans2 = project1.BeginTransaction( terr1)
-
- # and create an object
- cmp1 = bd.newObjInFold( project1, rf, 'Compound')
- cmp1.Name = "ThisObjectWillNotSurvive"
-
- # commit trans
- project1.CommitTransaction()
-
- # now try to save it
- try:
- project1.Save()
- assert False # it should have failed
- except:
- pass # it is OK to fail, since a Read-only file cannot not be saved modified
-
- project1.Close(0)
-
- mg2name = "_tc6_C_libuser_sf.mga"
-
- # create another project
- project2 = bd.creaP( mg2name, "SF")
- if not project2:
- self.fail("Create failed for " + mg2name + " project")
-
- bd.saveP( project2)
-
- # open the created project
- self.project = project2
- try:
- project2.Open( "MGA=" + mg2name )
- except:
- project2.Close(0)
- raise
-
-
- terr2 = project2.CreateTerritory( None, None, None)
- trans3 = project2.BeginTransaction( terr2)
- rf2 = project2.RootFolder
-
- # attach mg1name to it
- try:
- # attach the read-only file as a library
- libroot = project2.RootFolder.AttachLibrary( "MGA=" + mg1name)
- pass
- except:
- print 'AttachLibrary failed'
- raise
-
-
-
- flds = project2.RootFolder.ChildFolders
- assert flds.Count == 1
-
- #the only subfolder of RootFolder is the library root
- obj = flds.Item(1).GetChildFCODisp( "NewCompound")
- assert obj.IsWritable # though the object is in a library it report itself as writable
- assert obj.IsLibObject # a lib object
- assert obj.Status == 0 # OBJECT_EXISTS defd in Mga.idl
-
- # commit trans
- project2.CommitTransaction()
-
- project2.Save()
- project2.Close(0)
-
- def populate6D(self, p):
- f1 = bd.newFolder( p, p.RootFolder, 'Folder')
- f1.Name = 'NewFolder'
-
- f2 = bd.newFolder( p, p.RootFolder, 'Folder')
- f2.Name = 'NewFolder'
-
- c1 = bd.newObjInFold( p, p.RootFolder, 'Compound')
- c1.Name = 'NewCompound'
-
- p1 = bd.newObjInFold( p, f1, 'Primitive')
- p1.Name = 'NewPrimitive'
-
- ip = bd.new( p, p1, 'InputParameters')
- ip.Name = 'NewInputParameters'
-
- is0 = bd.new( p, p1, 'InputSignals')
- is0.Name = 'NewInputSignals'
-
- op = bd.new( p, p1, 'OutputParameters')
- op.Name = 'NewOutputParameters'
-
- os = bd.new( p, p1, 'OutputSignals')
- os.Name = 'NewOutputSignals'
-
- pp = bd.new( p, p1, 'Parameters')
- pp.Name = 'NewParameters'
-
- p2 = bd.newObjInFold( p, f1, 'Primitive')
- p2.Name = 'NewPrimitive'
-
- op = bd.new( p, p2, 'OutputParameters')
- op.Name = 'NewOutputParameters'
-
- p2 = bd.newObjInFold( p, f2, 'Primitive')
- p2.Name = 'NewPrimitive'
-
- op = bd.new( p, p2, 'OutputParameters')
- op.Name = 'NewOutputParameters'
-
- cp1 = bd.new( p, c1, 'CompoundParts')
- cp1.Name = 'NewCompoundParts'
-
- pp1 = bd.new( p, c1, 'PrimitiveParts')
- pp1.Name = 'NewPrimitiveParts'
-
-
- @dec_disable_early_binding
- def testD( self ):
-
- """ testD
-
- Check
- CheckTree
- ChildObjects
- ChildObjectByRelID
- """
-
- mganame = "_tc6_D_sf.mga"
-
- # create the project with the needed kinds
- project = bd.creaP( mganame, "SF")
- if not project:
- self.fail("Create failed")
- try:
- self.populate6D( project)
- except:
- bd.saveP( project)
- raise
- bd.saveP( project)
-
- self.project = project
-
- # open the created project
- self.project = project
- try:
- project.Open( "MGA=" + mganame )
- except:
- project.Close(0)
- raise
-
- terr = project.CreateTerritory( None, None, None)
- trans = project.BeginTransaction( terr)
-
- rf = project.RootFolder
-
- #objs = list( rf.ChildObjects )
- objs = rf.ChildObjects
- names = [ "NewFolder", "NewCompound"]
- for obj in objs:
- obj.Check()
- obj.CheckTree()
- rid = obj.RelID
- one_obj = rf.ChildObjectByRelID( rid)
- assert one_obj
- assert one_obj.RelID == rid
- name_dummy = one_obj.Name # it should not throw exc
- assert name_dummy in names
-
- one_fol = rf.ChildObjectByRelID( 1 )
- assert one_fol.Name == names[0]
-
- one_pri = one_fol.ChildObjectByRelID( 2 )
- assert one_pri.Name == "NewPrimitive"
- one_pri = one_fol.ChildObjectByRelID( 1 )
- assert one_pri.Name == "NewPrimitive"
-
- names = [ "NewInputParameters", "NewInputSignals", "NewOutputParameters", "NewOutputSignals", "NewParameters"]
- name2relid = { "NewInputParameters" : 1,
- "NewInputSignals" : 2,
- "NewOutputParameters" : 3,
- "NewOutputSignals" : 4,
- "NewParameters" : 5
- }
-
- pri_objs = one_pri.ChildObjects
- for pri_obj in pri_objs:
- rid = pri_obj.RelID
- one_obj = one_pri.ChildObjectByRelID( rid)
- assert one_obj
- assert one_obj.RelID == rid
- s_name = one_obj.Name
- assert s_name in names
- assert name2relid[ s_name ] == rid
-
- # commit trans
- project.CommitTransaction()
-
- project.Save()
- project.Close(0)
-
-
- @dec_disable_early_binding
- def testE( self ):
-
- """ testE
-
- ObjectByPath
- NthObjectByPath
- """
-
- mganame = "_tc6_D_sf.mga" # uses the same as D
-
- # create the project with the needed kinds - the same ad testD
- project = bd.creaP( mganame, "SF")
- if not project:
- self.fail("Create failed")
- try:
- self.populate6D( project)
- except:
- bd.saveP( project)
- raise
- bd.saveP( project)
-
- self.project = project
-
- # open the created project
- self.project = project
- try:
- project.Open( "MGA=" + mganame )
- except:
- project.Close(0)
- raise
-
- terr = project.CreateTerritory( None, None, None)
-
- trans = project.BeginTransaction( terr)
- rf = project.RootFolder
-
- objs = list( rf.ChildObjects )
-
- one_fol = rf.ChildObjectByRelID( 2 )
- assert one_fol.Name == "NewFolder"
- one_fol = rf.ChildObjectByRelID( 1 )
- assert one_fol.Name == "NewFolder"
-
- ### try the methods for the rootfolder looking for "NewFolder"
- res = rf.ObjectByPath( "@NewFolder|kind=Folder") # search for a non-unique object, returns NULL
- try:
- assert not res
- assert res == None
- # this should throw 'AttributeError'
- s_dummy = res.Name
- assert 0
- except AttributeError:
- # goood, res is null
- pass
- except:
- assert 0
-
- res = rf.NthObjectByPath( 0, "@NewFolder|kind=Folder|relpos=0") # should be OK
- assert res.Name == "NewFolder"
-
-
- one_pri = one_fol.ChildObjectByRelID( 2 )
- assert one_pri.Name == "NewPrimitive"
- one_pri = one_fol.ChildObjectByRelID( 1 )
- assert one_pri.Name == "NewPrimitive"
-
- ### try the methods for the "NewFolder" looking for the primitive
- res = one_fol.ObjectByPath( "@NewPrimitive|kind=Primitive") # search for a non-unique object, returns NULL
- try:
- # this should throw
- s_dummy = res.Name
- assert 0
- except AttributeError:
- # goood, res is null
- pass
- except:
- assert 0
-
- res = one_fol.NthObjectByPath( 0, "@NewPrimitive|kind=Primitive|relpos=0") # should be OK
- assert res
- assert res.Name == "NewPrimitive"
- assert res == one_pri
-
- ### ... now looking for an atom
- res = one_fol.ObjectByPath( "@NewPrimitive|kind=Primitive/@NewOutputParameters|kind=OutputParam") # search for a non-unique object, returns NULL
- try:
- # this should throw
- s_dummy = res.Name
- assert 0
- except AttributeError:
- # goood, res is null
- pass
- except:
- assert 0
-
- res = one_fol.NthObjectByPath( 0, "@NewPrimitive|kind=Primitive|relpos=0/@NewOutputParameters|kind=OutputParam|relpos=0") # should be OK
- assert res.Name == "NewOutputParameters"
- assert res.RelID == 3
-
- res = one_fol.NthObjectByPath( 0, "@NewPrimitive|kind=Primitive|relpos=1/@NewOutputParameters|kind=OutputParam|relpos=0") # should be OK
- assert res.Name == "NewOutputParameters"
- assert res.RelID == 1
-
- ### try the methods for the "NewPrimitive" looking for the atom
- res = one_pri.ObjectByPath( "@NewOutputParameters|kind=OutputParam") # search for a unique object
- assert res.Name == "NewOutputParameters"
- assert res.RelID == 3
-
- res = one_pri.NthObjectByPath( 0, "@NewOutputParameters|kind=OutputParam|relpos=888") # should be OK, even with invalid relpos
- assert res.Name == "NewOutputParameters"
- assert res.RelID == 3 # the same as above
-
- f1 = rf.ObjectByPath( "#1/#1/#3")
- f2 = rf.NthObjectByPath( 0, "/@NewFolder|kind=Folder|relpos=0/@NewPrimitive|kind=Primitive|relpos=0/@NewOutputParameters|kind=OutputParam|relpos=0")
- assert f1 == f2
-
- f1 = rf.ObjectByPath( "#1/#2/#1")
- f2 = rf.NthObjectByPath( 0, "/@NewFolder|kind=Folder|relpos=0/@NewPrimitive|kind=Primitive|relpos=1/@NewOutputParameters|kind=OutputParam|relpos=0")
- assert f1 == f2
-
- f1 = rf.ObjectByPath( "#2/#1/#1")
- f2 = rf.NthObjectByPath( 0, "/@NewFolder|kind=Folder|relpos=1/@NewPrimitive|kind=Primitive|relpos=0/@NewOutputParameters|kind=OutputParam|relpos=0")
- assert f1 == f2
-
- # commit trans
- project.CommitTransaction()
-
- project.Save()
- project.Close(0)
+ def __init__(self, methodName='runTest'):
+ unittest.TestCase.__init__(self, methodName)
+ self.project = None
+
+ def setUp( self ): ## hook method
+ pass
+
+ def tearDown( self ): ## hook method
+ if self.project:
+ self.project.Close( 0 )
+
+ def populate6A(self, p):
+ f1 = bd.newFolder( p, p.RootFolder, 'Folder')
+ f1.Name = 'NewFolder'
+
+ c1 = bd.newObjInFold( p, p.RootFolder, 'Compound')
+ c1.Name = 'NewCompound'
+
+ p1 = bd.newObjInFold( p, f1, 'Primitive')
+ p1.Name = 'NewPrimitive'
+
+ @dec_disable_early_binding
+ def testA( self ):
+
+ """ testA
+ test properties of IMgaObject such as
+ Name
+ ID
+ AbsPath
+ GetParent
+ ObjType
+ MetaBase
+ Project
+ Territory
+
+ methods such as
+ ObjectByPath
+ IsEqual
+ """
+
+ mganame = _adjacent_file("_tc6_A_sf.mga")
+ project = bd.creaP( mganame, "SF")
+ if not project:
+ self.fail("Create failed")
+ try:
+ self.populate6A( project)
+ except:
+ bd.saveP( project)
+ raise
+ bd.saveP( project)
+
+
+ # open the created project
+ self.project = project
+ try:
+ project.Open( "MGA=" + mganame )
+ except:
+ project.Close(0)
+ raise
+
+ terr = project.CreateTerritory( None, None, None)
+ trans = project.BeginTransaction( terr)
+
+ rf = project.RootFolder
+
+ fol = rf.ObjectByPath( "@NewFolder|kind=Folder")
+ assert fol.Name == "NewFolder"
+ assert fol.AbsPath == "/@NewFolder|kind=Folder|relpos=0"
+
+ fco = rf.ObjectByPath( "@NewFolder|kind=Folder/@NewPrimitive|kind=Primitive")
+ assert fco.Name == "NewPrimitive"
+ assert fco.AbsPath == "/@NewFolder|kind=Folder|relpos=0/@NewPrimitive|kind=Primitive|relpos=0"
+ assert fco.GetParent() == ( fol, 6 ) # a tuple with parent and its type: OBJTYPE_FOLDER = 6
+
+ # use ObjectByPath with NewFolder as root
+ fcp = fol.ObjectByPath( "@NewPrimitive|kind=Primitive")
+ assert fcp.Name == "NewPrimitive"
+ assert fcp.Name == fco.Name
+ assert fcp.AbsPath == fco.AbsPath
+
+ # the object pointer should be equal (they are in the same territory)
+ assert fco == fcp
+ # this must be True regardless of territories
+ assert fco.IsEqual( fcp)
+
+ fc2 = rf.ObjectByPath( "@NewCompound|kind=Compound")
+ assert fc2.Name == "NewCompound"
+ assert fc2.AbsPath == "/@NewCompound|kind=Compound|relpos=0"
+ assert fc2.GetParent() == ( rf, 6) # a tuple with parent and its type: OBJTYPE_FOLDER = 6
+
+ fco.Name = "OldPrimitive"
+ fc2.Name = "OldCompound"
+ fol.Name = "OldFolder"
+
+ t_fol = rf.ObjectByPath( "@OldFolder|kind=Folder")
+ assert t_fol.Name == "OldFolder"
+
+ t_fco = rf.ObjectByPath( "@OldFolder|kind=Folder/@OldPrimitive|kind=Primitive")
+ assert t_fco.Name == "OldPrimitive"
+
+ t_fc2 = rf.ObjectByPath( "@OldCompound|kind=Compound")
+ assert t_fc2.Name == "OldCompound"
+
+ # test IsEqual for "should be false" cases
+ assert ~t_fc2.IsEqual( t_fco)
+ assert ~t_fc2.IsEqual( t_fol)
+
+ assert t_fol.IsEqual( fol)
+ assert t_fol.ID == fol.ID
+ assert t_fol.MetaBase == fol.MetaBase
+ assert t_fol.MetaBase.Name == "Folder"
+ assert t_fol.ObjType == fol.ObjType
+ assert t_fol.ObjType == 6 # OBJTYPE_FOLDER
+
+ assert t_fco.IsEqual( fco)
+ assert t_fco.ID == fco.ID
+ assert t_fco.MetaBase == fco.MetaBase
+ assert t_fco.MetaBase.Name == "Primitive"
+ assert t_fco.ObjType == fco.ObjType
+ assert t_fco.ObjType == 1 # OBJTYPE_MODEL
+
+ assert t_fc2.IsEqual( fc2)
+ assert t_fc2.ID == fc2.ID
+ assert t_fc2.MetaBase == fc2.MetaBase
+ assert t_fc2.MetaBase.Name == "Compound"
+ assert t_fc2.ObjType == fc2.ObjType
+ assert t_fc2.ObjType == 1 # OBJTYPE_MODEL
+
+ fco.Name = "NewPrimitive"
+ fc2.Name = "NewCompound"
+ fol.Name = "NewFolder"
+
+ assert fco.Project == project
+ assert fco.Territory == terr
+
+ assert fc2.Project == project
+ assert fc2.Territory == terr
+
+ assert fol.Project == project
+ assert fol.Territory == terr
+
+ # commit trans
+ project.CommitTransaction()
+
+ # create another territory
+ ter2 = project.CreateTerritory( None, None, None)
+ tran2 = project.BeginTransaction( ter2)
+
+ a_rf = project.RootFolder
+ # the objects must be equal in spite of different territories
+ assert a_rf.IsEqual( rf)
+
+ a_fco = a_rf.ObjectByPath( "@NewFolder|kind=Folder/@NewPrimitive|kind=Primitive")
+ assert a_fco.Name == "NewPrimitive"
+ assert a_fco != fco
+ assert a_fco.IsEqual( fco)
+
+ # commit tran2
+ project.CommitTransaction()
+
+
+ project.Save()
+ project.Close(0)
+
+
+ pass
+
+ def populate6C(self, p):
+ c1 = bd.newObjInFold( p, p.RootFolder, 'Compound')
+ c1.Name = 'NewCompound'
+
+ p1 = bd.new( p, c1, 'PrimitiveParts')
+ p1.Name = 'NewPrimitiveParts'
+
+ @dec_disable_early_binding
+ def testC( self ):
+ """ testC
+
+ for a READ-ONLY project test methods like:
+ IsLibObject
+ IsWritable
+ Status
+
+ then
+
+ create another project
+ AttachLibrary attach the prev project as a library
+ IsLibObject, IsWritable check on its objects
+ """
+
+ mg1name = _adjacent_file("_tc6_C_readonly_sf.mga")
+
+ # if file exists from previous testing remove its readonly flag and delete the file
+ for file in (mg1name, mg1name + "tmp"):
+ if os.path.isfile(file):
+ # revert to read/write permission in order to delete it seamlessly
+ os.chmod(file, stat.S_IWUSR)
+ #delete:
+ #os.remove( mg1name)
+
+
+ # create the project with the needed kinds
+ project1 = bd.creaP( mg1name, "SF")
+ if not project1:
+ self.fail("Create failed")
+ try:
+ self.populate6C( project1)
+ except:
+ bd.saveP( project1)
+ raise
+ bd.saveP( project1)
+
+ self.project = project1
+
+ # make the file read-only and
+ # ... open the created project
+ try:
+ # make the file read-only
+ os.chmod( mg1name, stat.S_IRUSR)
+
+ readonly = project1.Open( "MGA=" + mg1name )
+ # assert readonly
+ except:
+ project1.Close(0)
+ raise
+
+ self.project = project1
+
+ terr1 = project1.CreateTerritory( None, None, None)
+ # begin transaction as TRANSACTION_READ_ONLY = 1
+ trans1 = project1.BeginTransaction( terr1, 1)
+ rf = project1.RootFolder
+
+ obj = rf.ObjectByPath( "#1")
+ assert obj.IsWritable # though the project is ReadOnly, the object itself is writable
+ assert not obj.IsLibObject # not a lib object
+ assert obj.Status == 0 # OBJECT_EXISTS defd in Mga.idl
+
+ # commit trans
+ project1.CommitTransaction()
+
+ # begin a regular transaction
+ trans2 = project1.BeginTransaction( terr1)
+
+ # and create an object
+ cmp1 = bd.newObjInFold( project1, rf, 'Compound')
+ cmp1.Name = "ThisObjectWillNotSurvive"
+
+ # commit trans
+ project1.CommitTransaction()
+
+ # now try to save it
+ try:
+ project1.Save()
+ assert False # it should have failed
+ except:
+ pass # it is OK to fail, since a Read-only file cannot not be saved modified
+
+ project1.Close(0)
+
+ mg2name = _adjacent_file("_tc6_C_libuser_sf.mga")
+
+ # create another project
+ project2 = bd.creaP( mg2name, "SF")
+ if not project2:
+ self.fail("Create failed for " + mg2name + " project")
+
+ bd.saveP( project2)
+
+ # open the created project
+ self.project = project2
+ try:
+ project2.Open( "MGA=" + mg2name )
+ except:
+ project2.Close(0)
+ raise
+
+
+ terr2 = project2.CreateTerritory( None, None, None)
+ trans3 = project2.BeginTransaction( terr2)
+ rf2 = project2.RootFolder
+
+ # attach mg1name to it
+ try:
+ # attach the read-only file as a library
+ libroot = project2.RootFolder.AttachLibrary( "MGA=" + mg1name)
+ pass
+ except:
+ print 'AttachLibrary failed'
+ raise
+
+
+
+ flds = project2.RootFolder.ChildFolders
+ assert flds.Count == 1
+
+ #the only subfolder of RootFolder is the library root
+ obj = flds.Item(1).GetChildFCODisp( "NewCompound")
+ assert obj.IsWritable # though the object is in a library it report itself as writable
+ assert obj.IsLibObject # a lib object
+ assert obj.Status == 0 # OBJECT_EXISTS defd in Mga.idl
+
+ # commit trans
+ project2.CommitTransaction()
+
+ project2.Save()
+ project2.Close(0)
+
+ def populate6D(self, p):
+ f1 = bd.newFolder( p, p.RootFolder, 'Folder')
+ f1.Name = 'NewFolder'
+
+ f2 = bd.newFolder( p, p.RootFolder, 'Folder')
+ f2.Name = 'NewFolder'
+
+ c1 = bd.newObjInFold( p, p.RootFolder, 'Compound')
+ c1.Name = 'NewCompound'
+
+ p1 = bd.newObjInFold( p, f1, 'Primitive')
+ p1.Name = 'NewPrimitive'
+
+ ip = bd.new( p, p1, 'InputParameters')
+ ip.Name = 'NewInputParameters'
+
+ is0 = bd.new( p, p1, 'InputSignals')
+ is0.Name = 'NewInputSignals'
+
+ op = bd.new( p, p1, 'OutputParameters')
+ op.Name = 'NewOutputParameters'
+
+ os = bd.new( p, p1, 'OutputSignals')
+ os.Name = 'NewOutputSignals'
+
+ pp = bd.new( p, p1, 'Parameters')
+ pp.Name = 'NewParameters'
+
+ p2 = bd.newObjInFold( p, f1, 'Primitive')
+ p2.Name = 'NewPrimitive'
+
+ op = bd.new( p, p2, 'OutputParameters')
+ op.Name = 'NewOutputParameters'
+
+ p2 = bd.newObjInFold( p, f2, 'Primitive')
+ p2.Name = 'NewPrimitive'
+
+ op = bd.new( p, p2, 'OutputParameters')
+ op.Name = 'NewOutputParameters'
+
+ cp1 = bd.new( p, c1, 'CompoundParts')
+ cp1.Name = 'NewCompoundParts'
+
+ pp1 = bd.new( p, c1, 'PrimitiveParts')
+ pp1.Name = 'NewPrimitiveParts'
+
+
+ @dec_disable_early_binding
+ def testD( self ):
+
+ """ testD
+
+ Check
+ CheckTree
+ ChildObjects
+ ChildObjectByRelID
+ """
+
+ mganame = _adjacent_file("_tc6_D_sf.mga")
+
+ # create the project with the needed kinds
+ project = bd.creaP( mganame, "SF")
+ if not project:
+ self.fail("Create failed")
+ try:
+ self.populate6D( project)
+ except:
+ bd.saveP( project)
+ raise
+ bd.saveP( project)
+
+ self.project = project
+
+ # open the created project
+ self.project = project
+ try:
+ project.Open( "MGA=" + mganame )
+ except:
+ project.Close(0)
+ raise
+
+ terr = project.CreateTerritory( None, None, None)
+ trans = project.BeginTransaction( terr)
+
+ rf = project.RootFolder
+
+ #objs = list( rf.ChildObjects )
+ objs = rf.ChildObjects
+ names = [ "NewFolder", "NewCompound"]
+ for obj in objs:
+ obj.Check()
+ obj.CheckTree()
+ rid = obj.RelID
+ one_obj = rf.ChildObjectByRelID( rid)
+ assert one_obj
+ assert one_obj.RelID == rid
+ name_dummy = one_obj.Name # it should not throw exc
+ assert name_dummy in names
+
+ one_fol = rf.ChildObjectByRelID( 1 )
+ assert one_fol.Name == names[0]
+
+ one_pri = one_fol.ChildObjectByRelID( 2 )
+ assert one_pri.Name == "NewPrimitive"
+ one_pri = one_fol.ChildObjectByRelID( 1 )
+ assert one_pri.Name == "NewPrimitive"
+
+ names = [ "NewInputParameters", "NewInputSignals", "NewOutputParameters", "NewOutputSignals", "NewParameters"]
+ name2relid = { "NewInputParameters" : 1,
+ "NewInputSignals" : 2,
+ "NewOutputParameters" : 3,
+ "NewOutputSignals" : 4,
+ "NewParameters" : 5
+ }
+
+ pri_objs = one_pri.ChildObjects
+ for pri_obj in pri_objs:
+ rid = pri_obj.RelID
+ one_obj = one_pri.ChildObjectByRelID( rid)
+ assert one_obj
+ assert one_obj.RelID == rid
+ s_name = one_obj.Name
+ assert s_name in names
+ assert name2relid[ s_name ] == rid
+
+ # commit trans
+ project.CommitTransaction()
+
+ project.Save()
+ project.Close(0)
+
+
+ @dec_disable_early_binding
+ def testE( self ):
+
+ """ testE
+
+ ObjectByPath
+ NthObjectByPath
+ """
+
+ mganame = _adjacent_file("_tc6_D_sf.mga") # uses the same as D
+
+ # create the project with the needed kinds - the same ad testD
+ project = bd.creaP( mganame, "SF")
+ if not project:
+ self.fail("Create failed")
+ try:
+ self.populate6D( project)
+ except:
+ bd.saveP( project)
+ raise
+ bd.saveP( project)
+
+ self.project = project
+
+ # open the created project
+ self.project = project
+ try:
+ project.Open( "MGA=" + mganame )
+ except:
+ project.Close(0)
+ raise
+
+ terr = project.CreateTerritory( None, None, None)
+
+ trans = project.BeginTransaction( terr)
+ rf = project.RootFolder
+
+ objs = list( rf.ChildObjects )
+
+ one_fol = rf.ChildObjectByRelID( 2 )
+ assert one_fol.Name == "NewFolder"
+ one_fol = rf.ChildObjectByRelID( 1 )
+ assert one_fol.Name == "NewFolder"
+
+ ### try the methods for the rootfolder looking for "NewFolder"
+ res = rf.ObjectByPath( "@NewFolder|kind=Folder") # search for a non-unique object, returns NULL
+ try:
+ assert not res
+ assert res == None
+ # this should throw 'AttributeError'
+ s_dummy = res.Name
+ assert 0
+ except AttributeError:
+ # goood, res is null
+ pass
+ except:
+ assert 0
+
+ res = rf.NthObjectByPath( 0, "@NewFolder|kind=Folder|relpos=0") # should be OK
+ assert res.Name == "NewFolder"
+
+
+ one_pri = one_fol.ChildObjectByRelID( 2 )
+ assert one_pri.Name == "NewPrimitive"
+ one_pri = one_fol.ChildObjectByRelID( 1 )
+ assert one_pri.Name == "NewPrimitive"
+
+ ### try the methods for the "NewFolder" looking for the primitive
+ res = one_fol.ObjectByPath( "@NewPrimitive|kind=Primitive") # search for a non-unique object, returns NULL
+ try:
+ # this should throw
+ s_dummy = res.Name
+ assert 0
+ except AttributeError:
+ # goood, res is null
+ pass
+ except:
+ assert 0
+
+ res = one_fol.NthObjectByPath( 0, "@NewPrimitive|kind=Primitive|relpos=0") # should be OK
+ assert res
+ assert res.Name == "NewPrimitive"
+ assert res == one_pri
+
+ ### ... now looking for an atom
+ res = one_fol.ObjectByPath( "@NewPrimitive|kind=Primitive/@NewOutputParameters|kind=OutputParam") # search for a non-unique object, returns NULL
+ try:
+ # this should throw
+ s_dummy = res.Name
+ assert 0
+ except AttributeError:
+ # goood, res is null
+ pass
+ except:
+ assert 0
+
+ res = one_fol.NthObjectByPath( 0, "@NewPrimitive|kind=Primitive|relpos=0/@NewOutputParameters|kind=OutputParam|relpos=0") # should be OK
+ assert res.Name == "NewOutputParameters"
+ assert res.RelID == 3
+
+ res = one_fol.NthObjectByPath( 0, "@NewPrimitive|kind=Primitive|relpos=1/@NewOutputParameters|kind=OutputParam|relpos=0") # should be OK
+ assert res.Name == "NewOutputParameters"
+ assert res.RelID == 1
+
+ ### try the methods for the "NewPrimitive" looking for the atom
+ res = one_pri.ObjectByPath( "@NewOutputParameters|kind=OutputParam") # search for a unique object
+ assert res.Name == "NewOutputParameters"
+ assert res.RelID == 3
+
+ res = one_pri.NthObjectByPath( 0, "@NewOutputParameters|kind=OutputParam|relpos=888") # should be OK, even with invalid relpos
+ assert res.Name == "NewOutputParameters"
+ assert res.RelID == 3 # the same as above
+
+ f1 = rf.ObjectByPath( "#1/#1/#3")
+ f2 = rf.NthObjectByPath( 0, "/@NewFolder|kind=Folder|relpos=0/@NewPrimitive|kind=Primitive|relpos=0/@NewOutputParameters|kind=OutputParam|relpos=0")
+ assert f1 == f2
+
+ f1 = rf.ObjectByPath( "#1/#2/#1")
+ f2 = rf.NthObjectByPath( 0, "/@NewFolder|kind=Folder|relpos=0/@NewPrimitive|kind=Primitive|relpos=1/@NewOutputParameters|kind=OutputParam|relpos=0")
+ assert f1 == f2
+
+ f1 = rf.ObjectByPath( "#2/#1/#1")
+ f2 = rf.NthObjectByPath( 0, "/@NewFolder|kind=Folder|relpos=1/@NewPrimitive|kind=Primitive|relpos=0/@NewOutputParameters|kind=OutputParam|relpos=0")
+ assert f1 == f2
+
+ # commit trans
+ project.CommitTransaction()
+
+ project.Save()
+ project.Close(0)
"""
- Let's produce the test suites
+ Let's produce the test suites
"""
# 1st way
def suites():
- suite = unittest.makeSuite(TestCase6,'test')
- return suite
+ suite = unittest.makeSuite(TestCase6,'test')
+ return suite
# 2nd way
def suites2():
- tc = TestCase6()
- #all = tc.my_suite()
- #return all
+ tc = TestCase6()
+ #all = tc.my_suite()
+ #return all
# 3rd way
def suites3():
- suite = unittest.TestSuite()
- suite.addTest( TestCase6( "testA"))
- #suite.addTest( TestCase6( "testB"))
- #suite.addTest( TestCase6( "testC"))
- return suite
+ suite = unittest.TestSuite()
+ suite.addTest( TestCase6( "testA"))
+ #suite.addTest( TestCase6( "testB"))
+ #suite.addTest( TestCase6( "testC"))
+ return suite
########
# main
########
if __name__ == "__main__":
- print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
- print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
- print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
- print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
- print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
- print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TEST BEGINS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
- print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
- print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
- print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
- print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
- print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
-
- ######## 1st way
- unittest.main()
-
- ######## 2nd way
- # unittest.main(defaultTest='TestCase6')
-
- ######## 3rd way
- # all = suites3()
- # runner = unittest.TextTestRunner()
- # runner.run( all )
+ print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+ print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+ print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+ print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+ print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+ print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TEST BEGINS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+ print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+ print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+ print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+ print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+ print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+
+ ######## 1st way
+ unittest.main()
+
+ ######## 2nd way
+ # unittest.main(defaultTest='TestCase6')
+
+ ######## 3rd way
+ # all = suites3()
+ # runner = unittest.TextTestRunner()
+ # runner.run( all )
Modified: trunk/Tests/GPyUnit/Regr/Mga/tc7.py
==============================================================================
--- trunk/Tests/GPyUnit/Regr/Mga/tc7.py Mon Jul 30 18:39:32 2012 (r1984)
+++ trunk/Tests/GPyUnit/Regr/Mga/tc7.py Wed Aug 1 10:58:37 2012 (r1985)
@@ -8,6 +8,10 @@
from GPyUnit.util import DispatchEx
+def _adjacent_file(file):
+ import os.path
+ return os.path.join(os.path.dirname(os.path.abspath(__file__)), file)
+
class TestCase7( unittest.TestCase ):
"""
avoid if possible the overriding of __init__, yet if you override use the following form:
@@ -76,7 +80,7 @@
ParentFolder
"""
- mganame = "_tc7_A_sf.mga"
+ mganame = _adjacent_file("_tc7_A_sf.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "SF")
@@ -172,7 +176,7 @@
ParentFolder
"""
- mganame = "_tc7_B_sf.mga"
+ mganame = _adjacent_file("_tc7_B_sf.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "SF")
@@ -307,7 +311,7 @@
PartByMetaPart
"""
- mganame = "_tc7_C_sf.mga"
+ mganame = _adjacent_file("_tc7_C_sf.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "SF")
@@ -410,7 +414,7 @@
then modify and inquire once again using the variant put/getter AttributeByName
"""
- mganame = "_tc7_D_sf.mga"
+ mganame = _adjacent_file("_tc7_D_sf.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "SF")
@@ -524,7 +528,7 @@
test put/get methods on double type FieldAttributes on a custom (FloatAttr) paradigm
"""
- mganame = "_tc7_F_fl.mga"
+ mganame = _adjacent_file("_tc7_F_fl.mga")
# create the project with the needed kinds
project = bd.creaP( mganame, "FloatAttr")
Modified: trunk/Tests/GPyUnit/Regr/Mga/utils/Builder.py
==============================================================================
--- trunk/Tests/GPyUnit/Regr/Mga/utils/Builder.py Mon Jul 30 18:39:32 2012 (r1984)
+++ trunk/Tests/GPyUnit/Regr/Mga/utils/Builder.py Wed Aug 1 10:58:37 2012 (r1985)
@@ -4,157 +4,157 @@
from GPyUnit.util import DispatchEx
def findInProj( project, obj_name = "", obj_kind = ""):
- """ Returns an object in project, satisfying the obj_name and obj_kind criteria, if speficied
- """
-
- # create a filter
- filter = project.CreateFilter()
-
- # use Name filter
- filter.Name = obj_name
- filter.Kind = obj_kind
-
- try:
- some_fcos = project.AllFCOs( filter )
- if some_fcos.Count > 0:
- return some_fcos.Item( 1 )
- else:
- print "findInProj >> Object not found : name = '" + obj_name + "' kind = '" + obj_kind + "'"
- assert 0
- except:
- print "findInProj >> Exception : name = '" + obj_name + "' kind = '" + obj_kind + "'"
- raise
+ """ Returns an object in project, satisfying the obj_name and obj_kind criteria, if speficied
+ """
+
+ # create a filter
+ filter = project.CreateFilter()
+
+ # use Name filter
+ filter.Name = obj_name
+ filter.Kind = obj_kind
+
+ try:
+ some_fcos = project.AllFCOs( filter )
+ if some_fcos.Count > 0:
+ return some_fcos.Item( 1 )
+ else:
+ print "findInProj >> Object not found : name = '" + obj_name + "' kind = '" + obj_kind + "'"
+ assert 0
+ except:
+ print "findInProj >> Exception : name = '" + obj_name + "' kind = '" + obj_kind + "'"
+ raise
- pass
+ pass
def folder( project, kind):
- """ Returns an IMgaMetaFolder pointer, based on the folder kind given """
- metaproj = project.RootMeta # an IMgaMetaProject
- metaroot = metaproj.RootFolder # an IMgaMetaFolder
-
- #assert project.RootFolder.MetaFolder == metaroot
-
- mfol = metaroot.LegalChildFolderByName(kind)
- return mfol
+ """ Returns an IMgaMetaFolder pointer, based on the folder kind given """
+ metaproj = project.RootMeta # an IMgaMetaProject
+ metaroot = metaproj.RootFolder # an IMgaMetaFolder
+
+ #assert project.RootFolder.MetaFolder == metaroot
+
+ mfol = metaroot.LegalChildFolderByName(kind)
+ return mfol
def kind(project, kind):
- """ Returns an IMgaMetaFCO pointer, based on the kind given """
- metaproj = project.RootMeta # an IMgaMetaProject
- metaroot = metaproj.RootFolder # an IMgaMetaFolder
-
- #assert project.RootFolder.MetaFolder == metaroot
-
- mfco = metaroot.DefinedFCOByName(kind, 1)
- return mfco
+ """ Returns an IMgaMetaFCO pointer, based on the kind given """
+ metaproj = project.RootMeta # an IMgaMetaProject
+ metaroot = metaproj.RootFolder # an IMgaMetaFolder
+
+ #assert project.RootFolder.MetaFolder == metaroot
+
+ mfco = metaroot.DefinedFCOByName(kind, 1)
+ return mfco
def role(project, model, role_str):
- """ Returns an IMgaMetaRole pointer, based on role_str and the container model (IMgaFCO) given """
- try:
- metaproj = project.RootMeta # an IMgaMetaProject
- metaroot = metaproj.RootFolder # an IMgaMetaFolder
-
- metacont = kind(project, model.MetaBase.Name)
- metarole = metacont.RoleByName(role_str)
-
- except:
- print 'No such kind:', role_str, 'in', model
- raise
- return metarole
+ """ Returns an IMgaMetaRole pointer, based on role_str and the container model (IMgaFCO) given """
+ try:
+ metaproj = project.RootMeta # an IMgaMetaProject
+ metaroot = metaproj.RootFolder # an IMgaMetaFolder
+
+ metacont = kind(project, model.MetaBase.Name)
+ metarole = metacont.RoleByName(role_str)
+
+ except:
+ print 'No such kind:', role_str, 'in', model
+ raise
+ return metarole
def new(p, cont, role_str):
- """ Creates an fco, in role_str role in container model specified """
- return cont.CreateChildObject( role(p, cont, role_str))
+ """ Creates an fco, in role_str role in container model specified """
+ return cont.CreateChildObject( role(p, cont, role_str))
def subtype(p, cont, base):
- """ Creates a derived fco from base, in the same role as base in container model specified """
- return cont.DeriveChildObject( base, base.MetaRole, False)
+ """ Creates a derived fco from base, in the same role as base in container model specified """
+ return cont.DeriveChildObject( base, base.MetaRole, False)
def instantiate(p, cont, type):
- """ Instantiates an fco from type, in the same role as type in container model specified """
- return cont.DeriveChildObject( type, type.MetaRole, True)
+ """ Instantiates an fco from type, in the same role as type in container model specified """
+ return cont.DeriveChildObject( type, type.MetaRole, True)
def newObjInFold(p, fold, kind_str):
- """ Creates an object in a folder/rootfolder, based on kind_str"""
- return fold.CreateRootObject( kind( p, kind_str))
+ """ Creates an object in a folder/rootfolder, based on kind_str"""
+ return fold.CreateRootObject( kind( p, kind_str))
def subtypeInFold(p, cont, base):
- """ Creates a derived fco from base, in the folder specified """
- return cont.DeriveRootObject( base, False)
+ """ Creates a derived fco from base, in the folder specified """
+ return cont.DeriveRootObject( base, False)
def instantiateInFold(p, cont, type):
- """ Instantiates an fco from type, in the folder specified """
- return cont.DeriveRootObject( type, True)
+ """ Instantiates an fco from type, in the folder specified """
+ return cont.DeriveRootObject( type, True)
def newFolder(p, parent, folder_kind_str):
- """ Creates a folder_kind_str folder in parent"""
- return parent.CreateFolder( folder( p, folder_kind_str))
+ """ Creates a folder_kind_str folder in parent"""
+ return parent.CreateFolder( folder( p, folder_kind_str))
def connect(p, cont, s, d, role_str):
- """ Helper method connecting plain fcos/ports, when no references are involved
- """
- z0 = DispatchEx("Mga.MgaFCOs")
- return cont.CreateSimpleConn( role(p, cont, role_str), s, d, z0, z0)
+ """ Helper method connecting plain fcos/ports, when no references are involved
+ """
+ z0 = DispatchEx("Mga.MgaFCOs")
+ return cont.CreateSimpleConn( role(p, cont, role_str), s, d, z0, z0)
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)
+ """ 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 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
+ 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 saveP(project):
- try:
- project.CommitTransaction()
- except:
- project.AbortTransaction()
- project.Save()
- project.Close(0)
+ try:
+ project.CommitTransaction()
+ except:
+ project.AbortTransaction()
+ project.Save()
+ project.Close(0)
def populate(p):
- """Sample: The way the tester could build up a model needed for a test
- """
- folder1 = newFolder( p, p.RootFolder, 'SheetFolder')
- folder1.Name = 'SheetFolder1'
-
- parsh1 = newObjInFold( p, folder1, 'ParadigmSheet')
- parsh1.Name = 'ParadigmSheet1'
-
- at1 = new( p, parsh1, 'Atom')
- at1.Name = 'Atom1'
-
- at2 = new( p, parsh1, 'Atom')
- at2.Name = 'Atom2'
-
- ap1 = new( p, parsh1, 'AtomProxy')
- ap1.Name = 'AtProx1'
-
- ap2 = new( p, parsh1, 'AtomProxy')
- ap2.Name = 'AtProx2'
-
- ap1.Referred = at1
- ap2.Referred = at2
+ """Sample: The way the tester could build up a model needed for a test
+ """
+ folder1 = newFolder( p, p.RootFolder, 'SheetFolder')
+ folder1.Name = 'SheetFolder1'
+
+ parsh1 = newObjInFold( p, folder1, 'ParadigmSheet')
+ parsh1.Name = 'ParadigmSheet1'
+
+ at1 = new( p, parsh1, 'Atom')
+ at1.Name = 'Atom1'
+
+ at2 = new( p, parsh1, 'Atom')
+ at2.Name = 'Atom2'
+
+ ap1 = new( p, parsh1, 'AtomProxy')
+ ap1.Name = 'AtProx1'
+
+ ap2 = new( p, parsh1, 'AtomProxy')
+ ap2.Name = 'AtProx2'
+
+ ap1.Referred = at1
+ ap2.Referred = at2
More information about the gme-commit
mailing list