def test(base, create): def foo(self): return "foo" def _get_bar(self): return self._bar def _set_bar(self, value): self._bar = value def _del_bar(self): del self._bar bar = property(_get_bar, _set_bar, _del_bar) T = type("T", (base,), dict(foo=foo, bar=bar)) m = MockerExt() t = create(T) m.property(t, "bar") t.bar = "xyz" t.bar >> "abc" del t.bar with m: assert t.foo() == "foo" t.bar = "xyz" b = t.bar assert b == "abc", "got %r" % b del t.bar assert isinstance(t, T) assert T.bar is bar
def test_MockerExt_property_attr(): from Foundation import NSObject class Obj(object): def __init__(self): self.foo = 0 obj = Obj() m = MockerExt() m.property(obj, "foo") obj.foo >> "xyz" obj.foo = "abc" obj.foo >> "def" with m: assert obj.foo == "xyz" obj.foo = "abc" assert obj.foo == "def" assert isinstance(obj, Obj) assert not hasattr(Obj, "foo")
def test_MockerExt_property_value_mock(): from Foundation import NSObject class Obj(object): def __init__(self): self.foo = 0 obj = Obj() m = MockerExt() foo = m.property(obj, "foo") foo.value >> "xyz" foo.value = "abc" foo.value >> "def" del foo.value with m: assert obj.foo == "xyz" obj.foo = "abc" assert obj.foo == "def" del obj.foo assert isinstance(obj, Obj) assert not hasattr(Obj, "foo")