MCPcopy Create free account
hub / github.com/ImageEngine/cortex / test

Method test

test/IECore/SubstitutedDictTest.py:40–81  ·  view source on GitHub ↗
( self )

Source from the content-addressed store, hash-verified

38class SubstitutedDictTest( unittest.TestCase ) :
39
40 def test( self ) :
41
42 d = {
43 "a" : "hello ${name}",
44 "b" : IECore.CompoundObject(
45 {
46 "c" : IECore.StringData( "goodbye ${place}" )
47 }
48 )
49 }
50
51 ds = IECore.SubstitutedDict( d, { "name" : "john", "place" : "london" } )
52
53 self.assertEqual( ds["a"], "hello john" )
54 self.assertEqual( ds["b"]["c"], IECore.StringData( "goodbye london" ) )
55 self.assertTrue( isinstance( ds["b"], IECore.SubstitutedDict ) )
56 self.assertEqual( ds.get( "a" ), "hello john" )
57 self.assertEqual( ds.get( "notThere" ), None )
58 self.assertEqual( ds.get( "notThere", 10 ), 10 )
59 self.assertEqual( ds.get( "a", substituted=False ), "hello ${name}" )
60 self.assertEqual( ds.get( "b", substituted=False )["c"], IECore.StringData( "goodbye ${place}" ) )
61 self.assertTrue( ds.get( "b", substituted=False ).isInstanceOf( IECore.CompoundObject.staticTypeId() ) )
62 self.assertEqual( ds.get( "notThere", substituted=False ), None )
63
64 self.assertEqual( ds, ds )
65
66 keys = list( ds.keys() )
67 self.assertEqual( len( keys ), 2 )
68 self.assertTrue( "a" in keys )
69 self.assertTrue( "b" in keys )
70
71 values = ds.values()
72 self.assertEqual( len( values ), len( keys ) )
73 self.assertEqual( values[keys.index( "a" )], "hello john" )
74 self.assertTrue( isinstance( values[keys.index( "b" )], IECore.SubstitutedDict ) )
75
76 values = list( ds.values( substituted=False ) )
77 self.assertEqual( len( values ), len( keys ) )
78 self.assertEqual( values[keys.index( "a" )], "hello ${name}" )
79 self.assertTrue( isinstance( values[keys.index( "b" )], IECore.CompoundObject ) )
80
81 self.assertEqual( list( zip( *(ds.items()) ) ), [ tuple( ds.keys() ), tuple( ds.values() ) ] )
82
83 def testEquality( self ) :
84

Callers

nothing calls this directly

Calls 9

getMethod · 0.95
keysMethod · 0.95
valuesMethod · 0.95
itemsMethod · 0.95
CompoundObjectMethod · 0.80
isInstanceOfMethod · 0.80
staticTypeIdMethod · 0.80
indexMethod · 0.80
lenFunction · 0.50

Tested by

no test coverage detected