|
1
|
|
|
if __name__ == '__main__': |
|
2
|
|
|
import sys |
|
3
|
|
|
sys.path.insert(0, '..') |
|
4
|
|
|
sys.path.insert(0, '../..') |
|
5
|
|
|
|
|
6
|
|
|
from hamcrest.core.core.allof import * |
|
7
|
|
|
|
|
8
|
|
|
from hamcrest.core.core.isequal import equal_to |
|
9
|
|
|
from hamcrest_unit_test.matcher_test import MatcherTest |
|
10
|
|
|
import unittest |
|
11
|
|
|
|
|
12
|
|
|
__author__ = "Jon Reid" |
|
13
|
|
|
__copyright__ = "Copyright 2011 hamcrest.org" |
|
14
|
|
|
__license__ = "BSD, see License.txt" |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
View Code Duplication |
class AllOfTest(MatcherTest): |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
def testMatchesIfArgumentSatisfiesBothOfTwoOtherMatchers(self): |
|
20
|
|
|
self.assert_matches('both matchers', |
|
21
|
|
|
all_of(equal_to('good'), equal_to('good')), |
|
22
|
|
|
'good') |
|
23
|
|
|
|
|
24
|
|
|
def testProvidesConvenientShortcutForMatchingWithEqualTo(self): |
|
25
|
|
|
self.assert_matches('both matchers', |
|
26
|
|
|
all_of('good', 'good'), |
|
27
|
|
|
'good') |
|
28
|
|
|
|
|
29
|
|
|
def testNoMatchIfArgumentFailsToSatisfyEitherOfTwoOtherMatchers(self): |
|
30
|
|
|
self.assert_does_not_match('first matcher', |
|
31
|
|
|
all_of(equal_to('bad'), equal_to('good')), |
|
32
|
|
|
'good') |
|
33
|
|
|
self.assert_does_not_match('second matcher', |
|
34
|
|
|
all_of(equal_to('good'), equal_to('bad')), |
|
35
|
|
|
'good') |
|
36
|
|
|
self.assert_does_not_match('either matcher', |
|
37
|
|
|
all_of(equal_to('bad'), equal_to('bad')), |
|
38
|
|
|
'good') |
|
39
|
|
|
|
|
40
|
|
|
def testMatchesIfArgumentSatisfiesAllOfManyOtherMatchers(self): |
|
41
|
|
|
self.assert_matches('all matchers', |
|
42
|
|
|
all_of(equal_to('good'), |
|
43
|
|
|
equal_to('good'), |
|
44
|
|
|
equal_to('good'), |
|
45
|
|
|
equal_to('good'), |
|
46
|
|
|
equal_to('good')), |
|
47
|
|
|
'good') |
|
48
|
|
|
|
|
49
|
|
|
def testNoMatchIfArgumentFailsToSatisfyAllOfManyOtherMatchers(self): |
|
50
|
|
|
self.assert_does_not_match('matcher in the middle', |
|
51
|
|
|
all_of(equal_to('good'), |
|
52
|
|
|
equal_to('good'), |
|
53
|
|
|
equal_to('good'), |
|
54
|
|
|
equal_to('bad'), |
|
55
|
|
|
equal_to('good'), |
|
56
|
|
|
equal_to('good')), |
|
57
|
|
|
'good') |
|
58
|
|
|
|
|
59
|
|
|
def testHasAReadableDescription(self): |
|
60
|
|
|
self.assert_description("('good' and 'bad' and 'ugly')", |
|
61
|
|
|
all_of(equal_to('good'), equal_to('bad'), equal_to('ugly'))) |
|
62
|
|
|
|
|
63
|
|
|
def testSuccessfulMatchDoesNotGenerateMismatchDescription(self): |
|
64
|
|
|
self.assert_no_mismatch_description( |
|
65
|
|
|
all_of(equal_to('good'), equal_to('good')), |
|
66
|
|
|
'good') |
|
67
|
|
|
|
|
68
|
|
|
def testMismatchDescriptionDescribesFirstFailingMatch(self): |
|
69
|
|
|
self.assert_mismatch_description( |
|
70
|
|
|
"'good' was 'bad'", |
|
71
|
|
|
all_of(equal_to('bad'), equal_to('good')), |
|
72
|
|
|
'bad') |
|
73
|
|
|
|
|
74
|
|
|
def testDescribeMismatch(self): |
|
75
|
|
|
self.assert_describe_mismatch( |
|
76
|
|
|
"'good' was 'bad'", |
|
77
|
|
|
all_of(equal_to('bad'), equal_to('good')), |
|
78
|
|
|
'bad') |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
if __name__ == '__main__': |
|
82
|
|
|
unittest.main() |
|
83
|
|
|
|