| @@ 17-83 (lines=67) @@ | ||
| 14 | __license__ = "BSD, see License.txt" | |
| 15 | ||
| 16 | ||
| 17 | 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__': | |
| @@ 17-78 (lines=62) @@ | ||
| 14 | __license__ = "BSD, see License.txt" | |
| 15 | ||
| 16 | ||
| 17 | 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__': | |