[GME-commit]
GMESRC/Tests/GPyUnit/Regr/Mga tc8.py,NONE,1.1 tc4.py,1.1,1.2
tc6.py,1.1,1.2 tc7.py,1.1,1.2
gme-commit at list.isis.vanderbilt.edu
gme-commit at list.isis.vanderbilt.edu
Thu Dec 1 20:54:47 CST 2005
Update of /project/gme-repository/GMESRC/Tests/GPyUnit/Regr/Mga
In directory escher:/tmp/cvs-serv15908
Modified Files:
tc4.py tc6.py tc7.py
Added Files:
tc8.py
Log Message:
Testcases, benefiting from the dispatch-enabled mga methods.
CVS User: Zoltan Molnar, ISIS (zolmol)
Index: tc6.py
===================================================================
RCS file: /project/gme-repository/GMESRC/Tests/GPyUnit/Regr/Mga/tc6.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** tc6.py 29 Nov 2005 22:10:29 -0000 1.1
--- tc6.py 1 Dec 2005 20:54:45 -0000 1.2
***************
*** 175,189 ****
def populate6C(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'
def testC( self ):
-
""" testC
--- 175,185 ----
def populate6C(self, p):
c1 = bd.newObjInFold( p, p.RootFolder, 'Compound')
c1.Name = 'NewCompound'
! p1 = bd.new( p, c1, 'PrimitiveParts')
! p1.Name = 'NewPrimitiveParts'
def testC( self ):
""" testC
***************
*** 192,249 ****
IsWritable
Status
"""
! mganame = "_tc6_C_readonly_sf.mga"
# if file exists from previous testing remove its readonly flag and delete the file
! if os.path.isfile( mganame):
# revert to read/write permission in order to delete it seamlessly
! os.chmod( mganame, stat.S_IWUSR)
#delete:
! #os.remove( mganame)
# create the project with the needed kinds
! project = bd.creaP( mganame, "SF")
! if not project:
self.fail("Create failed")
try:
! self.populate6C( project)
except:
! bd.saveP( project)
raise
! bd.saveP( project)
! self.project = project
! # open the created project
try:
# make the file read-only
! os.chmod( mganame, stat.S_IRUSR)
! readonly = project.Open( "MGA=" + mganame )
assert readonly
except:
! project.Close(0)
raise
! terr = project.CreateTerritory( None, None, None)
# begin transaction as TRANSACTION_READ_ONLY = 1
! trans = project.BeginTransaction( terr, 1)
! rf = project.RootFolder
obj = rf.ObjectByPath( "#1")
! assert not obj.IsWritable == 0
! assert not obj.IsLibObject == 0
assert obj.Status == 0 # OBJECT_EXISTS defd in Mga.idl
! # abort trans
! project.AbortTransaction()
! project.Save()
! project.Close(0)
def populate6D(self, p):
--- 188,316 ----
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
! if os.path.isfile( mg1name):
# revert to read/write permission in order to delete it seamlessly
! os.chmod( mg1name, 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):
***************
*** 371,376 ****
assert name2relid[ s_name ] == rid
! # abort trans
! project.AbortTransaction()
project.Save()
--- 438,443 ----
assert name2relid[ s_name ] == rid
! # commit trans
! project.CommitTransaction()
project.Save()
***************
*** 380,384 ****
def testE( self ):
! """ DESCRIPTION
ObjectByPath
--- 447,451 ----
def testE( self ):
! """ testE
ObjectByPath
***************
*** 502,507 ****
assert f1 == f2
! # abort trans
! project.AbortTransaction()
project.Save()
--- 569,574 ----
assert f1 == f2
! # commit trans
! project.CommitTransaction()
project.Save()
Index: tc4.py
===================================================================
RCS file: /project/gme-repository/GMESRC/Tests/GPyUnit/Regr/Mga/tc4.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** tc4.py 10 Jun 2005 21:25:47 -0000 1.1
--- tc4.py 1 Dec 2005 20:54:45 -0000 1.2
***************
*** 1383,1387 ****
def testI( self ):
! """ DESCRIPTION
BeginTransaction
--- 1383,1387 ----
def testI( self ):
! """ testI
BeginTransaction
***************
*** 1465,1469 ****
def testJ( self ):
! """ DESCRIPTION
BeginTransaction
--- 1465,1469 ----
def testJ( self ):
! """ testJ
BeginTransaction
--- NEW FILE: tc8.py ---
import unittest
import win32com.client
import win32ui
import pythoncom
import os
import utils.Builder
bd = utils.Builder
class TestCase8( unittest.TestCase ):
"""
avoid if possible the overriding of __init__, yet if you override use the following form:
def __init__(self, methodName='runTest'):
unittest.TestCase.__init__(self, methodName)
"""
def setUp( self ): ## hook method
pass
def tearDown( self ): ## hook method
self.project.Close( 0 )
pass
def findInProj( self, project, obj_name = "", obj_kind = ""):
# 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 + "'"
assert 0
pass
def populate8A(self, p):
fff = bd.newFolder( p, p.RootFolder, 'TOSFolder')
fff.Name = 'NewTOSFolder'
md = bd.newObjInFold( p, fff, 'module')
md.Name = 'Newmodule'
st = bd.new( p, md, 'State')
st.Name = 'NewState'
def testA( self ):
""" testA
testing methods of IMgaFCO
Constraints([in] VARIANT_BOOL includemeta, [out, retval] IMgaConstraints **pVal);
AddConstraint([in] IMgaConstraint *constraint);
DefineConstraint([in] BSTR name, [in] long mask, [in] BSTR expr, [out] IMgaConstraint **nconstraint);
and methods of IMgaObject
Check
"""
mganame = "_tc8_A_gr.mga"
# create the project with the needed kinds
project = bd.creaP( mganame, "GRATISII")
if not project:
self.fail("Create failed")
try:
self.populate8A( 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)
to_find = "Newmodule"
obj = self.findInProj( project, to_find)
try:
nnnname = obj.Name
except:
print "Caught 1"
assert 0
print 'a1'
expr = "let modules = project.allInstancesOf( module ) in modules->select( n | n.name.trim() = name )->size <= 1"
print 'a2'
newconstraint = obj.DefineConstraint( "new_constraint_defined", 0, expr)
print 'a3'
obj.AddConstraint( newconstraint )
print 'a4'
obj.Check()
print 'a5'
obj.CheckTree()
print 'a6'
# commit trans
project.CommitTransaction()
print 'a7'
project.Save()
project.Close(0)
pass
def populate8B(self, p):
fff = bd.newFolder( p, p.RootFolder, 'TOSFolder')
fff.Name = 'NewTOSFolder'
cnf = bd.newObjInFold( p, fff, 'configuration')
cnf.Name = 'NewconfigurationB'
cnS = bd.subtypeInFold( p, fff, cnf)
cnS.Name = 'NewconfigurationS'
cnI = bd.instantiateInFold( p, fff, cnf)
cnI.Name = 'NewconfigurationI'
def testB( self ):
""" testB
test methods of IMgaFCO
DerivedObjects
DerivedFrom
IsInstance
Type
BaseType
ArcheType
IsPrimaryDerived
"""
mganame = "_tc8_B_gr.mga"
# create the project with the needed kinds
project = bd.creaP( mganame, "GRATISII")
if not project:
self.fail("Create failed")
try:
self.populate8B( 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)
to_find = "NewconfigurationB"
obj = self.findInProj( project, to_find)
ders = obj.DerivedObjects
for i in range( 1, ders.Count + 1):
one_der = ders.Item( i )
assert obj == one_der.DerivedFrom
if one_der.IsInstance:
inst = one_der
base = one_der.Type
assert inst.Name == "NewconfigurationI"
assert base.Name == "NewconfigurationB"
assert base == inst.ArcheType
assert inst.IsPrimaryDerived
else:
subt = one_der
base = one_der.BaseType
assert subt.Name == "NewconfigurationS"
assert base.Name == "NewconfigurationB"
assert base == subt.ArcheType
assert subt.IsPrimaryDerived
# commit trans
project.CommitTransaction()
project.Save()
project.Close(0)
pass
def populate8C(self, p):
fff = bd.newFolder( p, p.RootFolder, 'TOSFolder')
fff.Name = 'NewTOSFolder'
int = bd.newObjInFold( p, fff, 'interface')
int.Name = 'NewinterfaceB'
pps = bd.new( p, int, 'PreprocessorSet')
pps.Name = 'NewPreprocessorSet'
sta = bd.new( p, int, 'State')
sta.Name = 'NewStateB'
eve = bd.new( p, int, 'event')
eve.Name = 'Newevent'
# subtype int
inS = bd.subtypeInFold( p, fff, int)
inS.Name = 'NewinterfaceS'
# rename its child
inS.ChildFCO('NewStateB').Name = 'NewStateS'
# instantiate int
inI = bd.instantiateInFold( p, fff, int)
inI.Name = 'NewinterfaceI'
# rename its child
inI.ChildFCO('NewStateB').Name = 'NewStateI'
# subtype inS (the subtype of int)
inSS = bd.subtypeInFold( p, fff, inS)
inSS.Name = 'NewinterfaceSS'
# rename its child
inSS.ChildFCO('NewStateS').Name = 'NewStateSS'
def testC( self ):
""" testC
test methods of IMgaFCO
DerivedFrom
BaseType
ArcheType
IsPrimaryDerived
test objects which are derived along with their parents (not on their own) -> these are the nonprimaryderived ones
test subtypes of subtypes
"""
mganame = "_tc8_C_gr.mga"
# create the project with the needed kinds
project = bd.creaP( mganame, "GRATISII")
if not project:
self.fail("Create failed")
try:
self.populate8C( 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)
to_find = "NewStateB" # not a primary derived obj (derived along with a Newinterface)
statB = self.findInProj( project, to_find)
to_find = "NewStateI"
statI = self.findInProj( project, to_find)
to_find = "NewStateS"
statS = self.findInProj( project, to_find)
assert not statI.IsPrimaryDerived
assert statI.Type == statB
assert not statS.IsPrimaryDerived
assert statS.BaseType == statB
to_find = "NewinterfaceB"
arch = self.findInProj( project, to_find)
to_find = "NewinterfaceS" # a subtype of "arch"
subt = self.findInProj( project, to_find)
to_find = "NewinterfaceSS" # a subtype of "subt"
subt_two = self.findInProj( project, to_find)
assert subt_two.BaseType == subt
assert subt_two.DerivedFrom == subt
assert subt.BaseType == arch
assert subt.DerivedFrom == arch
assert subt_two.ArcheType == arch
assert subt.ArcheType == arch
# commit trans
project.CommitTransaction()
project.Save()
project.Close(0)
pass
def populate8D(self, p):
fff = bd.newFolder( p, p.RootFolder, 'TOSFolder')
fff.Name = 'NewTOSFolder'
md = bd.newObjInFold( p, fff, 'module')
md.Name = 'Newmodule'
tr = bd.new( p, md, 'Transition')
tr.Name = 'NewTransition'
# instantiate md
mdI = bd.instantiateInFold( p, fff, md)
mdI.Name = 'Newmodule_in'
# subtype md
mdS = bd.subtypeInFold( p, fff, md)
mdS.Name = 'Newmodule_st'
# create a new child in mdS (a subtype of md)
pps = bd.new( p, mdS, 'PreprocessorSet')
# instantiate mdS
mdSI = bd.instantiateInFold( p, fff, mdS)
mdSI.Name = 'Newmodule_st_in'
def testD( self ):
""" testD
test instances of subtypes
"""
mganame = "_tc8_D_gr.mga"
# create the project with the needed kinds
project = bd.creaP( mganame, "GRATISII")
if not project:
self.fail("Create failed")
try:
self.populate8D( 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)
to_find = "Newmodule"
modB = self.findInProj( project, to_find)
to_find = "Newmodule_st" # subtype of modB
modS = self.findInProj( project, to_find)
to_find = "Newmodule_st_in" # instance of the modS subtype
modIofS = self.findInProj( project, to_find)
assert modS.IsPrimaryDerived
assert modIofS.IsPrimaryDerived
assert modIofS.IsInstance
assert modS.BaseType == modB
assert modIofS.Type == modS # RESU: modIofS (instance of subtype) is derived from modB according to the tests
assert modS.DerivedFrom == modB
assert modIofS.DerivedFrom == modS # RESU: see above
assert modS.ArcheType == modB
assert modIofS.ArcheType == modS # archetype of modIofS is the subtype # RESU: see above
# commit trans
project.CommitTransaction()
project.Save()
project.Close(0)
pass
def populate8E(self, p):
fff = bd.newFolder( p, p.RootFolder, 'TOSFolder')
fff.Name = 'NewTOSFolder'
cnf = bd.newObjInFold( p, fff, 'configuration')
cnf.Name = 'NewconfigurationB'
sta = bd.new( p, cnf, 'State')
sta.Name = 'NewStateB'
sta.SetBoolAttrByNameDisp( 'IsInitial', True)
# subtype cnf
cnS = bd.subtypeInFold( p, fff, cnf)
cnS.Name = 'NewconfigurationS'
# rename its child
staS = cnS.ChildFCO('NewStateB')
staS.Name = 'NewStateS'
# set its attribute to a different value from its inherited
# thus, this attribute will be detached from the archetype's attr
staS.SetBoolAttrByNameDisp( 'IsInitial', False)
def testE( self ):
""" testE
open a project where the subtype has been detached manually already
modify attribute (when available) and test whether the modification is
propagated down the hierarchy (the subtype is detached already)
"""
mganame = "_tc8_E_gr.mga"
# create the project with the needed kinds
project = bd.creaP( mganame, "GRATISII")
if not project:
self.fail("Create failed")
try:
self.populate8E( 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)
to_find = "NewStateB"
statB = self.findInProj( project, to_find)
to_find = "NewStateS"
statS = self.findInProj( project, to_find)
# inquiring the "IsInitial" attribute of the two objects
statB_bval = statB.GetBoolAttrByNameDisp( "IsInitial" )
statS_bval = statS.GetBoolAttrByNameDisp( "IsInitial" )
assert statB_bval
assert not statS_bval
# modify attribute and test whether the modification is propagated down the hierarchy
# really is not a modification
statB.SetBoolAttrByNameDisp( "IsInitial", True )
# is propagated down?
statS_bval = statS.GetBoolAttrByNameDisp( "IsInitial" )
assert not statS_bval
# commit trans
project.CommitTransaction()
project.Save()
project.Close(0)
pass
def populate8F(self, p):
fff = bd.newFolder( p, p.RootFolder, 'TOSFolder')
fff.Name = 'NewTOSFolder'
cnf = bd.newObjInFold( p, fff, 'configuration')
cnf.Name = 'Newconfiguration'
staB = bd.new( p, cnf, 'State')
staB.Name = 'NewStateB'
# subtype staB
staS = bd.subtype( p, cnf, staB)
staS.Name = 'NewStateS'
def testF( self ):
""" testF
test methods of IMgaFCO
DetachFromArcheType()
detach a subtype programatically and
modify attribute (when available) and test whether the modification is
propagated down the hierarchy (the subtype is detached already)
[ helpstring("method AttachToArcheType")]
HRESULT AttachToArcheType([in] IMgaFCO *newtype, [in] VARIANT_BOOL instance);
[ helpstring("method DetachFromArcheType")]
HRESULT DetachFromArcheType();
"""
mganame = "_tc8_F_gr.mga"
# create the project with the needed kinds
project = bd.creaP( mganame, "GRATISII")
if not project:
self.fail("Create failed")
try:
self.populate8F( 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)
to_find = "NewStateB"
statB = self.findInProj( project, to_find)
to_find = "NewStateS"
statS = self.findInProj( project, to_find)
# inquiring the "IsInitial" attribute of the two objects
statB_bval = statB.GetBoolAttrByNameDisp( "IsInitial" )
statS_bval = statS.GetBoolAttrByNameDisp( "IsInitial" )
assert not statB_bval
assert not statS_bval
# detach the subtype
statS.DetachFromArcheType()
# modify attribute and test whether the modification is propagated down the hierarchy
statB.SetBoolAttrByNameDisp( "IsInitial", True )
# is propagated down?
statS_bval = statS.GetBoolAttrByNameDisp( "IsInitial" )
assert not statS_bval
# commit trans
project.CommitTransaction()
project.Save()
project.Close(0)
pass
def populate8G(self, p):
fff = bd.newFolder( p, p.RootFolder, 'TOSFolder')
fff.Name = 'NewTOSFolder'
cnf = bd.newObjInFold( p, fff, 'configuration')
cnf.Name = 'Newconfiguration'
staB = bd.new( p, cnf, 'State')
staB.Name = 'NewStateB'
# subtype staB
staS = bd.subtype( p, cnf, staB)
staS.Name = 'NewStateS'
# instantiate staB
staI = bd.instantiate( p, cnf, staB)
staI.Name = 'NewStateI'
def testG( self ):
""" testG
test methods of IMgaFCO
DetachFromArcheType
AttachToArcheType
"""
mganame = "_tc8_G_gr.mga"
# create the project with the needed kinds
project = bd.creaP( mganame, "GRATISII")
if not project:
self.fail("Create failed")
try:
self.populate8G( 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)
to_find = "NewStateB"
statB = self.findInProj( project, to_find)
to_find = "NewStateS"
statS = self.findInProj( project, to_find)
to_find = "NewStateI"
statI = self.findInProj( project, to_find)
# inquiring the "IsInitial" attribute of the two objects
statB_bval = statB.GetBoolAttrByNameDisp( "IsInitial" )
statS_bval = statS.GetBoolAttrByNameDisp( "IsInitial" )
statI_bval = statI.GetBoolAttrByNameDisp( "IsInitial" )
assert not statB_bval
assert not statS_bval
assert not statI_bval
# detach the subtype and instance
statS.DetachFromArcheType()
statI.DetachFromArcheType()
# modify attribute when available and test whether the modification is propagated down the hierarchy
statB.SetBoolAttrByNameDisp( "IsInitial", True )
# is propagated down? It should not
statS_bval = statS.GetBoolAttrByNameDisp( "IsInitial" )
statI_bval = statI.GetBoolAttrByNameDisp( "IsInitial" )
assert not statS_bval
assert not statI_bval
# attach again
statS.AttachToArcheType( statB, False) # isinstance: false
statI.AttachToArcheType( statB, True) # isinstance: true
# modify attribute and test ...
# really is not a modification
statB.SetBoolAttrByNameDisp( "IsInitial", True )
# is propagated down? It should
statS_bval = statS.GetBoolAttrByNameDisp( "IsInitial" )
statI_bval = statI.GetBoolAttrByNameDisp( "IsInitial" )
assert statS_bval
assert statI_bval
# commit trans
project.CommitTransaction()
project.Save()
project.Close(0)
pass
"""
Let's produce the test suites
"""
# 1st way
def suites():
suite = unittest.makeSuite(TestCase8,'test')
return suite
# 2nd way
def suites2():
tc = TestCase8()
#all = tc.my_suite()
#return all
# 3rd way
def suites3():
suite = unittest.TestSuite()
suite.addTest( TestCase8( "testA"))
#suite.addTest( TestCase8( "testB"))
#suite.addTest( TestCase8( "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='TestCase8')
######## 3rd way
# all = suites3()
# runner = unittest.TextTestRunner()
# runner.run( all )
Index: tc7.py
===================================================================
RCS file: /project/gme-repository/GMESRC/Tests/GPyUnit/Regr/Mga/tc7.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** tc7.py 29 Nov 2005 22:10:29 -0000 1.1
--- tc7.py 1 Dec 2005 20:54:45 -0000 1.2
***************
*** 22,29 ****
pass
- def runTest():
- testA()
- testB()
-
def findInProj( self, project, obj_name = "", obj_kind = ""):
--- 22,25 ----
***************
*** 72,76 ****
def testA( self ):
! """ testA DESCRIPTION
test properties of IMgaFCO such as
Meta
--- 68,72 ----
def testA( self ):
! """ testA
test properties of IMgaFCO such as
Meta
***************
*** 172,176 ****
def testB( self ):
! """ testB DESCRIPTION
test properties of IMgaFCO such as
ParentModel
--- 168,172 ----
def testB( self ):
! """ testB
test properties of IMgaFCO such as
ParentModel
***************
*** 309,313 ****
def testC( self ):
! """ testC DESCRIPTION
test properties of IMgaFCO such as
Part
--- 305,309 ----
def testC( self ):
! """ testC
test properties of IMgaFCO such as
Part
***************
*** 399,404 ****
pass
def testD( self ):
! """ testD DESCRIPTION
test properties of IMgaFCO such as
AttributeByName -get/put
--- 395,411 ----
pass
+ def populate7D(self, p):
+ c1 = bd.newObjInFold( p, p.RootFolder, 'Compound')
+ c1.Name = 'NewCompound'
+
+ p1 = bd.new( p, c1, 'PrimitiveParts')
+ p1.Name = 'NewPrimitiveParts'
+
+ ip1 = bd.new( p, p1, 'InputParameters')
+ ip1.Name = 'NewInputParameters'
+
+
def testD( self ):
! """ testD
test properties of IMgaFCO such as
AttributeByName -get/put
***************
*** 418,422 ****
self.fail("Create failed")
try:
! self.populate7C( project)
except:
bd.saveP( project)
--- 425,429 ----
self.fail("Create failed")
try:
! self.populate7D( project)
except:
bd.saveP( project)
***************
*** 438,445 ****
trans = project.BeginTransaction( terr)
! to_find = "id-0066-00000006"
ip = project.GetFCOByID( to_find ) # inputparameter
! to_find = "id-0065-00000008"
pp = project.GetFCOByID( to_find ) # newprimitiveparts
--- 445,452 ----
trans = project.BeginTransaction( terr)
! to_find = "id-0066-00000001"
ip = project.GetFCOByID( to_find ) # inputparameter
! to_find = "id-0065-00000002"
pp = project.GetFCOByID( to_find ) # newprimitiveparts
***************
*** 447,505 ****
aspect_2 = pp.Meta.AspectByName("SignalFlowAspect")
! assert 1 == ip.IntAttrByName( "Size" )
! assert "Integer" == ip.StrAttrByName( "DataType" )
# modify attributes
! ip.SetIntAttrByNameDisp( "Size", 2) # RESU: currently fails
! ip.SetStrAttrByNameDisp( "DataType", "Double") # RESU: currently fails
! assert 2 == ip.IntAttrByName( "Size" )
! assert "Double" == ip.StrAttrByName( "DataType" )
# revert changes
! ip.IntAttrByName( "Size", 1)
! ip.StrAttrByName( "DataType", "Integer")
! assert 10 == pp.IntAttrByName( "Priority" )
! assert "" == pp.StrAttrByName( "Script" )
! assert "IFALL" == pp.StrAttrByName( "Firing" )
# modify
! pp.IntAttrByName( "Priority", 5 )
d_s = "int dummy_script()\n{ return 1; }"
! pp.StrAttrByName( "Script", d_s)
! pp.StrAttrByName( "Firing", "IFANY" )
! assert 5 == pp.IntAttrByName( "Priority" )
! assert d_s == pp.StrAttrByName( "Script" )
! assert "IFANY" == pp.StrAttrByName( "Firing" )
# test whether VARIANTS are returning back the values
pr = 0 # integer
! pr = pp.AttributeByName( "Priority")
assert pr == 5
scr = ""
! scr = pp.AttributeByName( "Script" )
assert scr == d_s
fir = "IFALL"
! fir = pp.AttributeByName( "Firing" )
assert "IFANY" == fir
# revert changes using AttributeByName (test whether VARIANTS are interpreted all right)
old_pr_val = 10
! pp.AttributeByName( "Priority", old_pr_val )
old_scr_val = ""
! pp.AttributeByName( "Script", old_scr_val )
old_fir_val = "IFALL"
! pp.AttributeByName( "Firing", old_fir_val )
# the values must be the original ones
! assert 10 == pp.IntAttrByName( "Priority")
! assert "" == pp.StrAttrByName( "Script")
! assert "IFALL" == pp.StrAttrByName( "Firing")
# commit trans
--- 454,512 ----
aspect_2 = pp.Meta.AspectByName("SignalFlowAspect")
! assert 1 == ip.GetIntAttrByNameDisp( "Size" ) # default value
! assert "Integer" == ip.GetStrAttrByNameDisp( "DataType" ) # default value
# modify attributes
! ip.SetIntAttrByNameDisp( "Size", 2)
! ip.SetStrAttrByNameDisp( "DataType", "Double")
! assert 2 == ip.GetIntAttrByNameDisp( "Size" )
! assert "Double" == ip.GetStrAttrByNameDisp( "DataType" )
# revert changes
! ip.SetIntAttrByNameDisp( "Size", 1)
! ip.SetStrAttrByNameDisp( "DataType", "Integer")
! assert 10 == pp.GetIntAttrByNameDisp( "Priority" )
! assert "" == pp.GetStrAttrByNameDisp( "Script" )
! assert "IFALL" == pp.GetStrAttrByNameDisp( "Firing" )
# modify
! pp.SetIntAttrByNameDisp( "Priority", 5 )
d_s = "int dummy_script()\n{ return 1; }"
! pp.SetStrAttrByNameDisp( "Script", d_s)
! pp.SetStrAttrByNameDisp( "Firing", "IFANY" )
! assert 5 == pp.GetIntAttrByNameDisp( "Priority" )
! assert d_s == pp.GetStrAttrByNameDisp( "Script" )
! assert "IFANY" == pp.GetStrAttrByNameDisp( "Firing" )
# test whether VARIANTS are returning back the values
pr = 0 # integer
! pr = pp.GetAttributeByNameDisp( "Priority")
assert pr == 5
scr = ""
! scr = pp.GetAttributeByNameDisp( "Script" )
assert scr == d_s
fir = "IFALL"
! fir = pp.GetAttributeByNameDisp( "Firing" )
assert "IFANY" == fir
# revert changes using AttributeByName (test whether VARIANTS are interpreted all right)
old_pr_val = 10
! pp.SetAttributeByNameDisp( "Priority", old_pr_val )
old_scr_val = ""
! pp.SetAttributeByNameDisp( "Script", old_scr_val )
old_fir_val = "IFALL"
! pp.SetAttributeByNameDisp( "Firing", old_fir_val )
# the values must be the original ones
! assert 10 == pp.GetIntAttrByNameDisp( "Priority")
! assert "" == pp.GetStrAttrByNameDisp( "Script")
! assert "IFALL" == pp.GetStrAttrByNameDisp( "Firing")
# commit trans
***************
*** 568,572 ****
def testE( self ):
! """ testE DESCRIPTION
test properties of IMgaFCO such as
AttributeByName -get/put
--- 575,579 ----
def testE( self ):
! """ testE
test properties of IMgaFCO such as
AttributeByName -get/put
***************
*** 637,647 ****
# modify attributes
! ns.SetBoolAttrByNameDisp( "IsInitial", True) # RESU: currently fails
! ne.SetBoolAttrByNameDisp( "Default", True) # RESU: currently fails
! ne.SetBoolAttrByNameDisp( "Async", True) # RESU: currently fails
assert True == ns.BoolAttrByName( "IsInitial" )
try:
! assert -1 == ns.IntAttrByName ( "IsInitial" ) # try if it works
except:
pass
--- 644,654 ----
# modify attributes
! ns.SetBoolAttrByNameDisp( "IsInitial", True)
! ne.SetBoolAttrByNameDisp( "Default", True)
! ne.SetBoolAttrByNameDisp( "Async", True)
assert True == ns.BoolAttrByName( "IsInitial" )
try:
! assert -1 == ns.GetIntAttrByNameDisp ( "IsInitial" ) # try if it works
except:
pass
***************
*** 652,658 ****
# revert changes
! ns.SetBoolAttrByNameDisp( "IsInitial", False) # RESU: currently fails
! ne.SetBoolAttrByNameDisp( "Default", False) # RESU: currently fails
! ne.SetBoolAttrByNameDisp( "Async", False) # RESU: currently fails
assert False == ns.BoolAttrByName( "IsInitial" )
--- 659,665 ----
# revert changes
! ns.SetBoolAttrByNameDisp( "IsInitial", False)
! ne.SetBoolAttrByNameDisp( "Default", False)
! ne.SetBoolAttrByNameDisp( "Async", False)
assert False == ns.BoolAttrByName( "IsInitial" )
***************
*** 663,683 ****
# modify values using AttributeByName (test whether VARIANTS are interpreted all right)
! ns.SetAttributeByNameDisp( "IsInitial", True ) # RESU: currently fails
! ne.SetAttributeByNameDisp( "Default", True ) # RESU: currently fails
! ne.SetAttributeByNameDisp( "Async", True ) # RESU: currently fails
# test whether VARIANTS are returning back good boolean values
! bVal1 = True # bool
! bVal2 = True
! bVal3 = True
! bVal1 = ns.AttributeByName( "IsInitial" )
! bVal2 = ne.AttributeByName( "Default" )
! bVal3 = ne.AttributeByName( "Async" )
! assert bVal1 == False
! assert bVal2 == False
! assert bVal3 == False
# reset the attribute to its default value and to its unset state
--- 670,690 ----
# modify values using AttributeByName (test whether VARIANTS are interpreted all right)
! ns.SetAttributeByNameDisp( "IsInitial", True )
! ne.SetAttributeByNameDisp( "Default", True )
! ne.SetAttributeByNameDisp( "Async", True )
# test whether VARIANTS are returning back good boolean values
! bVal1 = False # bool init, so that VARIANTs are converted to bool
! bVal2 = False
! bVal3 = False
! bVal1 = ns.GetAttributeByNameDisp( "IsInitial")
! bVal2 = ne.GetAttributeByNameDisp( "Default")
! bVal3 = ne.GetAttributeByNameDisp( "Async")
! assert bVal1 == True
! assert bVal2 == True
! assert bVal3 == True
# reset the attribute to its default value and to its unset state
***************
*** 687,693 ****
# check once more the values
! assert False == ns.BoolAttrByName( "IsInitial" )
! assert False == ne.BoolAttrByName( "Default" )
! assert False == ne.BoolAttrByName( "Async" )
# commit trans
--- 694,700 ----
# check once more the values
! assert False == ns.GetBoolAttrByNameDisp( "IsInitial" )
! assert False == ne.GetBoolAttrByNameDisp( "Default" )
! assert False == ne.GetBoolAttrByNameDisp( "Async" )
# commit trans
***************
*** 707,711 ****
def testF( self ):
! """ testF DESCRIPTION
test properties of IMgaFCO such as
AttributeByName -get/put
--- 714,718 ----
def testF( self ):
! """ testF
test properties of IMgaFCO such as
AttributeByName -get/put
***************
*** 760,765 ****
assert 3.003 == at.GetFloatAttrByNameDisp( "Float2" )
! at.SetAttributeByNameDisp( "Float1", -4.004 ) # RESU: currently fails
! at.SetAttributeByNameDisp( "Float2", -5.005 ) # RESU: currently fails
# test whether VARIANTS are returning back good values
--- 767,772 ----
assert 3.003 == at.GetFloatAttrByNameDisp( "Float2" )
! at.SetAttributeByNameDisp( "Float1", -4.004 )
! at.SetAttributeByNameDisp( "Float2", -5.005 )
# test whether VARIANTS are returning back good values
***************
*** 800,804 ****
def testG( self ):
! """ testG DESCRIPTION
test properties of IMgaFCO such as
--- 807,811 ----
def testG( self ):
! """ testG
test properties of IMgaFCO such as
***************
*** 854,871 ****
attr_meta_list = ns.Meta.Attributes
- """
- TODO: copy this into the Meta tester when needed
- try:
- am1 = ns_meta.DefinedAttributeByName( "IsInitial", True)
- #print "am1: " + am1.Name
- except:
- pass
- try:
- am2 = ns_meta.DefinedAttributeByName( "IsInitial", False) # RESU: this fails, but it should not since the "InScope = false" case should be implemented
- print "am2: " + am2.Name
- except:
- pass
- """
-
assert attr_list.Count == attr_meta_list.Count
assert attr_list.Count == 1
--- 861,864 ----
***************
*** 936,940 ****
assert attr_i.OrigValue == attr_i.Value
assert attr_meta_list.Item( i ) == attr_i.Meta
! #assert False == attr_i.HasChanged # RESU: why is true, it is the original unfilled value
#assert not attr_i.HasChanged
--- 929,933 ----
assert attr_i.OrigValue == attr_i.Value
assert attr_meta_list.Item( i ) == attr_i.Meta
! #TODO assert False == attr_i.HasChanged # RESU: why is true, it is the original unfilled value
#assert not attr_i.HasChanged
***************
*** 945,949 ****
assert attr_i.OrigValue == attr_i.Value
assert attr_meta_list.Item( i ) == attr_i.Meta
! #assert False == attr_i.HasChanged # RESU: why is true?
#assert not attr_i.HasChanged
--- 938,942 ----
assert attr_i.OrigValue == attr_i.Value
assert attr_meta_list.Item( i ) == attr_i.Meta
! #TODO assert False == attr_i.HasChanged # RESU: why is true?
#assert not attr_i.HasChanged
***************
*** 962,966 ****
def testHfindInProj( self ):
! """ testHfindInProj DESCRIPTION
for testing the findInProj helper method (defined in this file)
"""
--- 955,959 ----
def testHfindInProj( self ):
! """ testHfindInProj
for testing the findInProj helper method (defined in this file)
"""
***************
*** 1017,1021 ****
def testL( self ):
! """ testL DESCRIPTION
testing IMgaFCO properties like
Registry get
--- 1010,1014 ----
def testL( self ):
! """ testL
testing IMgaFCO properties like
Registry get
***************
*** 1025,1029 ****
Value get/put
! inquire and modify values, finally abort transaction to revert changes
"""
--- 1018,1022 ----
Value get/put
! inquire and modify values, finally commit transaction to preserve changes
"""
***************
*** 1057,1081 ****
ns = self.findInProj( project, to_find)
! rgnodesB = ns.GetRegistryDisp( False ) # RESU: why doesn't work
! rgnodesA = ns.Registry
! rgnod1 = ns.RegistryNode( "OneNode" )
! rgnod2 = ns.RegistryNode( "AnoNode" )
assert rgnod1 in rgnodesA
! #assert rgnod2 in rgnodesB
assert "1one" == rgnod1.Value
assert "2two" == rgnod2.Value
! assert "1one" == ns.RegistryValue( "OneNode" )
! assert "2two" == ns.RegistryValue( "AnoNode" )
# modify through the IMgaFCO RegistryValue put-property
! ns.GetRegistryValueDisp( "OneNode", "one1-modified" ) # RESU: doesn't work
# check it
assert "one1-modified" == rgnod1.Value
! assert "one1-modified" == ns.RegistryValue( "OneNode" )
# modify through the IMgaRegNode Value put-property
--- 1050,1088 ----
ns = self.findInProj( project, to_find)
! # it should return a collection of nodes
! rgnodesA = ns.Registry # virtual nodes too
! rgnodesB = ns.GetRegistryDisp( False ) # just the owned ones
! assert rgnodesA.Count == 0 # initally no nodes exist
! assert rgnodesB.Count == 0
!
! rgnod1 = ns.GetRegistryNodeDisp( "OneNode" ) # this step (though it is a Get) will create the named nodes
! rgnod2 = ns.GetRegistryNodeDisp( "AnoNode" )
+ rgnod1.Value = '1one'
+ rgnod2.Value = '2two'
+
+ # now it should contain > 0 nodes
+ rgnodesA = ns.Registry
+ rgnodesB = ns.GetRegistryDisp( False)
+
+ # the fresh node must be in the collection
assert rgnod1 in rgnodesA
!
! assert rgnod1 in rgnodesA
! assert rgnod2 in rgnodesB
assert "1one" == rgnod1.Value
assert "2two" == rgnod2.Value
! assert "1one" == ns.GetRegistryValueDisp( "OneNode" )
! assert "2two" == ns.GetRegistryValueDisp( "AnoNode" )
# modify through the IMgaFCO RegistryValue put-property
! ns.SetRegistryValueDisp( "OneNode", "one1-modified" )
# check it
assert "one1-modified" == rgnod1.Value
! assert "one1-modified" == ns.GetRegistryValueDisp( "OneNode" )
# modify through the IMgaRegNode Value put-property
***************
*** 1084,1091 ****
# check it
assert "two2-modified" == rgnod2.Value
! assert "two2-modified" == ns.RegistryValue( "AnoNode" )
! # abort trans (thus revert changes)
! project.AbortTransaction()
project.Save()
--- 1091,1097 ----
# check it
assert "two2-modified" == rgnod2.Value
! assert "two2-modified" == ns.GetRegistryValueDisp( "AnoNode" )
! project.CommitTransaction()
project.Save()
More information about the GME-commit
mailing list