def testAddChildWithExistingNumericSuffix( self ) :

		g = Gaffer.GraphComponent()
		g.addChild( Gaffer.GraphComponent( "a1" ) )
		g.addChild( Gaffer.GraphComponent( "a1" ) )

		self.assertEqual( g[0].getName(), "a1" )
		self.assertEqual( g[1].getName(), "a2" )
Beispiel #2
0
    def testRenameThenRemove(self):

        p = Gaffer.GraphComponent()
        c = Gaffer.GraphComponent()

        p.addChild(c)
        c.setName("c")
        p.removeChild(c)
Beispiel #3
0
    def testProperties(self):

        r = Gaffer.GraphComponent()
        r["d"] = Gaffer.GraphComponent()

        p = Gaffer.GraphComponentPath(r, "/d")
        self.assertEqual(p.propertyNames(), ["name", "fullName"])
        self.assertEqual(p.property("name"), "d")
        self.assertEqual(p.property("fullName"), "/d")
		def f( q ) :
			try:
				g = Gaffer.GraphComponent()
				for i in range( 500 ):
					g.addChild( Gaffer.GraphComponent( "a" ) )

				self.assertEqual( set(g.keys()), set( [ "a" ] + [ "a%i" % i for i in range( 1, 500 ) ] ) )
			except Exception as e:
				q.put( e )
Beispiel #5
0
    def testNamesWithStrangeSuffixes(self):

        g = Gaffer.GraphComponent()
        g.addChild(Gaffer.GraphComponent("a"))
        g.addChild(Gaffer.GraphComponent("a1somethingElse"))
        self.assertEqual(g[0].getName(), "a")
        self.assertEqual(g[1].getName(), "a1somethingElse")

        g.addChild(Gaffer.GraphComponent("a"))
        self.assertEqual(g[2].getName(), "a1")
    def testChildrenInheritFilter(self):

        r = Gaffer.GraphComponent()
        r["d"] = Gaffer.GraphComponent()
        r["d"]["e"] = Gaffer.GraphComponent()

        p = Gaffer.GraphComponentPath(r, "/d", filter=Gaffer.PathFilter())
        child = p.children()[0]

        self.assertTrue(isinstance(child.getFilter(), Gaffer.PathFilter))
Beispiel #7
0
	def testGetChildWithPath( self ) :
	
		p1 = Gaffer.GraphComponent()
		p2 = Gaffer.GraphComponent()
		p3 = Gaffer.GraphComponent()
		
		p1["p2"] = p2
		p2["p3"] = p3
		
		self.failUnless( p1.getChild( "p2.p3" ).isSame( p3 ) )
Beispiel #8
0
    def testRemoveMany(self):

        g = Gaffer.GraphComponent()
        l = []
        for i in range(0, 10000):
            c = Gaffer.GraphComponent()
            l.append(c)
            g["c%d" % i] = c

        for c in l:
            g.removeChild(c)
Beispiel #9
0
    def testManyChildrenWithSameInitialName(self):

        g = Gaffer.GraphComponent()
        for i in range(0, 2000):
            g.addChild(Gaffer.GraphComponent())

        for index, child in enumerate(g):
            if index == 0:
                self.assertEqual(child.getName(), "GraphComponent")
            else:
                self.assertEqual(child.getName(), "GraphComponent%d" % index)
Beispiel #10
0
    def testDescendant(self):

        p1 = Gaffer.GraphComponent()
        p2 = Gaffer.GraphComponent()
        p3 = Gaffer.GraphComponent()

        p1["p2"] = p2
        p2["p3"] = p3

        self.failUnless(p1.descendant("p2").isSame(p2))
        self.failUnless(p1.descendant("p2.p3").isSame(p3))
Beispiel #11
0
    def testClearChildren(self):

        p = Gaffer.GraphComponent()

        for i in range(0, 10):
            p.addChild(Gaffer.GraphComponent())

        self.assertEqual(len(p), 10)

        p.clearChildren()

        self.assertEqual(len(p), 0)
Beispiel #12
0
    def testIsAncestorOf(self):

        n = Gaffer.GraphComponent()
        n["c"] = Gaffer.GraphComponent()
        n["c"]["c"] = Gaffer.GraphComponent()
        n2 = Gaffer.GraphComponent()

        self.failUnless(n.isAncestorOf(n["c"]["c"]))
        self.failUnless(n.isAncestorOf(n["c"]))
        self.failIf(n.isAncestorOf(n))
        self.failIf(n2.isAncestorOf(n))
        self.failIf(n.isAncestorOf(n2))
