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
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()
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)
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
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)
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'
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)
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
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
def test_find_mapped_property(self): sample = {'hello': 'world'} accessor = bindings.get_accessor(sample, 'hello') assert isinstance(accessor, bindings.DictAccessor) assert accessor.pull() == 'world'
def test_cmds_accessor(self): cmds.file(new=True, f=True) ac = bindings.get_accessor('persp', 'tx') assert isinstance(ac, bindings.CmdsAccessor)
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'))
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'))
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'))
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