diff options
-rw-r--r-- | test/coveragetest.py | 8 | ||||
-rw-r--r-- | test/test_testing.py | 19 |
2 files changed, 26 insertions, 1 deletions
diff --git a/test/coveragetest.py b/test/coveragetest.py index 8e15e49d..981beeea 100644 --- a/test/coveragetest.py +++ b/test/coveragetest.py @@ -116,13 +116,19 @@ class CoverageTest(TestCase): def make_file(self, filename, text): """Create a temp file. - `filename` is the file name, and `text` is the content. + `filename` is the path to the file, including directories if desired, + and `text` is the content. """ # Tests that call `make_file` should be run in a temp environment. assert self.run_in_temp_dir text = textwrap.dedent(text) + # Make sure the directories are available. + dirs, _ = os.path.split(filename) + if dirs and not os.path.exists(dirs): + os.makedirs(dirs) + # Create the file. f = open(filename, 'w') f.write(text) diff --git a/test/test_testing.py b/test/test_testing.py index 5a72c550..58b6dc82 100644 --- a/test/test_testing.py +++ b/test/test_testing.py @@ -3,6 +3,7 @@ import os, sys sys.path.insert(0, os.path.split(__file__)[0]) # Force relative import for Py3k from backunittest import TestCase +from coveragetest import CoverageTest from coverage.backward import set # pylint: disable-msg=W0622 @@ -84,3 +85,21 @@ class TestingTest(TestCase): def test_assert_false(self): self.assertFalse(False) self.assertRaises(AssertionError, self.assertFalse, True) + + +class CoverageTestTest(CoverageTest): + """Test the methods in `CoverageTest`.""" + + def test_make_file(self): + # A simple file. + self.make_file("fooey.boo", "Hello there") + self.assertEqual(open("fooey.boo").read(), "Hello there") + # A file in a sub-directory + self.make_file("sub/another.txt", "Another") + self.assertEqual(open("sub/another.txt").read(), "Another") + # A second file in that sub-directory + self.make_file("sub/second.txt", "Second") + self.assertEqual(open("sub/second.txt").read(), "Second") + # A deeper directory + self.make_file("sub/deeper/evenmore/third.txt", "Third") + self.assertEqual(open("sub/deeper/evenmore/third.txt").read(), "Third") |