diff options
Diffstat (limited to 'test/backunittest.py')
-rw-r--r-- | test/backunittest.py | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/test/backunittest.py b/test/backunittest.py index f606185f..30da78eb 100644 --- a/test/backunittest.py +++ b/test/backunittest.py @@ -2,7 +2,7 @@ import difflib, re, sys, unittest -from coverage.backward import set # pylint: disable-msg=W0622 +from coverage.backward import set # pylint: disable=W0622 def _need(method): @@ -29,6 +29,27 @@ class TestCase(unittest.TestCase): if exp: self.fail(msg) + if _need('assertIn'): + def assertIn(self, member, container, msg=None): + """Assert that `member` is in `container`.""" + if member not in container: + msg = msg or ('%r not found in %r' % (member, container)) + self.fail(msg) + + if _need('assertNotIn'): + def assertNotIn(self, member, container, msg=None): + """Assert that `member` is not in `container`.""" + if member in container: + msg = msg or ('%r found in %r' % (member, container)) + self.fail(msg) + + if _need('assertGreater'): + def assertGreater(self, a, b, msg=None): + """Assert that `a` is greater than `b`.""" + if not a > b: + msg = msg or ('%r not greater than %r' % (a, b)) + self.fail(msg) + if _need('assertRaisesRegexp'): def assertRaisesRegexp(self, excClass, regexp, callobj, *args, **kw): """ Just like unittest.TestCase.assertRaises, @@ -46,7 +67,7 @@ class TestCase(unittest.TestCase): # Message provided, and it didn't match: fail! raise self.failureException( "Right exception, wrong message: " - "'%s' doesn't match '%s'" % (excMsg, regexp) + "%r doesn't match %r" % (excMsg, regexp) ) # No need to catch other exceptions: They'll fail the test all by # themselves! @@ -66,11 +87,12 @@ class TestCase(unittest.TestCase): self.assertEqual(set(s1), set(s2)) if _need('assertRegexpMatches'): - def assertRegexpMatches(self, s, regex): - """Assert that `s` matches `regex`.""" - m = re.search(regex, s) + def assertRegexpMatches(self, text, regex, msg=None): + """Assert that `text` matches `regex`.""" + m = re.search(regex, text) if not m: - raise self.failureException("%r doesn't match %r" % (s, regex)) + msg = msg or ("%r doesn't match %r" % (text, regex)) + raise self.failureException(msg) if _need('assertMultiLineEqual'): def assertMultiLineEqual(self, first, second, msg=None): |