Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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"}))
Esempio 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")
Esempio 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"
             }))
Esempio 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")
Esempio 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")
Esempio 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)
Esempio n. 11
0
File: spy.py Progetto: Avvir/pyne
 def get_spy(object):
     if isinstance(object, Spy):
         return object
     return AttachedSpy.get_spy(object)
Esempio 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()
Esempio 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()
Esempio 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()
Esempio 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()
Esempio n. 16
0
 def _(self):
     with AttachedSpy(some_class, "some_module_method"):
         expect(some_class.some_module_method).was_not_called()
Esempio n. 17
0
 def _(self):
     with AttachedSpy(SomeClass, "some_class_method"):
         expect(SomeClass.some_class_method).was_not_called()
Esempio n. 18
0
 def _(self):
     some_instance = SomeClass()
     with AttachedSpy(some_instance, "some_decorated_method"):
         expect(some_instance.some_decorated_method).was_not_called()
Esempio n. 19
0
 def _(self):
     some_instance = SomeClass()
     expect(lambda: AttachedSpy(some_instance, "some_nonexistent_method"
                                )).to_raise_error_of_type(ValueError)