00001 import unittest
00002 import win32com.client
00003 import win32ui
00004 import pythoncom
00005 import os
00006 import utils.Builder
00007 bd = utils.Builder
00008
00009 from GPyUnit.util import DispatchEx
00010
00011 def _adjacent_file(file):
00012 import os.path
00013 return os.path.join(os.path.dirname(os.path.abspath(__file__)), file)
00014
00015 class TestCase7( unittest.TestCase ):
00016 """
00017 avoid if possible the overriding of __init__, yet if you override use the following form:
00018 def __init__(self, methodName='runTest'):
00019 unittest.TestCase.__init__(self, methodName)
00020 """
00021
00022 project = None
00023
00024 def setUp( self ):
00025 pass
00026
00027 def tearDown( self ):
00028 if self.project:
00029 self.project.Close( 0 )
00030 pass
00031
00032 def findInProj( self, project, obj_name = "", obj_kind = ""):
00033
00034 filter = project.CreateFilter()
00035
00036
00037 filter.Name = obj_name
00038 filter.Kind = obj_kind
00039
00040 try:
00041 some_fcos = project.AllFCOs( filter )
00042 if some_fcos.Count > 0:
00043 return some_fcos.Item( 1 )
00044 else:
00045 print "findInProj >> Object not found : name = '" + obj_name + "' kind = '" + obj_kind + "'"
00046 assert 0
00047 except:
00048 print "findInProj >> Exception : name = '" + obj_name + "' kind = '" + obj_kind + "'"
00049 assert 0
00050
00051 def populate7A(self, p):
00052 pri = bd.newObjInFold( p, p.RootFolder, 'Primitive')
00053 pri.Name = 'NewPrimitive'
00054
00055 i1 = bd.new( p, pri, 'InputParameters')
00056 i1.Name = 'NewInputParameters'
00057
00058 i2 = bd.new( p, pri, 'InputSignals')
00059 i2.Name = 'NewInputSignals'
00060
00061 i3 = bd.new( p, pri, 'OutputParameters')
00062 i3.Name = 'NewOutputParameters'
00063
00064 i4 = bd.new( p, pri, 'OutputParameters')
00065 i4.Name = 'NewOutputParameters'
00066
00067 i5 = bd.new( p, pri, 'OutputSignals')
00068 i5.Name = 'NewOutputSignals'
00069
00070 i6 = bd.new( p, pri, 'Parameters')
00071 i6.Name = 'NewParameters'
00072
00073
00074 def testA( self ):
00075 """ testA
00076 test properties of IMgaFCO such as
00077 Meta
00078 MetaRole
00079 ParentModel
00080 ParentFolder
00081 """
00082
00083 mganame = _adjacent_file("_tc7_A_sf.mga")
00084
00085
00086 project = bd.creaP( mganame, "SF")
00087 if not project:
00088 self.fail("Create failed")
00089 try:
00090 self.populate7A( project)
00091 except:
00092 bd.saveP( project)
00093 raise
00094 bd.saveP( project)
00095
00096
00097
00098 self.project = project
00099 try:
00100 project.Open( "MGA=" + mganame )
00101 except:
00102 project.Close(0)
00103 raise
00104
00105 terr = project.CreateTerritory( None, None, None)
00106 trans = project.BeginTransaction( terr)
00107
00108 to_find = "id-0066-00000002"
00109 fco1 = project.GetFCOByID( to_find )
00110
00111 to_find = "id-0066-00000003"
00112 fco3 = project.GetFCOByID( to_find )
00113 to_find = "id-0066-00000004"
00114 fco4 = project.GetFCOByID( to_find )
00115
00116 assert fco3.Meta == fco4.Meta
00117 metafco3 = fco3.Meta
00118 assert metafco3.Name == "OutputParam"
00119
00120 assert fco3.MetaRole == fco4.MetaRole
00121 metarole3 = fco3.MetaRole
00122 assert metarole3.Name == "OutputParameters"
00123
00124 mod = fco3.ParentModel
00125 par = mod.ParentFolder
00126
00127 assert par == project.RootFolder
00128
00129
00130 project.CommitTransaction()
00131
00132
00133 project.Save()
00134 project.Close(0)
00135
00136 def populate7B(self, p):
00137 folder1 = bd.newFolder( p, p.RootFolder, 'Folder')
00138 folder1.Name = 'NewFolder'
00139
00140 folder2 = bd.newFolder( p, folder1, 'Folder')
00141 folder2.Name = 'NewFolder'
00142
00143 folder3 = bd.newFolder( p, folder2, 'Folder')
00144 folder3.Name = 'NewFolder'
00145
00146 c1 = bd.newObjInFold( p, folder3, 'Compound')
00147 c1.Name = 'NewCompound'
00148
00149 for i in range(0,7):
00150 ci = bd.newObjInFold( p, folder3, 'Compound')
00151 ci.Name = 'NewCmp'
00152
00153 c2 = bd.new( p, c1, 'CompoundParts')
00154 c2.Name = 'NewCompoundParts'
00155
00156 c3 = bd.new( p, c2, 'CompoundParts')
00157 c3.Name = 'NewCompoundParts'
00158
00159 c4 = bd.new( p, c3, 'CompoundParts')
00160 c4.Name = 'NewCompoundParts'
00161
00162 c5 = bd.new( p, c4, 'CompoundParts')
00163 c5.Name = 'NewCompoundParts'
00164
00165 c6 = bd.new( p, c5, 'CompoundParts')
00166 c6.Name = 'NewCompoundParts'
00167
00168 c7 = bd.new( p, c5, 'PrimitiveParts')
00169 c7.Name = 'NewPrimitiveParts'
00170
00171
00172 def testB( self ):
00173 """ testB
00174 test properties of IMgaFCO such as
00175 ParentModel
00176 ParentFolder
00177 """
00178
00179 mganame = _adjacent_file("_tc7_B_sf.mga")
00180
00181
00182 project = bd.creaP( mganame, "SF")
00183 if not project:
00184 self.fail("Create failed")
00185 try:
00186 self.populate7B( project)
00187 except:
00188 bd.saveP( project)
00189 raise
00190 bd.saveP( project)
00191
00192
00193
00194 self.project = project
00195 try:
00196 project.Open( "MGA=" + mganame )
00197 except:
00198 project.Close(0)
00199 raise
00200
00201 terr = project.CreateTerritory( None, None, None)
00202
00203 trans = project.BeginTransaction( terr)
00204
00205 to_find = "id-0065-0000000d"
00206 fco3 = project.GetFCOByID( to_find )
00207 to_find = "id-0065-0000000e"
00208 fco4 = project.GetFCOByID( to_find )
00209
00210 last_parent = fco3;
00211 mod = fco3.ParentModel
00212 count_model_parents = 0
00213 while mod != None:
00214 count_model_parents = 1 + count_model_parents
00215 last_parent = mod
00216 mod = mod.ParentModel
00217
00218 assert count_model_parents == 5
00219
00220 fol = last_parent.ParentFolder
00221 count_folder_parents = 0
00222 while fol != None:
00223 count_folder_parents = 1 + count_folder_parents
00224 last_parent = fol
00225 fol = fol.ParentFolder
00226
00227 assert count_folder_parents == 4
00228
00229 assert last_parent == project.RootFolder
00230
00231
00232 project.CommitTransaction()
00233
00234 project.Save()
00235 project.Close(0)
00236
00237 def populate7C(self, p):
00238 folder1 = bd.newFolder( p, p.RootFolder, 'Folder')
00239 folder1.Name = 'Samples'
00240
00241 folder2 = bd.newFolder( p, p.RootFolder, 'Folder')
00242 folder2.Name = 'Universe'
00243
00244 c1 = bd.newObjInFold( p, folder1, 'Compound')
00245 c1.Name = 'NewCompound'
00246
00247 c2 = bd.newObjInFold( p, folder1, 'Primitive')
00248 c2.Name = 'NewPrimitive'
00249
00250 c3 = bd.new( p, c1, 'CompoundParts')
00251 c3.Name = 'NewCompoundParts'
00252
00253 i1 = bd.new( p, c3, 'InputParameters')
00254 i1.Name = 'NewInputParameters'
00255
00256 i2 = bd.new( p, c3, 'InputSignals')
00257 i2.Name = 'NewInputSignals'
00258
00259 c4 = bd.newObjInFold( p, folder2, 'Compound')
00260 c4.Name = 'NewCompound'
00261
00262 c5 = bd.newObjInFold( p, folder2, 'Primitive')
00263 c5.Name = 'NewPrimitive'
00264
00265 c6 = bd.new( p, c4, 'CompoundParts')
00266 c6.Name = 'NewCompoundParts'
00267
00268 c7 = bd.new( p, c4, 'PrimitiveParts')
00269 c7.Name = 'NewPrimitiveParts'
00270
00271 i3 = bd.new( p, c6, 'InputParameters')
00272 i3.Name = 'NewInputParameters'
00273
00274 i4 = bd.new( p, c6, 'InputParameters')
00275 i4.Name = 'NewInputParameters'
00276
00277 i5 = bd.new( p, c6, 'InputSignals')
00278 i5.Name = 'NewInputSignals'
00279
00280 i6 = bd.new( p, c6, 'InputSignals')
00281 i6.Name = 'NewInputSignals'
00282
00283
00284 i7 = bd.new( p, c7, 'InputParameters')
00285 i7.Name = 'NewInputParameters'
00286
00287 i8 = bd.new( p, c7, 'InputParameters')
00288 i8.Name = 'NewInputParameters'
00289
00290 i9 = bd.new( p, c7, 'InputSignals')
00291 i9.Name = 'NewInputSignals'
00292
00293 ia = bd.new( p, c7, 'InputSignals')
00294 ia.Name = 'NewInputSignals'
00295
00296 ib = bd.new( p, c5, 'InputParameters')
00297 ib.Name = 'NewInputParameters'
00298
00299 ic = bd.new( p, c5, 'InputSignals')
00300 ic.Name = 'NewInputSignals'
00301
00302 id = bd.new( p, c5, 'OutputParameters')
00303 id.Name = 'NewOutputParameters'
00304
00305
00306 def testC( self ):
00307 """ testC
00308 test properties of IMgaFCO such as
00309 Part
00310 Parts
00311 PartByMetaPart
00312 """
00313
00314 mganame = _adjacent_file("_tc7_C_sf.mga")
00315
00316
00317 project = bd.creaP( mganame, "SF")
00318 if not project:
00319 self.fail("Create failed")
00320 try:
00321 self.populate7C( project)
00322 except:
00323 bd.saveP( project)
00324 raise
00325 bd.saveP( project)
00326
00327
00328
00329 self.project = project
00330 try:
00331 project.Open( "MGA=" + mganame )
00332 except:
00333 project.Close(0)
00334 raise
00335
00336 terr = project.CreateTerritory( None, None, None)
00337
00338 trans = project.BeginTransaction( terr)
00339
00340 to_find = "id-0066-00000001"
00341 inpar = project.GetFCOByID( to_find )
00342
00343 to_find = "id-0066-00000002"
00344 insig = project.GetFCOByID( to_find )
00345
00346 to_find = "id-0065-00000003"
00347 cp = project.GetFCOByID( to_find )
00348
00349 to_find = "id-0065-00000004"
00350 pp = project.GetFCOByID( to_find )
00351
00352 aspect_1 = cp.Meta.AspectByName("ParameterAspect")
00353 aspect_2 = cp.Meta.AspectByName("SignalFlowAspect")
00354
00355
00356
00357
00358 part = insig.Part( aspect_1)
00359 assert part == None
00360
00361 part = insig.Part( aspect_2)
00362 assert part != None
00363 assert part in insig.Parts
00364 metapart = part.Meta
00365 another_part = insig.PartByMetaPart( metapart)
00366 assert another_part in insig.Parts
00367 assert another_part == part
00368 assert another_part.FCO.Name == part.FCO.Name
00369
00370
00371
00372
00373 part = inpar.Part( aspect_2)
00374 assert part == None
00375
00376 part = inpar.Part( aspect_1)
00377 assert part != None
00378
00379 assert part in inpar.Parts
00380
00381 metapart = part.Meta
00382 another_part = inpar.PartByMetaPart( metapart)
00383 assert another_part in inpar.Parts
00384 assert another_part == part
00385 assert another_part.FCO.Name == part.FCO.Name
00386
00387
00388 project.CommitTransaction()
00389
00390
00391 project.Save()
00392 project.Close(0)
00393
00394 def populate7D(self, p):
00395 c1 = bd.newObjInFold( p, p.RootFolder, 'Compound')
00396 c1.Name = 'NewCompound'
00397
00398 p1 = bd.new( p, c1, 'PrimitiveParts')
00399 p1.Name = 'NewPrimitiveParts'
00400
00401 ip1 = bd.new( p, p1, 'InputParameters')
00402 ip1.Name = 'NewInputParameters'
00403
00404
00405 def testD( self ):
00406 """ testD
00407 test properties of IMgaFCO such as
00408 AttributeByName -get/put
00409 StrAttrByName -get/put
00410 IntAttrByName -get/put
00411
00412 first inquire the original values, then modify them
00413 inquire once again, revert back to the original ones
00414 then modify and inquire once again using the variant put/getter AttributeByName
00415 """
00416
00417 mganame = _adjacent_file("_tc7_D_sf.mga")
00418
00419
00420 project = bd.creaP( mganame, "SF")
00421 if not project:
00422 self.fail("Create failed")
00423 try:
00424 self.populate7D( project)
00425 except:
00426 bd.saveP( project)
00427 raise
00428 bd.saveP( project)
00429
00430
00431
00432 self.project = project
00433 try:
00434 project.Open( "MGA=" + mganame )
00435 except:
00436 project.Close(0)
00437 raise
00438
00439 terr = project.CreateTerritory( None, None, None)
00440
00441 trans = project.BeginTransaction( terr)
00442
00443 to_find = "id-0066-00000001"
00444 ip = project.GetFCOByID( to_find )
00445
00446 to_find = "id-0065-00000002"
00447 pp = project.GetFCOByID( to_find )
00448
00449 aspect_1 = pp.Meta.AspectByName("ParameterAspect")
00450 aspect_2 = pp.Meta.AspectByName("SignalFlowAspect")
00451
00452 assert 1 == ip.GetIntAttrByNameDisp( "Size" )
00453 assert "Integer" == ip.GetStrAttrByNameDisp( "DataType" )
00454
00455
00456 ip.SetIntAttrByNameDisp( "Size", 2)
00457 ip.SetStrAttrByNameDisp( "DataType", "Double")
00458
00459 assert 2 == ip.GetIntAttrByNameDisp( "Size" )
00460 assert "Double" == ip.GetStrAttrByNameDisp( "DataType" )
00461
00462
00463 ip.SetIntAttrByNameDisp( "Size", 1)
00464 ip.SetStrAttrByNameDisp( "DataType", "Integer")
00465
00466 assert 10 == pp.GetIntAttrByNameDisp( "Priority" )
00467 assert "" == pp.GetStrAttrByNameDisp( "Script" )
00468 assert "IFALL" == pp.GetStrAttrByNameDisp( "Firing" )
00469
00470
00471 pp.SetIntAttrByNameDisp( "Priority", 5 )
00472 d_s = "int dummy_script()\n{ return 1; }"
00473 pp.SetStrAttrByNameDisp( "Script", d_s)
00474 pp.SetStrAttrByNameDisp( "Firing", "IFANY" )
00475
00476 assert 5 == pp.GetIntAttrByNameDisp( "Priority" )
00477 assert d_s == pp.GetStrAttrByNameDisp( "Script" )
00478 assert "IFANY" == pp.GetStrAttrByNameDisp( "Firing" )
00479
00480
00481 pr = 0
00482 pr = pp.GetAttributeByNameDisp( "Priority")
00483 assert pr == 5
00484
00485 scr = ""
00486 scr = pp.GetAttributeByNameDisp( "Script" )
00487 assert scr == d_s
00488
00489 fir = "IFALL"
00490 fir = pp.GetAttributeByNameDisp( "Firing" )
00491 assert "IFANY" == fir
00492
00493
00494 old_pr_val = 10
00495 pp.SetAttributeByNameDisp( "Priority", old_pr_val )
00496
00497 old_scr_val = ""
00498 pp.SetAttributeByNameDisp( "Script", old_scr_val )
00499
00500 old_fir_val = "IFALL"
00501 pp.SetAttributeByNameDisp( "Firing", old_fir_val )
00502
00503
00504 assert 10 == pp.GetIntAttrByNameDisp( "Priority")
00505 assert "" == pp.GetStrAttrByNameDisp( "Script")
00506 assert "IFALL" == pp.GetStrAttrByNameDisp( "Firing")
00507
00508
00509 project.CommitTransaction()
00510
00511 project.Save()
00512 project.Close(0)
00513
00514 def populate7F(self, p):
00515 f = bd.newObjInFold( p, p.RootFolder, 'NewModel')
00516 f.Name = 'NewNewModel'
00517
00518 a = bd.new( p, f, 'NewAtom')
00519 a.Name = 'NewNewAtom'
00520
00521 def _notworking_testF( self ):
00522 """ testF
00523 test properties of IMgaFCO such as
00524 AttributeByName -get/put
00525 FloatAttrByName -get/put
00526 ClearAttrByName
00527
00528 test put/get methods on double type FieldAttributes on a custom (FloatAttr) paradigm
00529 """
00530
00531 mganame = _adjacent_file("_tc7_F_fl.mga")
00532
00533
00534 project = bd.creaP( mganame, "FloatAttr")
00535 if not project:
00536 self.fail("Create failed")
00537 try:
00538 self.populate7F( project)
00539 except:
00540 bd.saveP( project)
00541 raise
00542 bd.saveP( project)
00543
00544
00545 self.project = project
00546 try:
00547 project.Open( "MGA=" + mganame )
00548 except:
00549 project.Close(0)
00550 raise
00551
00552 terr = project.CreateTerritory( None, None, None)
00553
00554 trans = project.BeginTransaction( terr)
00555
00556 to_find = "NewNewAtom"
00557 at = self.findInProj( project, to_find)
00558
00559 try:
00560 nnnname = at.Name
00561 except:
00562 print "Caught 1"
00563 assert 0
00564
00565
00566 assert 0.000 == at.GetFloatAttrByNameDisp( "Float1" )
00567 assert 1.001 == at.GetFloatAttrByNameDisp( "Float2" )
00568
00569 at.SetFloatAttrByNameDisp( "Float1", 2.002 )
00570 at.SetFloatAttrByNameDisp( "Float2", 3.003 )
00571
00572 assert 2.002 == at.GetFloatAttrByNameDisp( "Float1" )
00573 assert 3.003 == at.GetFloatAttrByNameDisp( "Float2" )
00574
00575 at.SetAttributeByNameDisp( "Float1", -4.004 )
00576 at.SetAttributeByNameDisp( "Float2", -5.005 )
00577
00578
00579 assert -4.004 == at.GetAttributeByNameDisp( "Float1" )
00580 assert -5.005 == at.GetAttributeByNameDisp( "Float2" )
00581
00582
00583 at.ClearAttrByName( "Float1" )
00584 at.ClearAttrByName( "Float2" )
00585
00586 assert 0.000 == at.GetFloatAttrByNameDisp( "Float1" )
00587 assert 1.001 == at.GetFloatAttrByNameDisp( "Float2" )
00588
00589
00590 project.CommitTransaction()
00591
00592 project.Save()
00593 project.Close(0)
00594
00595 pass
00596
00597 """
00598 Let's produce the test suites
00599 """
00600
00601 def suites():
00602 suite = unittest.makeSuite(TestCase7,'test')
00603 return suite
00604
00605
00606 def suites2():
00607 tc = TestCase7()
00608
00609
00610
00611
00612 def suites3():
00613 suite = unittest.TestSuite()
00614
00615
00616 suite.addTest( TestCase7( "testE"))
00617 return suite
00618
00619
00620
00621
00622 if __name__ == "__main__":
00623 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00624 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00625 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00626 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00627 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00628 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TEST BEGINS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00629 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00630 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00631 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00632 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00633 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00634
00635
00636 unittest.main()
00637
00638
00639
00640
00641
00642
00643
00644