Example #1
0
def test_mock_assert_called_with_can_fail():
    test_object = Mock()

    test_object.method({'bob': 'barker'})

    with pytest.raises(AssertionError):
        test_object.method.assert_called_with(instance_of(list))
Example #2
0
 def test_equals_same_type_with_multiple_types(self):
     assert instance_of(dict, tuple) == (1, 2)
Example #3
0
 def test_equals_same_type(self):
     assert instance_of(dict) == {}
Example #4
0
 def test__eq__that_returns_not_implemented_two(self):
     test_obj = instance_of(EqualsNotImplemented).with_attrs(
         name="Bob Barker", )
     assert test_obj == EqualsNotImplemented("Bob Barker")
Example #5
0
 def test_poorly_implemented__eq__(self):
     test_obj = instance_of(NeverEquals).with_attrs(name="Bob Barker", )
     assert test_obj == NeverEquals("Bob Barker")
Example #6
0
 def test_does_not_equal_instance_of_wrong_type(self):
     test_obj = instance_of(dict).with_attrs(foo='bar', bob='barker')
     assert not test_obj == Dummy('bar', 'barker')
Example #7
0
 def test_equals_instance_of_correct_type(self):
     test_obj = instance_of(Dummy).with_attrs(foo='bar', bob='barker')
     assert test_obj == Dummy('bar', 'barker')
Example #8
0
def test_mock_assert_called_with_passes():
    test_object = Mock()

    test_object.method({'bob': 'barker'})

    test_object.method.assert_called_with(instance_of(dict))
Example #9
0
 def test_order_of_test_does_not_matter(self):
     assert object() == instance_of(object)
Example #10
0
 def test_equals_same_type_with_multiple_types(self):
     assert instance_of(dict, tuple) == (1, 2)
Example #11
0
 def test_equals_same_type(self):
     assert instance_of(dict) == {}
Example #12
0
 def test__eq__that_returns_not_implemented_two(self):
     test_obj = instance_of(EqualsNotImplemented).with_attrs(
         name="Bob Barker",
     )
     assert test_obj == EqualsNotImplemented("Bob Barker")
Example #13
0
 def test_poorly_implemented__eq__(self):
     test_obj = instance_of(NeverEquals).with_attrs(
         name="Bob Barker",
     )
     assert test_obj == NeverEquals("Bob Barker")
Example #14
0
 def test_does_not_equal_instance_of_wrong_type(self):
     test_obj = instance_of(dict).with_attrs(foo='bar', bob='barker')
     assert not test_obj == Dummy('bar', 'barker')
Example #15
0
 def test_equals_instance_of_correct_type(self):
     test_obj = instance_of(Dummy).with_attrs(foo='bar', bob='barker')
     assert test_obj == Dummy('bar', 'barker')
Example #16
0
 def test_order_of_test_does_not_matter(self):
     assert object() == instance_of(object)
Example #17
0
 def test_representation(self):
     test_obj = instance_of(dict)
     expected = r"Any instance of <(type|class) 'dict'>"
     assert re.match(expected, str(test_obj))
     assert re.match('<Equals {}>'.format(expected), repr(test_obj))
Example #18
0
 def test_representation(self):
     test_obj = instance_of(dict)
     expected = r"Any instance of <(type|class) 'dict'>"
     assert re.match(expected, str(test_obj))
     assert re.match('<Equals {}>'.format(expected), repr(test_obj))