1
|
|
|
if __name__ == '__main__': |
2
|
|
|
import sys |
3
|
|
|
sys.path.insert(0, '..') |
4
|
|
|
sys.path.insert(0, '../..') |
5
|
|
|
|
6
|
|
|
from hamcrest.core.core.anyof 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 AnyOfTest(MatcherTest): |
|
|
|
|
18
|
|
|
|
19
|
|
|
def testMatchesIfArgumentSatisfiesEitherOrBothOfTwoOtherMatchers(self): |
20
|
|
|
self.assert_matches('first matcher', |
21
|
|
|
any_of(equal_to('good'), equal_to('bad')), |
22
|
|
|
'good') |
23
|
|
|
self.assert_matches('second matcher', |
24
|
|
|
any_of(equal_to('bad'), equal_to('good')), |
25
|
|
|
'good') |
26
|
|
|
self.assert_matches('both matchers', |
27
|
|
|
any_of(equal_to('good'), equal_to('good')), |
28
|
|
|
'good') |
29
|
|
|
|
30
|
|
|
def testProvidesConvenientShortcutForMatchingWithEqualTo(self): |
31
|
|
|
self.assert_matches('first matcher', |
32
|
|
|
any_of('good', 'bad'), |
33
|
|
|
'good') |
34
|
|
|
self.assert_matches('second matcher', |
35
|
|
|
any_of('bad', 'good'), |
36
|
|
|
'good') |
37
|
|
|
self.assert_matches('both matchers', |
38
|
|
|
any_of('good', 'good'), |
39
|
|
|
'good') |
40
|
|
|
|
41
|
|
|
def testNoMatchIfArgumentFailsToSatisfyEitherOfTwoOtherMatchers(self): |
42
|
|
|
self.assert_does_not_match('either matcher', |
43
|
|
|
any_of(equal_to('bad'), equal_to('bad')), |
44
|
|
|
'good') |
45
|
|
|
|
46
|
|
|
def testMatchesIfArgumentSatisfiesAnyOfManyOtherMatchers(self): |
47
|
|
|
self.assert_matches('matcher in the middle', |
48
|
|
|
any_of(equal_to('bad'), |
49
|
|
|
equal_to('bad'), |
50
|
|
|
equal_to('good'), |
51
|
|
|
equal_to('bad'), |
52
|
|
|
equal_to('bad')), |
53
|
|
|
'good') |
54
|
|
|
|
55
|
|
|
def testNoMatchIfArgumentFailsToSatisfyAnyOfManyOtherMatchers(self): |
56
|
|
|
self.assert_does_not_match('all matchers', |
57
|
|
|
any_of(equal_to('bad'), |
58
|
|
|
equal_to('bad'), |
59
|
|
|
equal_to('bad'), |
60
|
|
|
equal_to('bad'), |
61
|
|
|
equal_to('bad')), |
62
|
|
|
'good') |
63
|
|
|
|
64
|
|
|
def testHasAReadableDescription(self): |
65
|
|
|
self.assert_description("('good' or 'bad' or 'ugly')", |
66
|
|
|
any_of(equal_to('good'), equal_to('bad'), equal_to('ugly'))) |
67
|
|
|
|
68
|
|
|
def testSuccessfulMatchDoesNotGenerateMismatchDescription(self): |
69
|
|
|
self.assert_no_mismatch_description( |
70
|
|
|
any_of(equal_to('good'), equal_to('bad')), |
71
|
|
|
'good') |
72
|
|
|
|
73
|
|
|
def testMismatchDescriptionDescribesFirstFailingMatch(self): |
74
|
|
|
self.assert_mismatch_description( |
75
|
|
|
"was 'ugly'", |
76
|
|
|
any_of(equal_to('bad'), equal_to('good')), |
77
|
|
|
'ugly') |
78
|
|
|
|
79
|
|
|
def testDescribeMismatch(self): |
80
|
|
|
self.assert_describe_mismatch( |
81
|
|
|
"was 'ugly'", |
82
|
|
|
any_of(equal_to('bad'), equal_to('good')), |
83
|
|
|
'ugly') |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
if __name__ == '__main__': |
87
|
|
|
unittest.main() |
88
|
|
|
|