示例#1
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()
示例#2
0
文件: spy_test.py 项目: Avvir/pyne
def test__then_return__can_set_the_return_value_for_a_class_method():
    with TemporaryClass() as SomeTemporaryClass:
        when(SomeTemporaryClass.some_class_method).then_return("some value")

        expect(
            SomeTemporaryClass.some_class_method(
                "anything", ["can"], go="here")).to_be("some value")
示例#3
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")
示例#4
0
文件: spy_test.py 项目: Avvir/pyne
def test__stub__when_stubbing_a_static_method__tracks_what_the_method_was_called_with(
):
    with TemporaryClass() as SomeTemporaryClass:
        when(SomeTemporaryClass.some_static_method, SomeTemporaryClass)

        SomeTemporaryClass.some_static_method("anything", ["can"], go="here")
        expect(SomeTemporaryClass.some_static_method.last_call).to_be(
            (("anything", ["can"]), {
                "go": "here"
            }))
示例#5
0
文件: spy_test.py 项目: Avvir/pyne
def test__restore__can_set_a_class_method_back_to_what_it_originally_was():
    with TemporaryClass() as SomeTemporaryClass:
        original_class_method = SomeTemporaryClass.some_class_method

        when(SomeTemporaryClass.some_class_method).then_return("some value")

        SomeTemporaryClass.some_class_method.restore()

        expect(
            SomeTemporaryClass.some_class_method).to_be(original_class_method)
示例#6
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"}))
示例#7
0
文件: spy_test.py 项目: Avvir/pyne
def test__then_return__can_set_the_return_value_for_a_function():
    def some_function(*args, **kwargs):
        return "some_value"

    with when(some_function) as spy:
        spy.then_return("some_other_value")
        expect(spy.return_value).to_be("some_other_value")