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