Beispiel #1
0
 def test_representation_args_and_kwargs(self):
     test_obj = anything.with_attrs('bar', bob='barker')
     assert repr(test_obj) == (
         "<Equals Any object with attrs: bar and bob=barker>"
     )
     assert str(test_obj) == (
         "Any object with attrs: bar and bob=barker"
     )
Beispiel #2
0
class TestWithAttrs(object):
    test_obj = anything.with_attrs(foo='bar', bob='barker')

    def test_equals_instance_with_all_attrs(self):
        assert self.test_obj == Dummy('bar', 'barker')

    def test_does_not_equal_instance_with_all_attrs_but_diff_values(self):
        assert not self.test_obj == Dummy('Drew', 'Carey')

    def test_does_not_equal_instance_without_all_attrs(self):
        assert not self.test_obj == object()

    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')

    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')

    def test_order_of_test_does_not_matter(self):
        assert Dummy('bar', 'barker') == self.test_obj

    def test_passes_with_correct_args_and_kwargs(self):
        test_obj = anything.with_attrs('foo', bob='barker')
        assert Dummy('bar', 'barker') == test_obj

    def test_fails_with_incorrect_args_and_kwargs(self):
        test_obj = anything.with_attrs('bar', bob='barker')
        assert Dummy('bar', 'barker') != test_obj

    def test_representation(self):
        assert repr(self.test_obj) == (
            "<Equals Any object with attrs: bob=barker, foo=bar>")
        assert str(
            self.test_obj) == ("Any object with attrs: bob=barker, foo=bar")

    def test_representation_args_and_kwargs(self):
        test_obj = anything.with_attrs('bar', bob='barker')
        assert repr(test_obj) == (
            "<Equals Any object with attrs: bar and bob=barker>")
        assert str(test_obj) == ("Any object with attrs: bar and bob=barker")

    def test_poorly_implemented__eq__(self):
        test_obj = instance_of(NeverEquals).with_attrs(name="Bob Barker", )
        assert test_obj == NeverEquals("Bob Barker")

    def test__eq__that_returns_not_implemented(self):
        test_obj = instance_of(EqualsNotImplemented).with_attrs(
            name="Bob Barker", )
        assert EqualsNotImplemented("Bob Barker") == test_obj

    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")
Beispiel #3
0
 def test_representation_args_and_kwargs(self):
     test_obj = anything.with_attrs('bar', bob='barker')
     assert repr(test_obj) == (
         "<Equals Any object with attrs: bar and bob=barker>")
     assert str(test_obj) == ("Any object with attrs: bar and bob=barker")
Beispiel #4
0
 def test_fails_with_incorrect_args_and_kwargs(self):
     test_obj = anything.with_attrs('bar', bob='barker')
     assert Dummy('bar', 'barker') != test_obj
Beispiel #5
0
 def test_passes_with_correct_args_and_kwargs(self):
     test_obj = anything.with_attrs('foo', bob='barker')
     assert Dummy('bar', 'barker') == test_obj
Beispiel #6
0
 def test_fails_with_incorrect_args_and_kwargs(self):
     test_obj = anything.with_attrs('bar', bob='barker')
     assert Dummy('bar', 'barker') != test_obj
Beispiel #7
0
 def test_passes_with_correct_args_and_kwargs(self):
     test_obj = anything.with_attrs('foo', bob='barker')
     assert Dummy('bar', 'barker') == test_obj