Пример #1
0
 def test_binding_survives_object_deletion(self):
     ex = self.Example('fred', 'flintstone')
     ex2 = self.Example('barney', 'rubble')
     tester = bindings.Binding(bindings.get_accessor(ex, 'name'), bindings.get_accessor(ex2, 'val'))
     del (ex)
     assert not tester()  # deleted referent = failed binding
     assert ex2.val == 'rubble'  # so value is unchanged
Пример #2
0
 def test_invalid_binding_fails(self):
     ex = self.Example('fred', 'flintstone')
     ex2 = self.Example('barney', 'rubble')
     tester = bindings.Binding(bindings.get_accessor(ex, 'name'),
                               bindings.get_accessor(ex2, 'val'))
     tester.invalidate()
     assert not tester()
Пример #3
0
 def test_pyattr_accessor(self):
     cmds.file(new=True, f=True)
     cube, shape = pm.polyCube()
     ac = bindings.get_accessor(cube.rx)
     assert isinstance(ac, bindings.PyAttributeAccessor)
     ac2 = bindings.get_accessor(shape.width)
     assert isinstance(ac2, bindings.PyAttributeAccessor)
Пример #4
0
 def test_basic_binding_update(self):
     ex = self.Example('fred', 'flintstone')
     ex2 = self.Example('barney', 'rubble')
     tester = bindings.Binding(bindings.get_accessor(ex, 'name'),
                               bindings.get_accessor(ex2, 'val'))
     tester()
     assert ex2.val == ex.name
Пример #5
0
 def test_pynode_accessor(self):
     cmds.file(new=True, f=True)
     cube, shape = pm.polyCube()
     ac = bindings.get_accessor(cube, 'rx')
     assert isinstance(ac, bindings.PyNodeAccessor)
     ac2 = bindings.get_accessor(shape, 'width')
     assert isinstance(ac2, bindings.PyNodeAccessor)
Пример #6
0
 def test_pynode_accessor(self):
     cmds.file(new=True, f=True)
     cube, shape = pm.polyCube()
     ac = bindings.get_accessor(cube, 'rx')
     assert isinstance(ac, bindings.PyNodeAccessor)
     ac2 = bindings.get_accessor(shape, 'width')
     assert isinstance(ac2, bindings.PyNodeAccessor)
Пример #7
0
 def test_pyattr_accessor(self):
     cmds.file(new=True, f=True)
     cube, shape = pm.polyCube()
     ac = bindings.get_accessor(cube.rx)
     assert isinstance(ac, bindings.PyAttributeAccessor)
     ac2 = bindings.get_accessor(shape.width)
     assert isinstance(ac2, bindings.PyAttributeAccessor)
Пример #8
0
 def test_binding_source_order(self):
     ex = self.Example('fred', 'flintstone')
     ex2 = self.Example('barney', 'rubble')
     tester = bindings.Binding(bindings.get_accessor(ex, 'name'),
                               bindings.get_accessor(ex2, 'val'))
     assert tester.getter.target.name == 'fred'
     assert tester.setter.target.name == 'barney'
Пример #9
0
 def test_binding_survives_object_deletion(self):
     ex = self.Example('fred', 'flintstone')
     ex2 = self.Example('barney', 'rubble')
     tester = bindings.Binding(bindings.get_accessor(ex, 'name'),
                               bindings.get_accessor(ex2, 'val'))
     del (ex)
     assert not tester()  # deleted referent = failed binding
     assert ex2.val == 'rubble'  # so value is unchanged
Пример #10
0
 def test_bindings_except_when_allowed(self):
     ex = self.Example('fred', 'flintstone')
     ex2 = self.Example('barney', 'rubble')
     tester = bindings.Binding(bindings.get_accessor(ex, 'name'), bindings.get_accessor(ex2, 'val'))
     bindings.BREAK_ON_ACCESS_FAILURE = True
     bindings.BREAK_ON_BIND_FAILURE = True
     del (ex)
     self.assertRaises(bindings.BindingError, tester)
Пример #11
0
 def test_bindings_except_when_allowed(self):
     ex = self.Example('fred', 'flintstone')
     ex2 = self.Example('barney', 'rubble')
     tester = bindings.Binding(bindings.get_accessor(ex, 'name'),
                               bindings.get_accessor(ex2, 'val'))
     bindings.BREAK_ON_ACCESS_FAILURE = True
     bindings.BREAK_ON_BIND_FAILURE = True
     del (ex)
     self.assertRaises(bindings.BindingError, tester)
Пример #12
0
    def test_find_simple_property(self):
        class Dummy(object):
            def __init__(self):
                self.Property = 999

        sample = Dummy()
        accessor = bindings.get_accessor(sample, 'Property')
        assert isinstance(accessor, bindings.Accessor)
        assert accessor.pull() == 999
Пример #13
0
    def test_find_simple_property(self):
        class Dummy(object):
            def __init__(self):
                self.Property = 999

        sample = Dummy()
        accessor = bindings.get_accessor(sample, 'Property')
        assert isinstance(accessor, bindings.Accessor)
        assert accessor.pull() == 999
