1
|
|
|
if __name__ == '__main__': |
2
|
|
|
import sys |
3
|
|
|
sys.path.insert(0, '..') |
4
|
|
|
sys.path.insert(0, '../..') |
5
|
|
|
|
6
|
|
|
from hamcrest.core.core.isequal import * |
7
|
|
|
|
8
|
|
|
from hamcrest_unit_test.matcher_test import MatcherTest |
9
|
|
|
import unittest |
10
|
|
|
import pytest |
11
|
|
|
import six |
12
|
|
|
|
13
|
|
|
__author__ = "Jon Reid" |
14
|
|
|
__copyright__ = "Copyright 2011 hamcrest.org" |
15
|
|
|
__license__ = "BSD, see License.txt" |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
class IsEqualTest(MatcherTest): |
19
|
|
|
|
20
|
|
|
def testComparesObjectsUsingEquality(self): |
21
|
|
|
self.assert_matches('equal numbers', equal_to(1), 1) |
22
|
|
|
self.assert_does_not_match('unequal numbers', equal_to(1), 2) |
23
|
|
|
|
24
|
|
|
def testCanCompareNoneValues(self): |
25
|
|
|
self.assert_matches('None equals None', equal_to(None), None) |
26
|
|
|
|
27
|
|
|
self.assert_does_not_match('None as argument', equal_to('hi'), None) |
28
|
|
|
self.assert_does_not_match('None in equal_to', equal_to(None), 'hi') |
29
|
|
|
|
30
|
|
|
def testHonorsArgumentEqImplementationEvenWithNone(self): |
31
|
|
|
class AlwaysEqual: |
32
|
|
|
def __eq__(self, obj): return True |
33
|
|
|
class NeverEqual: |
34
|
|
|
def __eq__(self, obj): return False |
35
|
|
|
self.assert_matches("always equal", equal_to(None), AlwaysEqual()) |
36
|
|
|
self.assert_does_not_match("never equal", equal_to(None), NeverEqual()) |
37
|
|
|
|
38
|
|
|
def testIncludesTheResultOfCallingToStringOnItsArgumentInTheDescription(self): |
39
|
|
|
argument_description = 'ARGUMENT DESCRIPTION' |
40
|
|
|
class Argument: |
41
|
|
|
def __str__(self): return argument_description |
42
|
|
|
self.assert_description('<ARGUMENT DESCRIPTION>', equal_to(Argument())) |
43
|
|
|
|
44
|
|
|
def testReturnsAnObviousDescriptionIfCreatedWithANestedMatcherByMistake(self): |
45
|
|
|
inner_matcher = equal_to('NestedMatcher') |
46
|
|
|
self.assert_description("<'NestedMatcher'>", equal_to(inner_matcher)) |
47
|
|
|
|
48
|
|
|
def testSuccessfulMatchDoesNotGenerateMismatchDescription(self): |
49
|
|
|
self.assert_no_mismatch_description(equal_to('hi'), 'hi') |
50
|
|
|
|
51
|
|
|
def testMismatchDescriptionShowsActualArgument(self): |
52
|
|
|
self.assert_mismatch_description("was 'bad'", equal_to('good'), 'bad') |
53
|
|
|
|
54
|
|
|
def testDescribeMismatch(self): |
55
|
|
|
self.assert_describe_mismatch("was 'bad'", equal_to('good'), 'bad') |
56
|
|
|
|
57
|
|
|
def testEqualToWithEqualBytes(self): |
58
|
|
|
self.assert_matches("equal for b", equal_to(six.b('a')), six.b('a')) |
59
|
|
|
|
60
|
|
|
def testNotEqualToWithEqualBytes(self): |
61
|
|
|
self.assert_does_not_match("equal for b", equal_to(six.b('a')), six.b('b')) |
62
|
|
|
|
63
|
|
|
@pytest.mark.skipif(six.PY2, reason="Py3 formatting") |
64
|
|
|
def testByteInequalityDescriptionPy3(self): |
65
|
|
|
self.assert_mismatch_description("was <{0!r}>".format(six.b('b')), equal_to(six.b('a')), six.b('b')) |
66
|
|
|
|
67
|
|
|
@pytest.mark.skipif(six.PY3, reason="Py2 formatting") |
68
|
|
|
def testByteInequalityDescriptionPy2(self): |
69
|
|
|
self.assert_mismatch_description("was {0!r}".format(six.b('b')), equal_to(six.b('a')), six.b('b')) |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
if __name__ == '__main__': |
73
|
|
|
unittest.main() |
74
|
|
|
|