Exemple #1
0
class StartsWith(MatcherTestCase):
    def test_exact(self):
        self.assert_match('', '')
        self.assert_match(' ', ' ')
        self.assert_match('foo', 'foo')

    def test_prefix(self):
        self.assert_match('foo', '')  # empty string is a prefix of everything
        self.assert_match('foo', 'f')
        self.assert_match('foo', 'fo')
        self.assert_match(' foo', ' ')

    def test_no_match(self):
        self.assert_no_match('foo', 'b')
        self.assert_no_match(' foo', 'f')
        self.assert_no_match('', 'foo')

    @skipIf(IS_PY3, "requires Python 2.x")
    def test_unicode(self):
        self.assert_match(u'', u'')
        self.assert_match(u' ', u' ')
        self.assert_match(u'foo', u'foo')
        self.assert_match(u'foo', u'')
        self.assert_match(u'foo', u'f')
        self.assert_match(u'foo', u'fo')
        self.assert_match(u' foo', u' ')
        self.assert_no_match(u' foo', u'f')
        self.assert_no_match(u'foo', u'b')
        self.assert_no_match(u'', u'foo')

    test_repr = lambda self: self.assert_repr(__unit__.StartsWith(''))

    # Assertion functions

    def assert_match(self, value, prefix):
        return super(StartsWith, self) \
            .assert_match(__unit__.StartsWith(prefix), value)

    def assert_no_match(self, value, prefix):
        return super(StartsWith, self) \
            .assert_no_match(__unit__.StartsWith(prefix), value)
Exemple #2
0
 def assert_no_match(self, value, prefix):
     return super(StartsWith, self) \
         .assert_no_match(__unit__.StartsWith(prefix), value)