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 from GPyUnit.util import dec_disable_early_binding
00011
00012 def _adjacent_file(file):
00013 import os.path
00014 return os.path.join(os.path.dirname(os.path.abspath(__file__)), file)
00015
00016 class TestCase5( unittest.TestCase ):
00017 """
00018 avoid if possible the overriding of __init__, yet if you override use the following form:
00019 def __init__(self, methodName='runTest'):
00020 unittest.TestCase.__init__(self, methodName)
00021 """
00022
00023 def setUp( self ):
00024 pass
00025
00026 def tearDown( self ):
00027 self.project.Close( 0 )
00028 pass
00029
00030
00031 """
00032 def testA( self ):
00033
00034 " "" DESCRIPTION
00035 GetAbsMetaPath([in, out] BSTR *abspath)
00036 GetRelMetaPath([in] IMgaFCO *begfco, [in, out] BSTR *relpath, [in, defaultvalue(0)] IMgaFCOs *refs)
00037
00038 RESU: relmetapath how can GetRelMetaPath be called from Python
00039 " ""
00040
00041 pass
00042 """
00043
00044 def populate5B(self, p):
00045 folder1 = bd.newFolder( p, p.RootFolder, 'Folder')
00046 folder1.Name = 'Folder'
00047
00048 compA1 = bd.newObjInFold( p, folder1, 'Compound')
00049 compA1.Name = 'CompoundA'
00050
00051 ppM1 = bd.new( p, compA1, 'CompoundParts')
00052 ppM1.Name = 'CompoundPartsA'
00053
00054 s1 = bd.new( p, ppM1, 'InputSignals')
00055 s1.Name = 'inSig'
00056
00057 s2 = bd.new( p, ppM1, 'OutputSignals')
00058 s2.Name = 'ouSig'
00059
00060 @dec_disable_early_binding
00061 def testB( self ):
00062
00063 """ testB
00064 CreateCollection([in,out] IMgaFCOs **pVal)
00065 """
00066
00067 mganame = _adjacent_file("_tc5_B_sf.mga")
00068
00069
00070 project = bd.creaP( mganame, "SF")
00071 if not project:
00072 self.fail("Create failed")
00073 try:
00074 self.populate5B( project)
00075 except:
00076 bd.saveP( project)
00077 raise
00078 bd.saveP( project)
00079
00080 self.project = project
00081
00082
00083 project.Open( "MGA=" + mganame )
00084
00085 terr = project.CreateTerritory( None, None, None)
00086 trans = project.BeginTransaction( terr)
00087
00088 fco = bd.findInProj( project, "CompoundA")
00089 s1 = bd.findInProj( project, "inSig")
00090 s2 = bd.findInProj( project, "ouSig")
00091
00092 coll = fco.CreateCollection()
00093 assert coll.Count == 1
00094 assert coll.Item( 1 ).Name == fco.Name
00095
00096 coll.Append( fco)
00097 assert coll.Count == 2
00098 assert coll.Item( 1 ) == fco
00099 assert coll.Item( 2 ) == fco
00100 assert coll.Item( 1 ).Name == fco.Name
00101 assert coll.Item( 2 ).Name == coll.Item( 1 ).Name
00102
00103 col2 = s1.CreateCollection()
00104 assert col2.Count == 1
00105 assert col2.Item( 1 ) == s1
00106 assert col2.Item( 1 ).Name == s1.Name
00107
00108 col2.Append( s2)
00109 assert col2.Count == 2
00110 assert col2.Item( 1 ) == s1
00111 assert col2.Item( 2 ) == s2
00112 assert col2.Item( 1 ).Name == s1.Name
00113 assert col2.Item( 2 ).Name == s2.Name
00114
00115 col2.Append( fco)
00116 assert col2.Count == 3
00117 assert col2.Item( 1 ) == s1
00118 assert col2.Item( 2 ) == s2
00119 assert col2.Item( 3 ) == fco
00120 assert col2.Item( 1 ).Name == s1.Name
00121 assert col2.Item( 2 ).Name == s2.Name
00122 assert col2.Item( 3 ).Name == fco.Name
00123
00124
00125 project.AbortTransaction()
00126
00127 project.Save()
00128 project.Close(0)
00129
00130 pass
00131
00132 def populate5C(self, p):
00133 folder0 = bd.newFolder( p, p.RootFolder, 'Folder')
00134 folder0.Name = 'Folder0'
00135
00136 comp0 = bd.newObjInFold( p, p.RootFolder, 'Compound')
00137 comp0.Name = 'Compound0'
00138
00139 folder1 = bd.newFolder( p, folder0, 'Folder')
00140 folder1.Name = 'Folder1'
00141
00142 folder2 = bd.newFolder( p, folder1, 'Folder')
00143 folder2.Name = 'Folder2'
00144
00145 comp1 = bd.newObjInFold( p, folder0, 'Compound')
00146 comp1.Name = 'Compound1'
00147
00148 comp2 = bd.newObjInFold( p, folder1, 'Compound')
00149 comp2.Name = 'Compound2'
00150
00151 prim3 = bd.newObjInFold( p, folder2, 'Primitive')
00152 prim3.Name = 'Primitive3'
00153
00154 pp3 = bd.new( p, comp2, 'CompoundParts')
00155 pp3.Name = 'CompoundParts3'
00156
00157 is3 = bd.new( p, comp2, 'InputSignals')
00158 is3.Name = 'InSig3'
00159
00160 pp4 = bd.new( p, pp3, 'CompoundParts')
00161 pp4.Name = 'CompoundParts4'
00162
00163 ip4 = bd.new( p, pp3, 'InputParameters')
00164 ip4.Name = 'InPar4'
00165
00166 pp5 = bd.new( p, pp4, 'CompoundParts')
00167 pp5.Name = 'CompoundParts5'
00168
00169 os5 = bd.new( p, pp4, 'OutputSignals')
00170 os5.Name = 'OutSig5'
00171
00172 is4 = bd.new( p, prim3, 'InputSignals')
00173 is4.Name = 'InputSig4'
00174
00175
00176
00177 @dec_disable_early_binding
00178 def testC( self ):
00179
00180 """ testC
00181 testing property of IMgaFCO
00182 RootFCO
00183
00184 it should return the first object which is in the hierarchy ( below folders )
00185 """
00186
00187 mganame = _adjacent_file("_tc5_C_sf.mga")
00188
00189 project = bd.creaP( mganame, "SF")
00190 if not project:
00191 self.fail("Create failed")
00192 try:
00193 self.populate5C( project)
00194 except:
00195 bd.saveP( project)
00196 raise
00197 bd.saveP( project)
00198
00199 self.project = project
00200
00201
00202 project.Open( "MGA=" + mganame )
00203
00204 terr = project.CreateTerritory( None, None, None)
00205 trans = project.BeginTransaction( terr)
00206
00207 cm0 = bd.findInProj( project, "Compound0")
00208 cm1 = bd.findInProj( project, "Compound1")
00209 cm2 = bd.findInProj( project, "Compound2")
00210 cm3 = bd.findInProj( project, "CompoundParts3")
00211 cm4 = bd.findInProj( project, "CompoundParts4")
00212 cm5 = bd.findInProj( project, "CompoundParts5")
00213 pm3 = bd.findInProj( project, "Primitive3")
00214
00215 is3 = bd.findInProj( project, "InSig3")
00216 ip4 = bd.findInProj( project, "InPar4")
00217 os5 = bd.findInProj( project, "OutSig5")
00218 is4 = bd.findInProj( project, "InputSig4")
00219
00220 assert cm0 == cm0.RootFCO
00221 assert cm1 == cm1.RootFCO
00222 assert cm2 == cm2.RootFCO
00223 assert cm2 == cm3.RootFCO
00224 assert cm2 == cm4.RootFCO
00225 assert cm2 == cm5.RootFCO
00226
00227 assert cm2 == is3.RootFCO
00228 assert cm2 == ip4.RootFCO
00229 assert cm2 == os5.RootFCO
00230
00231 assert pm3 == pm3.RootFCO
00232 assert pm3 == is4.RootFCO
00233
00234
00235 assert cm1.ParentFolder
00236 try:
00237 assert cm1.ParentModel
00238 self.fail("It should have failed")
00239 except:
00240
00241 pass
00242
00243
00244
00245 assert cm2.ParentFolder
00246 assert pm3.ParentFolder
00247
00248
00249 project.AbortTransaction()
00250
00251 project.Save()
00252 project.Close(0)
00253
00254 pass
00255
00256
00257 """
00258 Let's produce the test suites
00259 """
00260
00261 def suites():
00262 suite = unittest.makeSuite(TestCase5,'test')
00263 return suite
00264
00265
00266 def suites3():
00267 suite = unittest.TestSuite()
00268 suite.addTest( TestCase5( "testA"))
00269
00270
00271 return suite
00272
00273
00274
00275
00276 if __name__ == "__main__":
00277 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00278 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00279 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00280 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00281 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00282 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TEST BEGINS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00283 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00284 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00285 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00286 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00287 print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
00288
00289
00290 unittest.main()
00291
00292
00293
00294
00295
00296
00297
00298