Beispiel #13
0
    def testIsAncestorOf(self):

        n = Gaffer.GraphComponent()
        n["c"] = Gaffer.GraphComponent()
        n["c"]["c"] = Gaffer.GraphComponent()
        n2 = Gaffer.GraphComponent()

        self.assertTrue(n.isAncestorOf(n["c"]["c"]))
        self.assertTrue(n.isAncestorOf(n["c"]))
        self.assertFalse(n.isAncestorOf(n))
        self.assertFalse(n2.isAncestorOf(n))
        self.assertFalse(n.isAncestorOf(n2))
Beispiel #14
0
    def testLen(self):

        g = Gaffer.GraphComponent()
        self.assertEqual(len(g), 0)

        g["a"] = Gaffer.GraphComponent()
        self.assertEqual(len(g), 1)

        g["b"] = Gaffer.GraphComponent()
        self.assertEqual(len(g), 2)

        del g["a"]
        self.assertEqual(len(g), 1)
Beispiel #15
0
    def testDelItemByIndex(self):

        g = Gaffer.GraphComponent()
        a = Gaffer.GraphComponent("a")
        b = Gaffer.GraphComponent("b")
        g["a"] = a
        g["b"] = b
        self.assertEqual(a.parent(), g)
        self.assertEqual(b.parent(), g)

        del g[0]
        self.assertEqual(a.parent(), None)
        self.assertEqual(b.parent(), g)
Beispiel #16
0
	def testRelative( self ) :
	
		r = Gaffer.GraphComponent()
		r["d"] = Gaffer.GraphComponent()
		r["d"]["e"] = Gaffer.GraphComponent()

		p = Gaffer.GraphComponentPath( r, "d" )
		self.assertEqual( str( p ), "d" )
		self.assertEqual( p.root(), "" )
		self.assertEqual( [ str( c ) for c in p.children() ], [ "d/e" ] )
		
		p2 = p.copy()
		self.assertEqual( str( p2 ), "d" )
		self.assertEqual( p2.root(), "" )
		self.assertEqual( [ str( c ) for c in p2.children() ], [ "d/e" ] )
Beispiel #17
0
    def test(self):

        p = Gaffer.GraphComponent()
        s = Gaffer.ChildSet(p)

        self.assertEqual(len(s), 0)

        g1 = Gaffer.GraphComponent()
        p.addChild(g1)

        self.assertEqual(len(s), 1)
        self.assertTrue(s.contains(g1))
        self.assertTrue(s[0].isSame(g1))

        p.removeChild(g1)
        self.assertEqual(len(s), 0)
        self.assertFalse(s.contains(g1))
Beispiel #18
0
	def test( self ) :
	
		p = Gaffer.GraphComponent()
		s = Gaffer.ChildSet( p )
		
		self.assertEqual( len( s ), 0 )
		
		g1 = Gaffer.GraphComponent()
		p.addChild( g1 )
		
		self.assertEqual( len( s ), 1 )
		self.failUnless( s.contains( g1 ) )
		self.failUnless( s[0] is g1 )
		
		p.removeChild( g1 )
		self.assertEqual( len( s ), 0 )
		self.failIf( s.contains( g1 ) )
Beispiel #19
0
    def testDescriptiveKeyErrors(self):

        g = Gaffer.GraphComponent()
        self.assertRaisesRegexp(KeyError,
                                "'a' is not a child of 'GraphComponent'",
                                g.__getitem__, "a")
        self.assertRaisesRegexp(KeyError,
                                "'a' is not a child of 'GraphComponent'",
                                g.__delitem__, "a")
Beispiel #20
0
    def testNoneIsNotAString(self):

        g = Gaffer.GraphComponent()
        self.assertRaises(TypeError, g.getChild, None)
        self.assertRaises(TypeError, g.__getitem__, None)
        self.assertRaises(TypeError, g.__delitem__, None)
        self.assertRaises(TypeError, g.descendant, None)
        self.assertRaises(TypeError, g.__contains__, None)
        self.assertRaises(TypeError, g.setName, None)
