Пример #1
0
 def _(self):
     some_instance = SomeClass()
     with stub(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")
Пример #2
0
 def _(self):
     some_instance = SomeClass()
     with stub(some_instance.some_method) as spy:
         some_instance.some_method("anything", ["can"], go="here")
         expect(spy.last_call).to_be((("anything", ["can"]), {
             "go": "here"
         }))
Пример #3
0
 def _(self):
     with stub(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(Spy.get_spy(SomeClass.some_class_method)).to_be(spy)
Пример #4
0
 def _(self):
     some_instance = SomeClass()
     with stub('some_method', on=some_instance) as spy:
         some_instance.some_method("some_arg 123")
         expect(spy.last_call).to_be((("some_arg 123", ), {}))
         expect(Spy.get_spy(
             some_instance.some_method)).to_be(spy)
Пример #5
0
        def _(self):
            some_instance = SomeOtherClass()

            with stub(some_instance.some_function).call_real():
                result = some_instance.some_function("anything", ["can"],
                                                     go="here")
                expect(result).to_be("some_value")
Пример #6
0
        def _(self):
            some_instance = SomeClass()

            def some_function(*args, **kwargs):
                return "some_value"

            some_instance.some_function = some_function
            expect(lambda: stub(some_instance.some_function)
                   ).to_raise_error_of_type(ValueError)
Пример #7
0
 def _(self):
     with stub(some_class.some_module_method, on=some_class) as spy:
         some_class.some_module_method("anything", ["can"],
                                       go="here")
         expect(spy.last_call).to_be((("anything", ["can"]), {
             "go": "here"
         }))
         expect(Spy.get_spy(
             some_class.some_module_method)).to_be(spy)
Пример #8
0
 def _(self):
     some_instance = SomeOtherClass()
     original_function = some_instance.some_function
     with stub(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(spy.last_call).to_be_none()
     expect(some_instance.some_function).to_be(original_function)
Пример #9
0
 def spy(self, object_to_stub=None, method=None):
     new_spy = stub(object_to_stub, method)
     self._spies.append(new_spy)
     return new_spy
Пример #10
0
 def _(self):
     expect(lambda: stub(SomeClass.some_method)
            ).to_raise_error_of_type(ValueError)
Пример #11
0
 def _(self):
     some_instance = SomeClass()
     expect(lambda: stub(some_instance.some_decorated_method)
            ).to_raise_error_of_type(ValueError)