def _(self): some_instance = SomeClass() with AttachedSpy(some_instance, "some_method") as spy: some_instance.some_method("some_arg") expect(spy.last_call).to_be((("some_arg", ), {})) expect(AttachedSpy.get_spy( some_instance.some_method)).to_be(spy)
def _(self): with AttachedSpy(SomeClass, "some_class_method") as spy: SomeClass.some_class_method("anything", ["can"], go="here") expect(spy.last_call).to_be((("anything", ["can"]), { "go": "here" })) expect(AttachedSpy.get_spy( SomeClass.some_class_method)).to_be(spy)
def _(self): with AttachedSpy(SomeClass, "some_method", needs_binding=True) as spy: some_instance = SomeClass() some_instance.some_method("some_arg") expect(spy.last_call).to_be((("some_arg", ), {})) expect(AttachedSpy.get_spy( some_instance.some_method)).to_be(spy)
def _(self): some_instance = SomeClass() with AttachedSpy(some_instance, "some_decorated_method") as spy: some_instance.some_decorated_method("anything", ["can"], go="here") expect(spy.last_call).to_be((("anything", ["can"]), { "go": "here" })) expect( AttachedSpy.get_spy( some_instance.some_decorated_method)).to_be(spy)
def _(self): some_instance = SomeClass() with AttachedSpy(some_instance, "some_method") as spy: some_instance.some_method("anything", ["can"], go="here") some_instance.some_method("or", ["here"], xor="here") expect(spy.calls).to_have_length(2) expect(spy.calls[1]).to_be((("or", ["here"]), {"xor": "here"}))
def _(self): some_instance = SomeClass() with AttachedSpy(some_instance, "some_method").then_return("some_value") as spy: result = some_instance.some_method("anything", ["can"], go="here") expect(result).to_be("some_value")
def _(self): some_instance = SomeClass() with AttachedSpy(some_instance, "some_method") as spy: some_instance.some_method("anything", ["can"], go="here") expect(last_call_of(some_instance.some_method)).to_be( (("anything", ["can"]), { "go": "here" }))
def _(self): with AttachedSpy(SomeClass, "some_args_method_that_returns_some_value", needs_binding=True).call_real() as spy: some_class = SomeClass() expect( some_class.some_args_method_that_returns_some_value( "some_arg", some_keyword_arg="some_kwarg")).to_be("some_value") expect(some_class.some_args_method_that_returns_some_value ).was_called_with("some_arg", some_keyword_arg="some_kwarg")
def _(self): some_instance = SomeClass() def some_function(*args, **kwargs): return "some_value" some_instance.some_function = some_function with AttachedSpy(some_instance, "some_function").call_real(): result = some_instance.some_function("anything", ["can"], go="here") expect(result).to_be("some_value")
def _(self): def some_function(*args, **kwargs): return "some_value" some_instance = SomeClass() some_instance.some_function = some_function with AttachedSpy(some_instance, "some_function") as spy: some_instance.some_function("anything", ["can"], go="here") expect(spy.last_call).to_be((("anything", ["can"]), { "go": "here" })) expect(some_instance.some_function).to_be(some_function)
def get_spy(object): if isinstance(object, Spy): return object return AttachedSpy.get_spy(object)
def _(self): with AttachedSpy(some_class, "some_module_method"): some_class.some_module_method("anything", ["can"], go="here") expect(some_class.some_module_method).was_called()
def _(self): with AttachedSpy(SomeClass, "some_static_method"): SomeClass.some_static_method("anything", ["can"], go="here") expect(SomeClass.some_static_method).was_called()
def _(self): some_instance = SomeClass() with AttachedSpy(some_instance, "some_decorated_method"): some_instance.some_decorated_method("anything", ["can"], go="here") expect(some_instance.some_decorated_method).was_called()
def _(self): with AttachedSpy(SomeClass, "some_method"): some_instance = SomeClass() some_instance.some_method("some_arg") expect(some_instance.some_method).was_called()
def _(self): with AttachedSpy(some_class, "some_module_method"): expect(some_class.some_module_method).was_not_called()
def _(self): with AttachedSpy(SomeClass, "some_class_method"): expect(SomeClass.some_class_method).was_not_called()
def _(self): some_instance = SomeClass() with AttachedSpy(some_instance, "some_decorated_method"): expect(some_instance.some_decorated_method).was_not_called()
def _(self): some_instance = SomeClass() expect(lambda: AttachedSpy(some_instance, "some_nonexistent_method" )).to_raise_error_of_type(ValueError)