Beispiel #21
0
    def testNameConstraints(self):

        n = Gaffer.GraphComponent()

        for name in ("0", "0a", "@A", "a.A", ".", "A:", "a|", "a("):
            self.assertRaises(Exception, n.setName, "0")

        for name in ("hello", "_1", "brdf_0_degree_refl"):
            n.setName(name)
Beispiel #22
0
	def testParentChanging( self ) :
	
		class Child( Gaffer.GraphComponent ) :
		
			def __init__( self, name = "Child" ) :
			
				Gaffer.GraphComponent.__init__( self, name )
			
				self.parentChanges = []
			
			def _parentChanging( self, newParent ) :
			
				self.parentChanges.append( ( self.parent(), newParent ) )

		p1 = Gaffer.GraphComponent()
		p2 = Gaffer.GraphComponent()
		
		c = Child()
		self.assertEqual( len( c.parentChanges ), 0 )
		
		p1.addChild( c )
		self.assertEqual( len( c.parentChanges ), 1 )
		self.assertEqual( c.parentChanges[-1], ( None, p1 ) )
	
		p1.removeChild( c )
		self.assertEqual( len( c.parentChanges ), 2 )
		self.assertEqual( c.parentChanges[-1], ( p1, None ) )
	
		p1.addChild( c )
		self.assertEqual( len( c.parentChanges ), 3 )
		self.assertEqual( c.parentChanges[-1], ( None, p1 ) )

		p2.addChild( c )
		self.assertEqual( len( c.parentChanges ), 4 )
		self.assertEqual( c.parentChanges[-1], ( p1, p2 ) )
	
		# cause a parent change by destroying the parent.
		# we need to remove all references to the parent to do
		# this, including those stored in the parentChanges list.
		del p2
		del c.parentChanges[:]
		
		self.assertEqual( len( c.parentChanges ), 1 )
		self.assertEqual( c.parentChanges[-1], ( None, None ) )
Beispiel #23
0
    def testIndexByIndex(self):

        g = Gaffer.GraphComponent()

        g["a"] = Gaffer.GraphComponent()
        g["b"] = Gaffer.GraphComponent()
        g["c"] = Gaffer.GraphComponent()

        self.assertEqual(len(g), 3)

        self.assertRaises(IndexError, g.__getitem__, 3)
        self.assertRaises(IndexError, g.__getitem__, -4)

        self.assertEqual(g[0].getName(), "a")
        self.assertEqual(g[1].getName(), "b")
        self.assertEqual(g[2].getName(), "c")
        self.assertEqual(g[-1].getName(), "c")
        self.assertEqual(g[-2].getName(), "b")
        self.assertEqual(g[-3].getName(), "a")
Beispiel #24
0
    def testParenting(self):

        parent1 = Gaffer.GraphComponent()
        self.assert_(parent1.parent() is None)
        self.assertEqual(len(parent1.children()), 0)
        child1 = Gaffer.GraphComponent()
        self.assert_(child1.parent() is None)
        self.assertEqual(len(child1.children()), 0)

        parent1.addChild(child1)
        self.assert_(parent1.parent() is None)
        self.assert_(parent1.getChild("GraphComponent").isSame(child1))
        self.assert_(parent1["GraphComponent"].isSame(child1))
        self.assert_(child1.parent().isSame(parent1))

        parent1.removeChild(child1)
        self.assertEqual(parent1.children(), ())
        self.assertEqual(child1.parent(), None)

        self.assertRaises(RuntimeError, parent1.removeChild, child1)
Beispiel #25
0
    def testReparentingDoesntSignal(self):
        """Adding a child to a parent who already owns that child should do nothing."""

        parent = Gaffer.GraphComponent()
        child = Gaffer.GraphComponent()

        parent.addChild(child)
        self.assert_(child.parent().isSame(parent))

        GraphComponentTest.numSignals = 0

        def f(a, b=None):
            GraphComponentTest.numSignals += 1

        c1 = child.parentChangedSignal().connect(f)
        c2 = parent.childAddedSignal().connect(f)

        parent.addChild(child)

        self.assertEqual(GraphComponentTest.numSignals, 0)
	def testNoneIsNotAGraphComponent( self ) :

		g = Gaffer.GraphComponent()

		with six.assertRaisesRegex( self, Exception, r"did not match C\+\+ signature" ) :
			g.addChild( None )

		with six.assertRaisesRegex( self, Exception, r"did not match C\+\+ signature" ) :
			g.setChild( "x", None )

		with six.assertRaisesRegex( self, Exception, r"did not match C\+\+ signature" ) :
			g.removeChild( None )
