Пример #1
0
def test_is_satisfied_if_called_as_many_times_as_initial_call_count():
    call = Call('save', IntegerCallCount(2))
    assert not call.is_satisfied()
    call()
    assert not call.is_satisfied()
    call()
    assert call.is_satisfied()
Пример #2
0
def test_accepts_returns_true_if_call_count_is_greater_than_zero():
    call = Call('save', IntegerCallCount(2))
    assert call.accepts([], {}, [])
    call()
    assert call.accepts([], {}, [])
    call()
    assert not call.accepts([], {}, [])
Пример #3
0
def test_accepts_returns_true_if_arguments_match_those_set_by_with_args():
    call = Call('save')
    call.with_args(1, 2, name="Bob")
    assert not call.accepts((), {}, [])
    assert not call.accepts((1, 2, 3), {"name": "Bob"}, [])
    assert not call.accepts((1, ), {"name": "Bob"}, [])
    assert call.accepts((1, 2), {"name": "Bob"}, [])
Пример #4
0
def test_can_use_matchers_instead_of_values_for_keyword_arguments_when_using_with_args():
    class BlahMatcher(Matcher):
        def matches(self, other, failure_output):
            return other == "Blah"
            
    return_value = "Whoopee!"
    call = Call('save').with_args(value=BlahMatcher()).returns(return_value)
    
    assert call.accepts([], {'value': 'Blah'}, [])
    assert not call.accepts([], {}, [])
    assert not call.accepts([], {'key': 'word'}, [])
    assert not call.accepts(["positional"], {}, [])
    assert not call.accepts(["blah", "positional"], {}, [])
    assert not call.accepts(["positional"], {'key': 'word'}, [])
    assert not call.accepts([], {'key': 'word', 'value': 'Blah'}, [])
    assert call(value="Blah") is return_value
Пример #5
0
def test_call_that_allows_any_number_of_calls_is_always_satisfied():
    call = Call('save')
    for x in range(0, 1000):
        assert call.is_satisfied()
        call()
Пример #6
0
def test_has_name_returns_true_if_passed_name_matches_method_name():
    call = Call('save')
    assert call.has_name('save')
    assert not call.has_name('saved')
    assert not call.has_name('sav')
Пример #7
0
def test_error_is_raised_if_called_with_wrong_arguments():
    call = Call('save')
    call.with_args("positional")
    call("positional")
    assert_raises_str(FunkyError, "Called with wrong arguments", lambda: call(["wrong"], {}))
Пример #8
0
def test_not_specifying_call_count_allows_any_number_of_calls():
    call = Call('save')
    for x in range(0, 1000):
        assert call.accepts([], {}, [])
        call()
Пример #9
0
def test_accepts_returns_true_if_with_args_not_called():
    call = Call('save')
    assert call.accepts((), {}, [])
    assert call.accepts((1, 2, 3), {"name": "Bob"}, [])
Пример #10
0
def test_mismatch_description_shows_both_mismatching_positional_and_keyword_arguments():
    call = Call('save').with_args("eggs", "potatoes", vegetable="cucumber", fruit="banana")
    mismatch_description = []
    call.accepts(["duck", "potatoes"], {"vegetable": "cucumber", "fruit": "coconut"}, mismatch_description)
    assert_equals(''.join(mismatch_description),
                  "save('eggs' [got 'duck'],\n     'potatoes' [matched],\n     fruit='banana' [got 'coconut'],\n     vegetable='cucumber' [matched])")
Пример #11
0
def test_mismatch_description_indicates_whether_keyword_arguments_matched_or_not():
    call = Call('save').with_args(vegetable="cucumber", fruit="banana")
    mismatch_description = []
    call.accepts([], {"vegetable": "cucumber", "fruit": "coconut"}, mismatch_description)
    assert_equals(''.join(mismatch_description), "save(fruit='banana' [got 'coconut'],\n     vegetable='cucumber' [matched])")
Пример #12
0
def test_returns_return_value_if_set():
    return_value = 'Oh noes!'
    call = Call('save')
    call.returns(return_value)
    assert call() is return_value
Пример #13
0
def test_mismatch_description_indicates_whether_keyword_argument_is_missing():
    call = Call('save').with_args(fruit="banana", vegetable="cucumber", salad="caesar")
    mismatch_description = []
    call.accepts([], {"fruit": "banana"}, mismatch_description)
    assert_equals(''.join(mismatch_description),
                  "save(fruit='banana', salad='caesar', vegetable='cucumber') [missing keyword arguments: salad, vegetable]")
Пример #14
0
def test_mismatch_description_indicates_whether_positional_arguments_matched_or_not():
    call = Call('save').with_args("apple", "banana")
    mismatch_description = []
    call.accepts(["coconut", "banana"], {}, mismatch_description)
    assert_equals(''.join(mismatch_description), "save('apple' [got 'coconut'],\n     'banana' [matched])")
Пример #15
0
def test_mismatch_description_indicates_when_number_of_positional_arguments_is_wrong():
    call = Call('save').with_args()
    mismatch_description = []
    call.accepts(["banana"], {}, mismatch_description)
    assert_equals(''.join(mismatch_description), "save() [wrong number of positional arguments]")
Пример #16
0
def test_mismatch_description_indicates_when_expectation_has_already_been_satisfied():
    call = Call('save', IntegerCallCount(1)).with_args()
    call()
    mismatch_description = []
    call.accepts([], {}, mismatch_description)
    assert_equals(''.join(mismatch_description), "save() [expectation has already been satisfied]")