summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/backunittest.py7
-rw-r--r--test/test_api.py8
-rw-r--r--test/test_summary.py4
-rw-r--r--test/test_testing.py10
4 files changed, 20 insertions, 9 deletions
diff --git a/test/backunittest.py b/test/backunittest.py
index 84a7f36e..3723dea4 100644
--- a/test/backunittest.py
+++ b/test/backunittest.py
@@ -36,6 +36,13 @@ class TestCase(unittest.TestCase):
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('assertRaisesRegexp'):
def assertRaisesRegexp(self, excClass, regexp, callobj, *args, **kw):
""" Just like unittest.TestCase.assertRaises,
diff --git a/test/test_api.py b/test/test_api.py
index aa0e726b..bbea8e62 100644
--- a/test/test_api.py
+++ b/test/test_api.py
@@ -366,16 +366,12 @@ class OmitIncludeTestsMixin(UsingModulesMixin):
def filenames_in(self, summary, filenames):
"""Assert the `filenames` are in the keys of `summary`."""
for filename in filenames.split():
- self.assert_(filename in summary,
- "%s should be in %r" % (filename, summary)
- )
+ self.assertIn(filename, summary)
def filenames_not_in(self, summary, filenames):
"""Assert the `filenames` are not in the keys of `summary`."""
for filename in filenames.split():
- self.assert_(filename not in summary,
- "%s should not be in %r" % (filename, summary)
- )
+ self.assertNotIn(filename, summary)
def test_nothing_specified(self):
result = self.coverage_usepkgs()
diff --git a/test/test_summary.py b/test/test_summary.py
index fae91ba5..d2be95d9 100644
--- a/test/test_summary.py
+++ b/test/test_summary.py
@@ -208,8 +208,8 @@ class SummaryTest2(CoverageTest):
report = repout.getvalue().replace('\\', '/')
report = re.sub(r"\s+", " ", report)
- self.assert_("test/modules/pkg1/__init__ 1 0 100%" in report)
- self.assert_("test/modules/pkg2/__init__ 0 0 100%" in report)
+ self.assertIn("test/modules/pkg1/__init__ 1 0 100%", report)
+ self.assertIn("test/modules/pkg2/__init__ 0 0 100%", report)
class ReportingReturnValue(CoverageTest):
diff --git a/test/test_testing.py b/test/test_testing.py
index 67eb9456..d909021b 100644
--- a/test/test_testing.py
+++ b/test/test_testing.py
@@ -94,7 +94,7 @@ class TestingTest(TestCase):
self.assertFalse(False)
self.assertRaises(AssertionError, self.assertFalse, True)
- def test_assert_contains(self):
+ def test_assert_in(self):
self.assertIn("abc", "hello abc")
self.assertIn("abc", ["xyz", "abc", "foo"])
self.assertIn("abc", {'abc': 1, 'xyz': 2})
@@ -102,6 +102,14 @@ class TestingTest(TestCase):
self.assertRaises(AssertionError, self.assertIn, "abc", ["x", "xabc"])
self.assertRaises(AssertionError, self.assertIn, "abc", {'x':'abc'})
+ def test_assert_not_in(self):
+ self.assertRaises(AssertionError, self.assertNotIn, "abc", "hello abc")
+ self.assertRaises(AssertionError, self.assertNotIn, "abc", ["xyz", "abc", "foo"])
+ self.assertRaises(AssertionError, self.assertNotIn, "abc", {'abc': 1, 'xyz': 2})
+ self.assertNotIn("abc", "xyz")
+ self.assertNotIn("abc", ["x", "xabc"])
+ self.assertNotIn("abc", {'x':'abc'})
+
class CoverageTestTest(CoverageTest):
"""Test the methods in `CoverageTest`."""