summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2009-10-25 09:31:20 -0400
committerNed Batchelder <ned@nedbatchelder.com>2009-10-25 09:31:20 -0400
commit915d749f363b4753dc7f6857cf75d69d8b2ac674 (patch)
treed9fa03d65713771c23dcb99093cd16525cd7e2a6 /test
parent8a2daa7d674a52f20a911b3354faeb3ed1aa2ee7 (diff)
downloadpython-coveragepy-915d749f363b4753dc7f6857cf75d69d8b2ac674.tar.gz
Add an assert_matches method, and tests to prove it works.
Diffstat (limited to 'test')
-rw-r--r--test/coveragetest.py8
-rw-r--r--test/test_testing.py26
2 files changed, 33 insertions, 1 deletions
diff --git a/test/coveragetest.py b/test/coveragetest.py
index b1f4644..32da6e6 100644
--- a/test/coveragetest.py
+++ b/test/coveragetest.py
@@ -1,6 +1,6 @@
"""Base test case class for coverage testing."""
-import imp, os, random, shutil, sys, tempfile, textwrap, unittest
+import imp, os, random, re, shutil, sys, tempfile, textwrap, unittest
import coverage
from coverage.backward import set, sorted, StringIO # pylint: disable-msg=W0622
@@ -268,3 +268,9 @@ class CoverageTest(unittest.TestCase):
def assert_equal_sets(self, s1, s2):
"""Assert that the two arguments are equal as sets."""
self.assertEqual(set(s1), set(s2))
+
+ def assert_matches(self, s, regex):
+ """Assert that `s` matches `regex`."""
+ m = re.search(regex, s)
+ if not m:
+ raise self.failureException("%r doesn't match %r" % (s, regex))
diff --git a/test/test_testing.py b/test/test_testing.py
new file mode 100644
index 0000000..806f087
--- /dev/null
+++ b/test/test_testing.py
@@ -0,0 +1,26 @@
+"""Tests that our test infrastructure is really working!"""
+
+import os, sys
+sys.path.insert(0, os.path.split(__file__)[0]) # Force relative import for Py3k
+from coveragetest import CoverageTest
+
+class TestingTest(CoverageTest):
+ """Tests of helper methods on CoverageTest."""
+
+ def test_assert_equal_sets(self):
+ self.assert_equal_sets(set(), set())
+ self.assert_equal_sets(set([1,2,3]), set([3,1,2]))
+ self.assertRaises(AssertionError, self.assert_equal_sets,
+ set([1,2,3]), set()
+ )
+ self.assertRaises(AssertionError, self.assert_equal_sets,
+ set([1,2,3]), set([4,5,6])
+ )
+
+ def test_assert_matches(self):
+ self.assert_matches("hello", "hel*o")
+ self.assert_matches("Oh, hello there!", "hel*o")
+ self.assertRaises(AssertionError, self.assert_matches,
+ "hello there", "^hello$"
+ )
+