summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/coveragetest.py10
-rw-r--r--test/test_coverage.py4
-rw-r--r--test/test_process.py26
-rw-r--r--test/test_testing.py9
4 files changed, 34 insertions, 15 deletions
diff --git a/test/coveragetest.py b/test/coveragetest.py
index 8c05f32f..621d7ae2 100644
--- a/test/coveragetest.py
+++ b/test/coveragetest.py
@@ -340,6 +340,16 @@ class CoverageTest(TestCase):
flist2_nice = [self.nice_file(f) for f in flist2]
self.assertSameElements(flist1_nice, flist2_nice)
+ def assert_exists(self, fname):
+ """Assert that `fname` is a file that exists."""
+ msg = "File %r should exist" % fname
+ self.assert_(os.path.exists(fname), msg)
+
+ def assert_doesnt_exist(self, fname):
+ """Assert that `fname` is a file that doesn't exist."""
+ msg = "File %r shouldn't exist" % fname
+ self.assert_(not os.path.exists(fname), msg)
+
def command_line(self, args, ret=OK, _covpkg=None):
"""Run `args` through the command line.
diff --git a/test/test_coverage.py b/test/test_coverage.py
index 4d3c37f5..fe81da76 100644
--- a/test/test_coverage.py
+++ b/test/test_coverage.py
@@ -1704,7 +1704,7 @@ class ReportingTest(CoverageTest):
CoverageException, "No data to report.",
self.command_line, "annotate -d ann"
)
- self.assertFalse(os.path.exists("ann"))
+ self.assert_doesnt_exist("ann")
def test_no_data_to_report_on_html(self):
# Reporting with no data produces a nice message and no output dir.
@@ -1712,7 +1712,7 @@ class ReportingTest(CoverageTest):
CoverageException, "No data to report.",
self.command_line, "html -d htmlcov"
)
- self.assertFalse(os.path.exists("htmlcov"))
+ self.assert_doesnt_exist("htmlcov")
def test_no_data_to_report_on_xml(self):
# Reporting with no data produces a nice message.
diff --git a/test/test_process.py b/test/test_process.py
index 917abc70..47f3a088 100644
--- a/test/test_process.py
+++ b/test/test_process.py
@@ -24,9 +24,9 @@ class ProcessTest(CoverageTest):
w = "world"
""")
- self.assertFalse(os.path.exists(".coverage"))
+ self.assert_doesnt_exist(".coverage")
self.run_command("coverage -x mycode.py")
- self.assertTrue(os.path.exists(".coverage"))
+ self.assert_exists(".coverage")
def test_environment(self):
# Checks that we can import modules from the test directory at all!
@@ -37,9 +37,9 @@ class ProcessTest(CoverageTest):
print ('done')
""")
- self.assertFalse(os.path.exists(".coverage"))
+ self.assert_doesnt_exist(".coverage")
out = self.run_command("coverage -x mycode.py")
- self.assertTrue(os.path.exists(".coverage"))
+ self.assert_exists(".coverage")
self.assertEqual(out, 'done\n')
def test_combine_parallel_data(self):
@@ -56,18 +56,18 @@ class ProcessTest(CoverageTest):
out = self.run_command("coverage -x -p b_or_c.py b")
self.assertEqual(out, 'done\n')
- self.assertFalse(os.path.exists(".coverage"))
+ self.assert_doesnt_exist(".coverage")
out = self.run_command("coverage -x -p b_or_c.py c")
self.assertEqual(out, 'done\n')
- self.assertFalse(os.path.exists(".coverage"))
+ self.assert_doesnt_exist(".coverage")
# After two -p runs, there should be two .coverage.machine.123 files.
self.assertEqual(self.number_of_data_files(), 2)
# Combine the parallel coverage data files into .coverage .
self.run_command("coverage -c")
- self.assertTrue(os.path.exists(".coverage"))
+ self.assert_exists(".coverage")
# After combining, there should be only the .coverage file.
self.assertEqual(self.number_of_data_files(), 1)
@@ -97,19 +97,19 @@ class ProcessTest(CoverageTest):
out = self.run_command("coverage run b_or_c.py b")
self.assertEqual(out, 'done\n')
- self.assertFalse(os.path.exists(".coverage"))
+ self.assert_doesnt_exist(".coverage")
out = self.run_command("coverage run b_or_c.py c")
self.assertEqual(out, 'done\n')
- self.assertFalse(os.path.exists(".coverage"))
+ self.assert_doesnt_exist(".coverage")
# After two runs, there should be two .coverage.machine.123 files.
self.assertEqual(self.number_of_data_files(), 2)
# Combine the parallel coverage data files into .coverage .
self.run_command("coverage combine")
- self.assertTrue(os.path.exists(".coverage"))
- self.assertTrue(os.path.exists(".coveragerc"))
+ self.assert_exists(".coverage")
+ self.assert_exists(".coveragerc")
# After combining, there should be only the .coverage file.
self.assertEqual(self.number_of_data_files(), 1)
@@ -242,7 +242,7 @@ class ProcessTest(CoverageTest):
out = self.run_command("coverage run -p fork.py")
self.assertEqual(out, 'Child!\n')
- self.assertFalse(os.path.exists(".coverage"))
+ self.assert_doesnt_exist(".coverage")
# After running the forking program, there should be two
# .coverage.machine.123 files.
@@ -250,7 +250,7 @@ class ProcessTest(CoverageTest):
# Combine the parallel coverage data files into .coverage .
self.run_command("coverage -c")
- self.assertTrue(os.path.exists(".coverage"))
+ self.assert_exists(".coverage")
# After combining, there should be only the .coverage file.
self.assertEqual(self.number_of_data_files(), 1)
diff --git a/test/test_testing.py b/test/test_testing.py
index 2461a08e..bcf7d281 100644
--- a/test/test_testing.py
+++ b/test/test_testing.py
@@ -121,3 +121,12 @@ class CoverageTestTest(CoverageTest):
self.assertEqual(self.file_text("dos.txt"), "Hello\r\n")
self.make_file("mac.txt", "Hello\n", newline="\r")
self.assertEqual(self.file_text("mac.txt"), "Hello\r")
+
+ def test_file_exists(self):
+ self.make_file("whoville.txt", "We are here!")
+ self.assert_exists("whoville.txt")
+ self.assert_doesnt_exist("shadow.txt")
+ self.assertRaises(AssertionError, self.assert_doesnt_exist,
+ "whoville.txt")
+ self.assertRaises(AssertionError, self.assert_exists, "shadow.txt")
+