Beispiel #27
0
    def testNoOrphanRemoval(self):

        p = Gaffer.GraphComponent()
        c1 = Gaffer.GraphComponent()
        c2 = Gaffer.GraphComponent()
        p["c1"] = c1
        p["c2"] = c2

        s1 = Gaffer.StandardSet(p.children())
        s2 = Gaffer.StandardSet(p.children(), removeOrphans=False)

        self.assertFalse(s1.getRemoveOrphans())
        self.assertFalse(s2.getRemoveOrphans())

        p.removeChild(c1)
        p.removeChild(c2)

        self.assertTrue(c1 in s1)
        self.assertTrue(c2 in s1)
        self.assertTrue(c1 in s2)
        self.assertTrue(c2 in s2)
Beispiel #28
0
    def testName(self):

        c = Gaffer.GraphComponent()
        self.assertEqual(c.getName(), "GraphComponent")
        self.assertEqual(c.fullName(), "GraphComponent")

        def f(c):
            GraphComponentTest.name = c.getName()

        con = c.nameChangedSignal().connect(f)
        GraphComponentTest.name = "xxx"
        c.setName("newName")
        self.assertEqual(GraphComponentTest.name, "newName")
        # slot shouldn't be called this time, as the name
        # doesn't change (it's the same value)
        c.setName("newName")
        self.assertEqual(self.name, "newName")

        self.assertEqual(c.getName(), "newName")

        child1 = Gaffer.GraphComponent()
        child2 = Gaffer.GraphComponent()
        self.assertEqual(child1.getName(), "GraphComponent")
        self.assertEqual(child2.getName(), "GraphComponent")
        self.assertEqual(child1.fullName(), "GraphComponent")
        self.assertEqual(child2.fullName(), "GraphComponent")

        c.addChild(child1)
        self.assertEqual(child1.getName(), "GraphComponent")
        self.assertEqual(child1.fullName(), "newName.GraphComponent")

        con = child2.nameChangedSignal().connect(f)
        GraphComponentTest.name = "xxx"
        c.addChild(child2)
        self.assertEqual(child2.getName(), "GraphComponent1")
        self.assertEqual(child2.fullName(), "newName.GraphComponent1")
        self.assertEqual(child2.relativeName(None), "newName.GraphComponent1")
        self.assertEqual(child2.relativeName(c), "GraphComponent1")
        self.assertEqual(GraphComponentTest.name, "GraphComponent1")
Beispiel #29
0
	def testUniqueNaming( self ) :
	
		p = Gaffer.GraphComponent()
		c1 = Gaffer.GraphComponent()
		c2 = Gaffer.GraphComponent()
		c3 = Gaffer.GraphComponent()
		
		c1.setName( "a" )
		c2.setName( "a" )
		c3.setName( "a" )
		
		p.addChild( c1 )
		self.assertEqual( c1.getName(), "a" )
		
		p.addChild( c2 )
		self.assertEqual( c2.getName(), "a1" )
		
		p.addChild( c3 )
		self.assertEqual( c3.getName(), "a2" )
		
		c4 = Gaffer.GraphComponent( "a1" )
		p.addChild( c4 )
		self.assertEqual( c4.getName(), "a3" )
Beispiel #30
0
    def testKeysAndValuesAndItems(self):

        g = Gaffer.GraphComponent()
        self.assertEqual(g.keys(), [])
        self.assertEqual(g.values(), [])

        g["a"] = Gaffer.GraphComponent()
        g["b"] = Gaffer.GraphComponent()
        g["c"] = Gaffer.GraphComponent()

        self.assertEqual(g.keys(), ["a", "b", "c"])
        self.assertEqual(len(g.values()), 3)
        self.assertEqual(g.values()[0].getName(), "a")
        self.assertEqual(g.values()[1].getName(), "b")
        self.assertEqual(g.values()[2].getName(), "c")

        items = g.items()
        self.assertEqual(len(items), 3)
        self.assertEqual(items[0][0], "a")
        self.assertEqual(items[1][0], "b")
        self.assertEqual(items[2][0], "c")
        self.assertEqual(items[0][1].getName(), "a")
        self.assertEqual(items[1][1].getName(), "b")
        self.assertEqual(items[2][1].getName(), "c")