1
|
|
|
import six |
2
|
|
|
|
3
|
|
|
from hamcrest.library.text.stringendswith import * |
4
|
|
|
|
5
|
|
|
from hamcrest_unit_test.matcher_test import MatcherTest |
6
|
|
|
import unittest |
7
|
|
|
|
8
|
|
|
__author__ = "Jon Reid" |
9
|
|
|
__copyright__ = "Copyright 2011 hamcrest.org" |
10
|
|
|
__license__ = "BSD, see License.txt" |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
EXCERPT = 'EXCERPT' |
14
|
|
|
matcher = ends_with(EXCERPT) |
15
|
|
|
|
16
|
|
View Code Duplication |
class StringEndsWithTest(MatcherTest): |
|
|
|
|
17
|
|
|
|
18
|
|
|
def testEvaluatesToTrueIfArgumentContainsSpecifiedSubstring(self): |
19
|
|
|
self.assert_does_not_match('excerpt at beginning', |
20
|
|
|
matcher, EXCERPT + 'END') |
21
|
|
|
self.assert_matches('excerpt at end', matcher, 'START' + EXCERPT) |
22
|
|
|
self.assert_does_not_match('excerpt in middle', |
23
|
|
|
matcher, 'START' + EXCERPT + 'END') |
24
|
|
|
self.assert_matches('excerpt repeated', matcher, EXCERPT + EXCERPT) |
25
|
|
|
|
26
|
|
|
self.assert_does_not_match('excerpt not in string', |
27
|
|
|
matcher, 'whatever') |
28
|
|
|
self.assert_does_not_match('only part of excerpt is at end of string', |
29
|
|
|
matcher, EXCERPT[1:]) |
30
|
|
|
|
31
|
|
|
def testEvaluatesToTrueIfArgumentIsEqualToSubstring(self): |
32
|
|
|
self.assert_matches('excerpt is entire string', matcher, EXCERPT) |
33
|
|
|
|
34
|
|
|
def testMatcherCreationRequiresString(self): |
35
|
|
|
self.assertRaises(TypeError, ends_with, 3) |
36
|
|
|
|
37
|
|
|
def testFailsIfMatchingAgainstNonString(self): |
38
|
|
|
self.assert_does_not_match('non-string', matcher, object()) |
39
|
|
|
|
40
|
|
|
def testCanApplyUnicodeStringToUnicodeMatcher(self): |
41
|
|
|
self.assert_matches('unicode-unicode', |
42
|
|
|
ends_with(six.u('baz')), six.u('foo bar baz')) |
43
|
|
|
|
44
|
|
|
def testCanApplyPlainStringToUnicodeMatcher(self): |
45
|
|
|
self.assert_matches('unicode-ascii', |
46
|
|
|
ends_with(six.u('baz')), 'foo bar baz') |
47
|
|
|
|
48
|
|
|
def testCanApplyUnicodeStringToPlainMatcher(self): |
49
|
|
|
self.assert_matches('ascii-unicode', |
50
|
|
|
ends_with(six.u('baz')), six.u('foo bar baz')) |
51
|
|
|
|
52
|
|
|
def testHasAReadableDescription(self): |
53
|
|
|
self.assert_description("a string ending with 'EXCERPT'", matcher) |
54
|
|
|
|
55
|
|
|
def testSuccessfulMatchDoesNotGenerateMismatchDescription(self): |
56
|
|
|
self.assert_no_mismatch_description(matcher, EXCERPT) |
57
|
|
|
|
58
|
|
|
def testMismatchDescription(self): |
59
|
|
|
self.assert_mismatch_description("was 'bad'", matcher, 'bad') |
60
|
|
|
|
61
|
|
|
def testDescribeMismatch(self): |
62
|
|
|
self.assert_describe_mismatch("was 'bad'", matcher, 'bad') |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
if __name__ == '__main__': |
66
|
|
|
unittest.main() |
67
|
|
|
|