diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/coveragetest.py | 8 | ||||
| -rw-r--r-- | tests/test_api.py | 3 | ||||
| -rw-r--r-- | tests/test_data.py | 2 | ||||
| -rw-r--r-- | tests/test_testing.py | 17 | 
4 files changed, 29 insertions, 1 deletions
diff --git a/tests/coveragetest.py b/tests/coveragetest.py index caddbeed..94f50852 100644 --- a/tests/coveragetest.py +++ b/tests/coveragetest.py @@ -6,6 +6,7 @@  import contextlib  import datetime  import functools +import glob  import os  import random  import re @@ -347,6 +348,13 @@ class CoverageTest(          msg = "File %r shouldn't exist" % fname          self.assertTrue(not os.path.exists(fname), msg) +    def assert_file_count(self, pattern, count): +        """Assert that there are `count` files matching `pattern`.""" +        files = glob.glob(pattern) +        msg = "There should be {} files matching {!r}, but there are these: {}" +        msg = msg.format(count, pattern, files) +        self.assertEqual(len(files), count, msg) +      def assert_starts_with(self, s, prefix, msg=None):          """Assert that `s` starts with `prefix`."""          if not s.startswith(prefix): diff --git a/tests/test_api.py b/tests/test_api.py index 248784ff..d0b8efe9 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -357,6 +357,7 @@ class ApiTest(CoverageTest):          cov = coverage.Coverage(data_suffix=True)          self.start_import_stop(cov, "code2")          cov.save() +        self.assert_file_count(".coverage.*", 2)      def make_bad_data_file(self):          """Make one bad data file.""" @@ -387,6 +388,8 @@ class ApiTest(CoverageTest):          cov1.combine()          cov1.save()          self.check_code1_code2(cov1) +        self.assert_file_count(".coverage.*", 0) +        self.assert_exists(".coverage")          cov2 = coverage.Coverage()          with self.assertRaisesRegex(CoverageException, r"No data to combine"): diff --git a/tests/test_data.py b/tests/test_data.py index 0d3172d4..5e7b7fc4 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -582,7 +582,7 @@ class CoverageDataFilesTest(DataTestHelpers, CoverageTest):          self.assert_doesnt_exist(".coverage")      def test_true_suffix(self): -        self.assertEqual(glob.glob(".coverage.*"), []) +        self.assert_file_count(".coverage.*", 0)          # suffix=True will make a randomly named data file.          covdata1 = CoverageData() diff --git a/tests/test_testing.py b/tests/test_testing.py index d8cd0ef0..2b01584e 100644 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -51,6 +51,23 @@ class CoverageTestTest(CoverageTest):          with self.assertRaises(AssertionError):              self.assert_exists("shadow.txt") +    def test_file_count(self): +        self.make_file("abcde.txt", "abcde") +        self.make_file("axczz.txt", "axczz") +        self.make_file("afile.txt", "afile") +        self.assert_file_count("a*.txt", 3) +        self.assert_file_count("*c*.txt", 2) +        self.assert_file_count("afile.*", 1) +        self.assert_file_count("*.q", 0) +        with self.assertRaises(AssertionError): +            self.assert_file_count("a*.txt", 13) +        with self.assertRaises(AssertionError): +            self.assert_file_count("*c*.txt", 12) +        with self.assertRaises(AssertionError): +            self.assert_file_count("afile.*", 11) +        with self.assertRaises(AssertionError): +            self.assert_file_count("*.q", 10) +      def test_assert_startwith(self):          self.assert_starts_with("xyzzy", "xy")          self.assert_starts_with("xyz\nabc", "xy")  | 
