def test_simple_signal_object_identifier(): on_test_identifier(obj='xxx') class Foo(): def on_test_identifier(self, a): a / self.b __init__ = register_object f1 = Foo() f2 = Foo() f1.b = 1 f2.b = 0 with pytest.raises(MissingIdentifier): on_test_identifier(a=5, b=0, c='c') on_test_identifier(a=5, b=0, obj=f1) with pytest.raises(ZeroDivisionError): on_test_identifier(a=5, b=0, obj=f2) unregister_object(f1) unregister_object(f2) with on_test_identifier.registered(f2.on_test_identifier): with pytest.raises(ZeroDivisionError): on_test_identifier(a=5, b=0, obj=f2)
def test_simple_signal_object_registration(): class Foo(): def on_test(self, a, b): a / b __init__ = register_object f = Foo() with pytest.raises(ZeroDivisionError): on_test(a=5, b=0, c='c') unregister_object(f)
def test_simple_signal_object_wo_identifier(): class Foo(): def on_test_identifier(self, obj): 1 / 0 __init__ = register_object f1 = Foo() with pytest.raises(ZeroDivisionError): on_test_identifier(a=5, b=0, obj='obj1') on_test_identifier(a=5, b=0, obj='obj2') unregister_object(f1)
def test_simple_signal_object_identifier_attribute(): class Foo(): def on_test_identifier(self): 1 / 0 __init__ = register_object f1 = Foo() f1.obj = 'obj1' on_test_identifier(obj='xxx') with pytest.raises(ZeroDivisionError): on_test_identifier(obj='obj1') unregister_object(f1)
def test_ctx(): result = [] class Foo: @contextmanager def on_ctx_test(self, before, after): result.append(before) yield result.append(after) foo = Foo() register_object(foo) assert result == [] with on_ctx_test(before=1, after=2): assert result == [1] assert result == [1, 2] unregister_object(foo) with on_ctx_test(before=3, after=4): assert result == [1, 2] assert result == [1, 2]