diff options
-rw-r--r-- | tests/coveragetest.py | 5 | ||||
-rw-r--r-- | tests/test_misc.py | 2 | ||||
-rw-r--r-- | tests/test_testing.py | 11 |
3 files changed, 17 insertions, 1 deletions
diff --git a/tests/coveragetest.py b/tests/coveragetest.py index d047a472..0467d808 100644 --- a/tests/coveragetest.py +++ b/tests/coveragetest.py @@ -422,6 +422,11 @@ class CoverageTest(TestCase): msg = "File %r shouldn't exist" % fname self.assert_(not os.path.exists(fname), msg) + def assert_starts_with(self, s, prefix, msg=None): + """Assert that `s` starts with `prefix`.""" + if not s.startswith(prefix): + self.fail(msg or ("%r doesn't start with %r" % (s, prefix))) + def command_line(self, args, ret=OK, _covpkg=None): """Run `args` through the command line. diff --git a/tests/test_misc.py b/tests/test_misc.py index 020b1425..4fcc0f6f 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -72,7 +72,7 @@ class SetupPyTest(CoverageTest): classifiers = setup_args['classifiers'] self.assertGreater(len(classifiers), 7) - self.assertTrue(classifiers[-1].startswith("Development Status ::")) + self.assert_starts_with(classifiers[-1], "Development Status ::") long_description = setup_args['long_description'].splitlines() self.assertGreater(len(long_description), 7) diff --git a/tests/test_testing.py b/tests/test_testing.py index 64dca617..6222db9a 100644 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -166,6 +166,17 @@ class CoverageTestTest(CoverageTest): ) self.assertRaises(AssertionError, self.assert_exists, "shadow.txt") + def test_assert_startwith(self): + self.assert_starts_with("xyzzy", "xy") + self.assert_starts_with("xyz\nabc", "xy") + self.assert_starts_with("xyzzy", ("x", "z")) + self.assertRaises( + AssertionError, self.assert_starts_with, "xyz", "a" + ) + self.assertRaises( + AssertionError, self.assert_starts_with, "xyz\nabc", "a" + ) + def test_sub_python_is_this_python(self): # Try it with a python command. os.environ['COV_FOOBAR'] = 'XYZZY' |