From 7d71b1e052b2adead8c43bbc320582eab4938221 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 15 Jul 2018 16:26:48 -0400 Subject: Make file operations implicit on constructed filename --- tests/test_process.py | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'tests/test_process.py') diff --git a/tests/test_process.py b/tests/test_process.py index e022e727..341ad37c 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -98,7 +98,7 @@ class ProcessTest(CoverageTest): # Read the coverage file and see that b_or_c.py has all 8 lines # executed. data = coverage.CoverageData() - data.read_file(".coverage") + data.read() self.assertEqual(data.line_counts()['b_or_c.py'], 8) # Running combine again should fail, because there are no parallel data @@ -109,7 +109,7 @@ class ProcessTest(CoverageTest): # And the originally combined data is still there. data = coverage.CoverageData() - data.read_file(".coverage") + data.read() self.assertEqual(data.line_counts()['b_or_c.py'], 8) def test_combine_parallel_data_with_a_corrupt_file(self): @@ -145,7 +145,7 @@ class ProcessTest(CoverageTest): # Read the coverage file and see that b_or_c.py has all 8 lines # executed. data = coverage.CoverageData() - data.read_file(".coverage") + data.read() self.assertEqual(data.line_counts()['b_or_c.py'], 8) def test_combine_no_usable_files(self): @@ -179,7 +179,7 @@ class ProcessTest(CoverageTest): # Read the coverage file and see that b_or_c.py has 6 lines # executed (we only did b, not c). data = coverage.CoverageData() - data.read_file(".coverage") + data.read() self.assertEqual(data.line_counts()['b_or_c.py'], 6) def test_combine_parallel_data_in_two_steps(self): @@ -210,7 +210,7 @@ class ProcessTest(CoverageTest): # Read the coverage file and see that b_or_c.py has all 8 lines # executed. data = coverage.CoverageData() - data.read_file(".coverage") + data.read() self.assertEqual(data.line_counts()['b_or_c.py'], 8) def test_combine_parallel_data_no_append(self): @@ -242,7 +242,7 @@ class ProcessTest(CoverageTest): # Read the coverage file and see that b_or_c.py has only 7 lines # because we didn't keep the data from running b. data = coverage.CoverageData() - data.read_file(".coverage") + data.read() self.assertEqual(data.line_counts()['b_or_c.py'], 7) def test_append_data(self): @@ -261,7 +261,7 @@ class ProcessTest(CoverageTest): # Read the coverage file and see that b_or_c.py has all 8 lines # executed. data = coverage.CoverageData() - data.read_file(".coverage") + data.read() self.assertEqual(data.line_counts()['b_or_c.py'], 8) def test_append_data_with_different_file(self): @@ -284,8 +284,8 @@ class ProcessTest(CoverageTest): # Read the coverage file and see that b_or_c.py has all 8 lines # executed. - data = coverage.CoverageData() - data.read_file(".mycovdata") + data = coverage.CoverageData(".mycovdata") + data.read() self.assertEqual(data.line_counts()['b_or_c.py'], 8) def test_append_can_create_a_data_file(self): @@ -299,7 +299,7 @@ class ProcessTest(CoverageTest): # Read the coverage file and see that b_or_c.py has only 6 lines # executed. data = coverage.CoverageData() - data.read_file(".coverage") + data.read() self.assertEqual(data.line_counts()['b_or_c.py'], 6) def test_combine_with_rc(self): @@ -332,7 +332,7 @@ class ProcessTest(CoverageTest): # Read the coverage file and see that b_or_c.py has all 8 lines # executed. data = coverage.CoverageData() - data.read_file(".coverage") + data.read() self.assertEqual(data.line_counts()['b_or_c.py'], 8) # Reporting should still work even with the .rc file @@ -386,7 +386,7 @@ class ProcessTest(CoverageTest): # Read the coverage data file and see that the two different x.py # files have been combined together. data = coverage.CoverageData() - data.read_file(".coverage") + data.read() summary = data.line_counts(fullpath=True) self.assertEqual(len(summary), 1) actual = os.path.normcase(os.path.abspath(list(summary.keys())[0])) @@ -549,7 +549,7 @@ class ProcessTest(CoverageTest): self.assertEqual(self.number_of_data_files(), 1) data = coverage.CoverageData() - data.read_file(".coverage") + data.read() self.assertEqual(data.line_counts()['fork.py'], 9) def test_warnings_during_reporting(self): @@ -655,8 +655,8 @@ class ProcessTest(CoverageTest): self.make_file("simple.py", """print('hello')""") self.run_command("coverage run simple.py") - data = CoverageData() - data.read_file("mydata.dat") + data = CoverageData("mydata.dat") + data.read() infos = data.run_infos() self.assertEqual(len(infos), 1) expected = u"These are musical notes: ♫𝅗𝅥♩" @@ -686,7 +686,7 @@ class ProcessTest(CoverageTest): out = self.run_command("python -m coverage run -L getenv.py") self.assertEqual(out, "FOOEY == BOO\n") data = coverage.CoverageData() - data.read_file(".coverage") + data.read() # The actual number of executed lines in os.py when it's # imported is 120 or so. Just running os.getenv executes # about 5. @@ -916,7 +916,7 @@ class ExcepthookTest(CoverageTest): # Read the coverage file and see that excepthook.py has 7 lines # executed. data = coverage.CoverageData() - data.read_file(".coverage") + data.read() self.assertEqual(data.line_counts()['excepthook.py'], 7) def test_excepthook_exit(self): @@ -1245,9 +1245,9 @@ class ProcessStartupTest(ProcessCoverageMixin, CoverageTest): # An existing data file should not be read when a subprocess gets # measured automatically. Create the data file here with bogus data in # it. - data = coverage.CoverageData() + data = coverage.CoverageData(".mycovdata") data.add_lines({os.path.abspath('sub.py'): dict.fromkeys(range(100))}) - data.write_file(".mycovdata") + data.write() self.make_file("coverage.ini", """\ [run] @@ -1261,8 +1261,8 @@ class ProcessStartupTest(ProcessCoverageMixin, CoverageTest): # Read the data from .coverage self.assert_exists(".mycovdata") - data = coverage.CoverageData() - data.read_file(".mycovdata") + data = coverage.CoverageData(".mycovdata") + data.read() self.assertEqual(data.line_counts()['sub.py'], 3) def test_subprocess_with_pth_files_and_parallel(self): # pragma: no metacov @@ -1286,7 +1286,7 @@ class ProcessStartupTest(ProcessCoverageMixin, CoverageTest): # assert that the combined .coverage data file is correct self.assert_exists(".coverage") data = coverage.CoverageData() - data.read_file(".coverage") + data.read() self.assertEqual(data.line_counts()['sub.py'], 3) # assert that there are *no* extra data files left over after a combine @@ -1376,7 +1376,7 @@ class ProcessStartupWithSourceTest(ProcessCoverageMixin, CoverageTest): # Read the data from .coverage self.assert_exists(".coverage") data = coverage.CoverageData() - data.read_file(".coverage") + data.read() summary = data.line_counts() print(summary) self.assertEqual(summary[source + '.py'], 3) -- cgit v1.2.1 From 8562aeb29eddf3349f5c363c1842f9822b18a450 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Fri, 10 Aug 2018 16:39:22 -0400 Subject: Move line_counts out of the data classes --- tests/test_process.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'tests/test_process.py') diff --git a/tests/test_process.py b/tests/test_process.py index ede86691..48083f22 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -16,6 +16,7 @@ import pytest import coverage from coverage import env, CoverageData +from coverage.data import line_counts from coverage.misc import output_encoding from tests.coveragetest import CoverageTest @@ -91,7 +92,7 @@ class ProcessTest(CoverageTest): # executed. data = coverage.CoverageData() data.read() - self.assertEqual(data.line_counts()['b_or_c.py'], 8) + self.assertEqual(line_counts(data)['b_or_c.py'], 8) # Running combine again should fail, because there are no parallel data # files to combine. @@ -102,7 +103,7 @@ class ProcessTest(CoverageTest): # And the originally combined data is still there. data = coverage.CoverageData() data.read() - self.assertEqual(data.line_counts()['b_or_c.py'], 8) + self.assertEqual(line_counts(data)['b_or_c.py'], 8) def test_combine_parallel_data_with_a_corrupt_file(self): self.make_b_or_c_py() @@ -138,7 +139,7 @@ class ProcessTest(CoverageTest): # executed. data = coverage.CoverageData() data.read() - self.assertEqual(data.line_counts()['b_or_c.py'], 8) + self.assertEqual(line_counts(data)['b_or_c.py'], 8) def test_combine_no_usable_files(self): # https://bitbucket.org/ned/coveragepy/issues/629/multiple-use-of-combine-leads-to-empty @@ -173,7 +174,7 @@ class ProcessTest(CoverageTest): # executed (we only did b, not c). data = coverage.CoverageData() data.read() - self.assertEqual(data.line_counts()['b_or_c.py'], 6) + self.assertEqual(line_counts(data)['b_or_c.py'], 6) def test_combine_parallel_data_in_two_steps(self): self.make_b_or_c_py() @@ -204,7 +205,7 @@ class ProcessTest(CoverageTest): # executed. data = coverage.CoverageData() data.read() - self.assertEqual(data.line_counts()['b_or_c.py'], 8) + self.assertEqual(line_counts(data)['b_or_c.py'], 8) def test_combine_parallel_data_no_append(self): self.make_b_or_c_py() @@ -236,7 +237,7 @@ class ProcessTest(CoverageTest): # because we didn't keep the data from running b. data = coverage.CoverageData() data.read() - self.assertEqual(data.line_counts()['b_or_c.py'], 7) + self.assertEqual(line_counts(data)['b_or_c.py'], 7) def test_append_data(self): self.make_b_or_c_py() @@ -255,7 +256,7 @@ class ProcessTest(CoverageTest): # executed. data = coverage.CoverageData() data.read() - self.assertEqual(data.line_counts()['b_or_c.py'], 8) + self.assertEqual(line_counts(data)['b_or_c.py'], 8) def test_append_data_with_different_file(self): self.make_b_or_c_py() @@ -279,7 +280,7 @@ class ProcessTest(CoverageTest): # executed. data = coverage.CoverageData(".mycovdata") data.read() - self.assertEqual(data.line_counts()['b_or_c.py'], 8) + self.assertEqual(line_counts(data)['b_or_c.py'], 8) def test_append_can_create_a_data_file(self): self.make_b_or_c_py() @@ -293,7 +294,7 @@ class ProcessTest(CoverageTest): # executed. data = coverage.CoverageData() data.read() - self.assertEqual(data.line_counts()['b_or_c.py'], 6) + self.assertEqual(line_counts(data)['b_or_c.py'], 6) def test_combine_with_rc(self): self.make_b_or_c_py() @@ -326,7 +327,7 @@ class ProcessTest(CoverageTest): # executed. data = coverage.CoverageData() data.read() - self.assertEqual(data.line_counts()['b_or_c.py'], 8) + self.assertEqual(line_counts(data)['b_or_c.py'], 8) # Reporting should still work even with the .rc file out = self.run_command("coverage report") @@ -380,7 +381,7 @@ class ProcessTest(CoverageTest): # files have been combined together. data = coverage.CoverageData() data.read() - summary = data.line_counts(fullpath=True) + summary = line_counts(data, fullpath=True) self.assertEqual(len(summary), 1) actual = os.path.normcase(os.path.abspath(list(summary.keys())[0])) expected = os.path.normcase(os.path.abspath('src/x.py')) @@ -544,7 +545,7 @@ class ProcessTest(CoverageTest): data = coverage.CoverageData() data.read() - self.assertEqual(data.line_counts()['fork.py'], 9) + self.assertEqual(line_counts(data)['fork.py'], 9) def test_warnings_during_reporting(self): # While fixing issue #224, the warnings were being printed far too @@ -684,7 +685,7 @@ class ProcessTest(CoverageTest): # The actual number of executed lines in os.py when it's # imported is 120 or so. Just running os.getenv executes # about 5. - self.assertGreater(data.line_counts()['os.py'], 50) + self.assertGreater(line_counts(data)['os.py'], 50) def test_lang_c(self): if env.JYTHON: @@ -911,7 +912,7 @@ class ExcepthookTest(CoverageTest): # executed. data = coverage.CoverageData() data.read() - self.assertEqual(data.line_counts()['excepthook.py'], 7) + self.assertEqual(line_counts(data)['excepthook.py'], 7) def test_excepthook_exit(self): if env.PYPY or env.JYTHON: @@ -1257,7 +1258,7 @@ class ProcessStartupTest(ProcessCoverageMixin, CoverageTest): self.assert_exists(".mycovdata") data = coverage.CoverageData(".mycovdata") data.read() - self.assertEqual(data.line_counts()['sub.py'], 3) + self.assertEqual(line_counts(data)['sub.py'], 3) def test_subprocess_with_pth_files_and_parallel(self): # pragma: no metacov # https://bitbucket.org/ned/coveragepy/issues/492/subprocess-coverage-strange-detection-of @@ -1281,7 +1282,7 @@ class ProcessStartupTest(ProcessCoverageMixin, CoverageTest): self.assert_exists(".coverage") data = coverage.CoverageData() data.read() - self.assertEqual(data.line_counts()['sub.py'], 3) + self.assertEqual(line_counts(data)['sub.py'], 3) # assert that there are *no* extra data files left over after a combine data_files = glob.glob(os.getcwd() + '/.coverage*') @@ -1371,7 +1372,7 @@ class ProcessStartupWithSourceTest(ProcessCoverageMixin, CoverageTest): self.assert_exists(".coverage") data = coverage.CoverageData() data.read() - summary = data.line_counts() + summary = line_counts(data) print(summary) self.assertEqual(summary[source + '.py'], 3) self.assertEqual(len(summary), 1) -- cgit v1.2.1 From 9b13a1a7d44d991c4c5dd51d5624f5abe84b77f8 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Tue, 14 Aug 2018 20:39:31 -0400 Subject: Skip some tests for SQL for now --- tests/test_process.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/test_process.py') diff --git a/tests/test_process.py b/tests/test_process.py index 48083f22..7c705739 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -504,6 +504,8 @@ class ProcessTest(CoverageTest): def test_fork(self): if not hasattr(os, 'fork'): self.skipTest("Can't test os.fork since it doesn't exist.") + # See https://nedbatchelder.com/blog/201808/sqlite_data_storage_for_coveragepy.html + self.skip_unless_data_storage_is_json() self.make_file("fork.py", """\ import os @@ -642,6 +644,8 @@ class ProcessTest(CoverageTest): if env.PYPY and env.PY3 and env.PYPYVERSION[:3] == (5, 10, 0): # pragma: obscure # https://bitbucket.org/pypy/pypy/issues/2729/pypy3-510-incorrectly-decodes-astral-plane self.skipTest("Avoid incorrect decoding astral plane JSON chars") + self.skip_unless_data_storage_is_json() + self.make_file(".coveragerc", """\ [run] data_file = mydata.dat -- cgit v1.2.1 From 19ec83bde56b6dfecef4ddae275376fdb4262e3a Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Tue, 14 Aug 2018 20:39:57 -0400 Subject: Be flexible, and accept either json-sourced or sql-source error messages in some tests --- tests/test_process.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'tests/test_process.py') diff --git a/tests/test_process.py b/tests/test_process.py index 7c705739..49919b0f 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -127,8 +127,13 @@ class ProcessTest(CoverageTest): self.assert_exists(".coverage") self.assert_exists(".coverage.bad") warning_regex = ( + r"(" # JSON message: r"Coverage.py warning: Couldn't read data from '.*\.coverage\.bad': " r"CoverageException: Doesn't seem to be a coverage\.py data file" + r"|" # SQL message: + r"Coverage.py warning: Couldn't use data file '.*\.coverage\.bad': " + r"file is encrypted or is not a database" + r")" ) self.assertRegex(out, warning_regex) @@ -160,8 +165,14 @@ class ProcessTest(CoverageTest): for n in "12": self.assert_exists(".coverage.bad{0}".format(n)) warning_regex = ( + r"(" # JSON message: r"Coverage.py warning: Couldn't read data from '.*\.coverage\.bad{0}': " - r"CoverageException: Doesn't seem to be a coverage\.py data file".format(n) + r"CoverageException: Doesn't seem to be a coverage\.py data file" + r"|" # SQL message: + r"Coverage.py warning: Couldn't use data file '.*\.coverage.bad{0}': " + r"file is encrypted or is not a database" + r")" + .format(n) ) self.assertRegex(out, warning_regex) self.assertRegex(out, r"No usable data files") -- cgit v1.2.1