示例#1
0
def test_expose():
    @expose("increment")
    class Counter(object):
        def __init__(self):
            self.x = 0

        def increment(self, amount=1):
            self.x += amount

    assert watchable(Counter)
    assert Counter.__name__ == "Counter"
    assert isinstance(Counter.increment, MethodSpectator)
示例#2
0
    def test_subclass_override():
        @expose("method")
        class Parent:
            def method(self):
                pass

        class Child(Parent):
            def method(self):
                pass

        assert watchable(Child)
        assert isinstance(Child.method, MethodSpectator)
示例#3
0
def test_expose_as():
    WatchableList = expose_as("WatchableList", list, "append")
    assert watchable(WatchableList)
    assert issubclass(WatchableList, list)
    assert WatchableList.__name__ == "WatchableList"
    assert isinstance(WatchableList.append, MethodSpectator)
示例#4
0
def test_watchable():
    assert watchable(Watchable)
    assert watchable(Watchable())