Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 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"}))
Exemplo n.º 6
0
 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")
Exemplo n.º 7
0
 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"
             }))
Exemplo n.º 8
0
 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")
Exemplo n.º 9
0
        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")
Exemplo n.º 10
0
        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)
Exemplo n.º 11
0
Arquivo: spy.py Projeto: Avvir/pyne
 def get_spy(object):
     if isinstance(object, Spy):
         return object
     return AttachedSpy.get_spy(object)
Exemplo n.º 12
0
 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()
Exemplo n.º 13
0
 def _(self):
     with AttachedSpy(SomeClass, "some_static_method"):
         SomeClass.some_static_method("anything", ["can"], go="here")
         expect(SomeClass.some_static_method).was_called()
Exemplo n.º 14
0
 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()
Exemplo n.º 15
0
 def _(self):
     with AttachedSpy(SomeClass, "some_method"):
         some_instance = SomeClass()
         some_instance.some_method("some_arg")
         expect(some_instance.some_method).was_called()
Exemplo n.º 16
0
 def _(self):
     with AttachedSpy(some_class, "some_module_method"):
         expect(some_class.some_module_method).was_not_called()
Exemplo n.º 17
0
 def _(self):
     with AttachedSpy(SomeClass, "some_class_method"):
         expect(SomeClass.some_class_method).was_not_called()
Exemplo n.º 18
0
 def _(self):
     some_instance = SomeClass()
     with AttachedSpy(some_instance, "some_decorated_method"):
         expect(some_instance.some_decorated_method).was_not_called()
Exemplo n.º 19
0
 def _(self):
     some_instance = SomeClass()
     expect(lambda: AttachedSpy(some_instance, "some_nonexistent_method"
                                )).to_raise_error_of_type(ValueError)