Пример #14
0
    def test_find_mapped_on_mapping_derived(self):
        class MapTest(object):
            def __init__(self):
                self.secret = 999

            def __getitem__(self, key):
                if key == 'test':
                    return self.secret
                else:
                    return -999

            def __setitem__(self, key, val):
                if key == 'test': self.secret = val

            def __len__(self):
                return 1

        example = MapTest()
        accessor = bindings.get_accessor(example, 'test')
        assert isinstance(accessor, bindings.DictAccessor)
        assert accessor.pull() == 999
Пример #15
0
    def test_find_mapped_on_mapping_derived(self):

        class MapTest(object):
            def __init__(self):
                self.secret = 999

            def __getitem__(self, key):
                if key == 'test':
                    return self.secret
                else:
                    return -999

            def __setitem__(self, key, val):
                if key == 'test': self.secret = val

            def __len__(self):
                return 1

        example = MapTest()
        accessor = bindings.get_accessor(example, 'test')
        assert isinstance(accessor, bindings.DictAccessor)
        assert accessor.pull() == 999
Пример #16
0
 def test_find_mapped_property(self):
     sample = {'hello': 'world'}
     accessor = bindings.get_accessor(sample, 'hello')
     assert isinstance(accessor, bindings.DictAccessor)
     assert accessor.pull() == 'world'
Пример #17
0
 def test_binding_source_order(self):
     ex = self.Example('fred', 'flintstone')
     ex2 = self.Example('barney', 'rubble')
     tester = bindings.Binding(bindings.get_accessor(ex, 'name'), bindings.get_accessor(ex2, 'val'))
     assert tester.getter.target.name == 'fred'
     assert tester.setter.target.name == 'barney'
Пример #18
0
 def test_basic_binding_update(self):
     ex = self.Example('fred', 'flintstone')
     ex2 = self.Example('barney', 'rubble')
     tester = bindings.Binding(bindings.get_accessor(ex, 'name'), bindings.get_accessor(ex2, 'val'))
     tester()
     assert ex2.val == ex.name
Пример #19
0
    def test_cmds_accessor(self):
        cmds.file(new=True, f=True)

        ac = bindings.get_accessor('persp', 'tx')
        assert isinstance(ac, bindings.CmdsAccessor)
Пример #20
0
 def test_pynode_accessor_excepts_for_nonexistent_attrib(self):
     cmds.file(new=True, f=True)
     cube, _ = pm.polyCube()
     self.assertRaises(bindings.BindingError, lambda: bindings.get_accessor(cube, 'xyz'))
Пример #21
0
 def test_cmds_accessor_excepts_for_nonexistent_object(self):
     cmds.file(new=True, f=True)
     self.assertRaises(bindings.BindingError,
                       lambda: bindings.get_accessor('dont_exist', 'tx'))
Пример #22
0
 def test_cmds_accessor_excepts_for_nonexistent_attrrib(self):
     cmds.file(new=True, f=True)
     self.assertRaises(bindings.BindingError, lambda: bindings.get_accessor('persp', 'dontexist'))
Пример #23
0
 def test_cmds_accessor_excepts_for_nonexistent_object(self):
     cmds.file(new=True, f=True)
     self.assertRaises(bindings.BindingError, lambda: bindings.get_accessor('dont_exist', 'tx'))
Пример #24
0
    def test_cmds_accessor(self):
        cmds.file(new=True, f=True)

        ac = bindings.get_accessor('persp', 'tx')
        assert isinstance(ac, bindings.CmdsAccessor)
Пример #25
0
 def test_find_mapped_property(self):
     sample = {'hello': 'world'}
     accessor = bindings.get_accessor(sample, 'hello')
     assert isinstance(accessor, bindings.DictAccessor)
     assert accessor.pull() == 'world'
Пример #26
0
 def test_cmds_accessor_excepts_for_nonexistent_attrrib(self):
     cmds.file(new=True, f=True)
     self.assertRaises(bindings.BindingError,
                       lambda: bindings.get_accessor('persp', 'dontexist'))
Пример #27
0
 def test_pynode_accessor_excepts_for_nonexistent_attrib(self):
     cmds.file(new=True, f=True)
     cube, _ = pm.polyCube()
     self.assertRaises(bindings.BindingError,
                       lambda: bindings.get_accessor(cube, 'xyz'))
Пример #28
0
 def test_invalid_binding_fails(self):
     ex = self.Example('fred', 'flintstone')
     ex2 = self.Example('barney', 'rubble')
     tester = bindings.Binding(bindings.get_accessor(ex, 'name'), bindings.get_accessor(ex2, 'val'))
     tester.invalidate()
     assert not tester()
Пример #29
0
 def test_basic_binding(self):
     ex = self.Example('fred', 'flintstone')
     ex2 = self.Example('barney', 'rubble')
     tester = bindings.Binding(bindings.get_accessor(ex, 'Name'), bindings.get_accessor(ex2, 'Val'))
     assert tester