src/test.py: Implement assertIn for old Python versions.

This commit is contained in:
Valentin Lorentz 2013-01-05 21:16:30 +01:00
parent 2bcffdf523
commit 52e91d5f9c

View File

@ -115,6 +115,20 @@ class SupyTestCase(unittest.TestCase):
irc._reallyDie() irc._reallyDie()
if sys.version_info < (2, 7, 0): if sys.version_info < (2, 7, 0):
def assertIn(self, member, container, msg=None):
"""Just like self.assertTrue(a in b), but with a nicer default message."""
if member not in container:
standardMsg = '%s not found in %s' % (safe_repr(member),
safe_repr(container))
self.fail(self._formatMessage(msg, standardMsg))
def assertNotIn(self, member, container, msg=None):
"""Just like self.assertTrue(a not in b), but with a nicer default message."""
if member in container:
standardMsg = '%s unexpectedly found in %s' % (safe_repr(member),
safe_repr(container))
self.fail(self._formatMessage(msg, standardMsg))
def assertIs(self, expr1, expr2, msg=None): def assertIs(self, expr1, expr2, msg=None):
"""Just like self.assertTrue(a is b), but with a nicer default message.""" """Just like self.assertTrue(a is b), but with a nicer default message."""
if expr1 is not expr2: if expr1 is not expr2: