Commits

Ned Batchelder  committed a10ddd9

Add assert_starts_with

  • Participants
  • Parent commits f07e9c9

Comments (0)

Files changed (3)

File tests/coveragetest.py

         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.
 

File tests/test_misc.py

 
         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)

File tests/test_testing.py

             )
         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'