Ejemplo n.º 1
0
    def test__contains__(self):
        parent = Node()
        child = parent.descend('Child')
        parent.ctx['a'] = 1
        child.ctx['b'] = 2

        assert 'a' in parent.ctx
        assert 'a' in child.ctx
        assert 'b' in child.ctx
        assert 'b' not in parent.ctx
Ejemplo n.º 2
0
    def test__contains__(self):
        parent = Node()
        child = parent.descend('Child')
        parent.ctx['a'] = 1
        child.ctx['b'] = 2

        assert 'a' in parent.ctx
        assert 'a' in child.ctx
        assert 'b' in child.ctx
        assert 'b' not in parent.ctx
Ejemplo n.º 3
0
 def test_correct_scope(self):
     '''Dynamically create nodes should be in the global scope.
     '''
     name = 'Cow'
     newtype = Node().descend(name)
     self.assertIn(name, globals())
     self.assertNotIn(name, locals())
Ejemplo n.º 4
0
 def test_correct_module(self):
     '''Assert dynamically created types get created in
     the calling scope.
     '''
     name = 'Cow'
     newtype = Node().descend(name)
     self.assertEqual(newtype.__class__.__module__, __name__)
Ejemplo n.º 5
0
 def test_clone_ne(self):
     n1 = Node(a=1, b=2, c=3)
     n1.descend('Test1', x=1, y=2, z=3)
     n2 = n1.clone(cow='moo')
     self.assertNotEqual(n1, n2)
Ejemplo n.º 6
0
 def test_clone_eq(self):
     n1 = Node(a=1, b=2, c=3)
     n1.descend('Test1', x=1, y=2, z=3)
     self.assertEqual(n1, n1.clone())
Ejemplo n.º 7
0
 def test_ne(self):
     n1 = Node(a=1, b=2, c=3)
     n1.descend('Test1', x=1, y=2, z=3)
     n2 = Node(a=1, b=2, c=3)
     n2.descend('Test1', x=1, y=2, z=4)
     self.assertNotEqual(n1, n2)
Ejemplo n.º 8
0
 def test_clone_eq(self):
     n1 = Node(a=1, b=2, c=3)
     n1.descend('Test1', x=1, y=2, z=3)
     self.assertEqual(n1, n1.clone())
Ejemplo n.º 9
0
    def test_eq(self):
        n1 = Node(a=1, b=2, c=3)
        n1.descend('Test1', x=1, y=2, z=3)

        n2 = Node(a=1, b=2, c=3)
        n2.descend('Test1', x=1, y=2, z=3)
Ejemplo n.º 10
0
 def test__delitem__(self):
     parent = Node()
     child = parent.descend('Child')
     parent.ctx['a'] = 1
     del parent.ctx['a']
Ejemplo n.º 11
0
 def test_maps(self):
     parent = Node()
     child = parent.descend('Child')
     assert list(child.ctx.maps) == [child.ctx.map] + list(parent.ctx.maps)
Ejemplo n.º 12
0
 def test__len__(self):
     parent = Node()
     child = parent.descend('Child')
     parent.ctx['a'] = 1
     child.ctx['b'] = 2
     assert len(child.ctx) is 2
Ejemplo n.º 13
0
 def test__delitem__(self):
     parent = Node()
     child = parent.descend('Child')
     parent.ctx['a'] = 1
     del parent.ctx['a']
Ejemplo n.º 14
0
    def test_root(self):
        parent = Node()
        assert parent.ctx is parent.ctx.root

        ancestor = parent.descend_path("Child", "Grandchild")
        assert parent.ctx is ancestor.ctx.root
Ejemplo n.º 15
0
 def test_maps(self):
     parent = Node()
     child = parent.descend('Child')
     assert list(child.ctx.maps) == [child.ctx.map] + list(parent.ctx.maps)
Ejemplo n.º 16
0
 def test_import_works(self):
     '''Verify that the resolved name points to this module's TestNode.
     '''
     name = 'ExampleNode'
     newtype = Node().descend(name)
     self.assertIs(type(newtype), ExampleNode)
Ejemplo n.º 17
0
    def test_eq(self):
        n1 = Node(a=1, b=2, c=3)
        n1.descend('Test1', x=1, y=2, z=3)

        n2 = Node(a=1, b=2, c=3)
        n2.descend('Test1', x=1, y=2, z=3)
Ejemplo n.º 18
0
 def test__iter__(self):
     parent = Node()
     child = parent.descend('Child')
     parent.ctx['a'] = 1
     child.ctx['b'] = 2
     assert list(child.ctx) == list(child.ctx.map) + list(parent.ctx)
Ejemplo n.º 19
0
 def test__get__(self):
     node = Node()
     assert node.ctx.inst is node
     assert node.ctx._inst is node
Ejemplo n.º 20
0
 def test__iter__(self):
     parent = Node()
     child = parent.descend('Child')
     parent.ctx['a'] = 1
     child.ctx['b'] = 2
     assert list(child.ctx) == list(child.ctx.map) + list(parent.ctx)
Ejemplo n.º 21
0
    def test_root(self):
        parent = Node()
        assert parent.ctx is parent.ctx.root

        ancestor = parent.descend_path("Child", "Grandchild")
        assert parent.ctx is ancestor.ctx.root
Ejemplo n.º 22
0
 def test__repr__(self):
     parent = Node()
     child = parent.descend('Child')
     parent.ctx['a'] = 1
     child.ctx['b'] = 2
     assert repr(child.ctx) == "{'b': 2} -> {'a': 1}"
Ejemplo n.º 23
0
 def test__len__(self):
     parent = Node()
     child = parent.descend('Child')
     parent.ctx['a'] = 1
     child.ctx['b'] = 2
     assert len(child.ctx) is 2
Ejemplo n.º 24
0
 def test_clone_ne(self):
     n1 = Node(a=1, b=2, c=3)
     n1.descend('Test1', x=1, y=2, z=3)
     n2 = n1.clone(cow='moo')
     self.assertNotEqual(n1, n2)
Ejemplo n.º 25
0
 def test__repr__(self):
     parent = Node()
     child = parent.descend('Child')
     parent.ctx['a'] = 1
     child.ctx['b'] = 2
     assert repr(child.ctx) == "{'b': 2} -> {'a': 1}"
Ejemplo n.º 26
0
 def test__init__(self):
     node = Node()
     node.ctx['a'] = 1
     child = node.descend('Child')
     newmap = ChainMap(inst=child)
     assert newmap['a'] == 1
Ejemplo n.º 27
0
 def test__init__(self):
     node = Node()
     node.ctx['a'] = 1
     child = node.descend('Child')
     newmap = ChainMap(inst=child)
     assert newmap['a'] == 1
Ejemplo n.º 28
0
 def test_ne(self):
     n1 = Node(a=1, b=2, c=3)
     n1.descend('Test1', x=1, y=2, z=3)
     n2 = Node(a=1, b=2, c=3)
     n2.descend('Test1', x=1, y=2, z=4)
     self.assertNotEqual(n1, n2)