コード例 #1
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"}, [])
コード例 #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_can_use_matchers_instead_of_values_for_positional_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(BlahMatcher()).returns(return_value)
    
    assert call.accepts(["Blah"], {}, [])
    assert not call.accepts([], {}, [])
    assert not call.accepts([], {'key': 'word'}, [])
    assert not call.accepts(["positional"], {}, [])
    assert not call.accepts(["positional"], {'key': 'word'}, [])
    assert call("Blah") is return_value
コード例 #4
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()
コード例 #5
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])")
コード例 #6
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"}, [])
コード例 #7
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])")
コード例 #8
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]")
コード例 #9
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])")
コード例 #10
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]")
コード例 #11
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]")