コード例 #1
0
ファイル: spy_test.py プロジェクト: Avvir/pyne
def test__stub__when_passed_in_an_instance_method__tracks_what_the_method_was_called_with(
):
    instance = SomeClass()
    spy = when(instance.some_method)

    instance.some_method("anything", ["can"], go="here")
    expect(spy.last_call).to_be((("anything", ["can"]), {"go": "here"}))
コード例 #2
0
ファイル: spy_test.py プロジェクト: Avvir/pyne
 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 test__for_an_instance_method__was_called__can_pass():
    some_instance = SomeClass()

    spy_on(some_instance.some_method)

    some_instance.some_method()
    expect(some_instance.some_method).was_called()
コード例 #4
0
ファイル: attached_spy_test.py プロジェクト: Avvir/pyne
 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"}))
コード例 #5
0
ファイル: attached_spy_test.py プロジェクト: Avvir/pyne
 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)
コード例 #6
0
ファイル: spy_test.py プロジェクト: Avvir/pyne
 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)
コード例 #7
0
ファイル: attached_spy_test.py プロジェクト: Avvir/pyne
 def _(self):
     some_instance = SomeClass()
     with AttachedSpy(some_instance, "some_method") as spy:
         some_instance.some_method("anything", ["can"], go="here")
         expect(spy.last_call).to_be((("anything", ["can"]), {
             "go": "here"
         }))
     expect(spy.last_call).to_be_none()
コード例 #8
0
ファイル: attached_spy_test.py プロジェクト: Avvir/pyne
 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)
コード例 #9
0
ファイル: spy_test.py プロジェクト: Avvir/pyne
 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")
     result = some_instance.some_method("anything", ["can"], go="here")
     expect(result).to_be(None)
コード例 #10
0
def test__for_an_instance_method__was_called_with__can_pass():
    some_instance = SomeClass()

    spy_on(some_instance.some_method)

    some_instance.some_method("some-positional-argument",
                              ["some-array-content"])
    expect(some_instance.some_method).was_called_with(
        "some-positional-argument", ["some-array-content"])
コード例 #11
0
ファイル: sandbox_test.py プロジェクト: Avvir/pyne
def test__sandbox_reset():
    sandbox = Sandbox()
    some_class_instance = SomeClass()
    sandbox.spy(some_class_instance.some_method)

    some_class_instance.some_method("some_arg")
    assert some_class_instance.some_method.last_call == (("some_arg",), {})
    sandbox.reset()
    assert some_class_instance.some_method.last_call is None
コード例 #12
0
def test__was_called_with_matcher__supports_matchers_for_positional_arguments(
):
    some_instance = SomeClass()

    spy_on(some_instance.some_method)

    some_instance.some_method("some-positional-argument",
                              ["some-array-content"])
    expect(some_instance.some_method).to_be(
        was_called_with(anything(), ["some-array-content"]))
コード例 #13
0
def test__was_called_with_matcher__when_the_method_was_called_with_the_different_arguments__fails_with_a_message(
):
    some_instance = SomeClass()

    spy_on(some_instance.some_method)

    some_instance.some_method("some-positional-argument", "some-array-content")
    expect_expectation_to_fail_with_message(
        lambda: expect(some_instance.some_method).to_be(
            was_called_with("some-positional-argument", ["some-array-content"])
        ), "Expected <.*> to be <was_called_with\(.*>")
コード例 #14
0
def test__was_called_with_matcher__when_the_method_was_called_with_different_keyword_args__fails_with_a_message(
):
    some_instance = SomeClass()

    spy_on(some_instance.some_method)

    some_instance.some_method(some_keyword_arg="some-value")

    expect_expectation_to_fail_with_message(
        lambda: expect(some_instance.some_method).to_be(
            was_called_with(some_keyword_arg="some-other-value")),
        "Expected <.*> to be <was_called_with\(.*>")
コード例 #15
0
def test__for_an_instance_method__was_called_with__when_the_method_was_called_with_the_wrong_parameters__fails_with_a_message(
):
    some_instance = SomeClass()

    spy_on(some_instance.some_method)

    some_instance.some_method("some-positional-argument", "some-array-content")
    expect_expectation_to_fail_with_message(
        lambda: expect(some_instance.some_method).was_called_with(
            "some-positional-argument", ["some-array-content"]),
        """Expected that <SomeClass#some_method> was called with <('some-positional-argument', ['some-array-content'])> but it was called with <('some-positional-argument', 'some-array-content')>"""
    )
コード例 #16
0
ファイル: sandbox_test.py プロジェクト: Avvir/pyne
def test__sandbox_restore():
    sandbox = Sandbox()
    some_class_instance = SomeClass()
    some_other_instace = SomeClass()
    sandbox.spy(some_class_instance.some_method)
    sandbox.spy(some_other_instace.some_positional_args_method)

    some_class_instance.some_method()
    assert sandbox._spies[0].method_name == 'some_method'
    assert sandbox._spies[1].method_name == 'some_positional_args_method'

    sandbox.restore()
    assert len(sandbox._spies) == 0
コード例 #17
0
ファイル: spy_test.py プロジェクト: Avvir/pyne
def test__restore__after_stubbing_an_instance_method__sets_the_method_back_to_what_it_originally_was(
):
    instance = SomeClass()
    when(instance.some_method).then_return("some value")

    instance.some_method.restore()
    expect(instance.some_method("anything", ["can"], go="here")).to_be_none()
コード例 #18
0
ファイル: attached_spy_test.py プロジェクト: Avvir/pyne
 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")
コード例 #19
0
ファイル: spy_test.py プロジェクト: Avvir/pyne
def test__then_return__returns_the_given_value_when_a_stubbed_method_is_called(
):
    instance = SomeClass()

    when(instance.some_method).then_return("some value")

    expect(instance.some_method("anything", ["can"],
                                go="here")).to_be("some value")
コード例 #20
0
 def _(self):
     some_instance = SomeClass()
     with attach_spy(some_instance, "some_method"):
         some_instance.some_method()
         expect_assertion_error(lambda: expect(some_instance.some_method).was_not_called())
コード例 #21
0
ファイル: sandbox_test.py プロジェクト: Avvir/pyne
def test__sandbox_when_calling_then_return():
    sandbox = Sandbox()
    some_class_instance = SomeClass()
    sandbox.when_calling(some_class_instance.some_method).then_return(5)
    assert some_class_instance.some_method() == 5
コード例 #22
0
 def _(self):
     some_instance = SomeClass()
     with spy_on(some_instance.some_method):
         some_instance.some_method()
         expect_assertion_error(
             lambda: expect(some_instance.some_method).was_not_called())
コード例 #23
0
 def _(self):
     some_instance = SomeClass()
     with spy_on(some_instance.some_method):
         some_instance.some_method()
         expect(some_instance.some_method).was_called()
コード例 #24
0
 def _(self):
     with AttachedSpy(SomeClass, "some_method"):
         some_instance = SomeClass()
         some_instance.some_method("some_arg")
         expect(some_instance.some_method).was_called()
コード例 #25
0
 def _(self):
     some_instance = SomeClass()
     with attach_spy(some_instance, "some_method"):
         expect(some_instance.some_method).was_not_called()
         some_instance.some_method("anything", ["can"], go="here")
         expect(some_instance.some_method).was_called_with("anything", ["can"], go="here")
コード例 #26
0
 def _(self):
     some_instance = SomeClass()
     with attach_spy(some_instance, "some_method"):
         some_instance.some_method()
         expect(some_instance.some_method).was_called()