diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2015-07-18 15:19:16 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-07-18 15:19:16 -0400 |
commit | b974729cedc7c967be07314fc4a20815575cc618 (patch) | |
tree | a3b9385d6973f217abc022ffdcbe134c4f41b3bc | |
parent | 2283cfd510d36068845ad085d78b77e4c01a228a (diff) | |
download | python-coveragepy-git-b974729cedc7c967be07314fc4a20815575cc618.tar.gz |
Add test of the debug output when reading/writing data
-rw-r--r-- | tests/coveragetest.py | 12 | ||||
-rw-r--r-- | tests/test_data.py | 34 |
2 files changed, 44 insertions, 2 deletions
diff --git a/tests/coveragetest.py b/tests/coveragetest.py index 2f488616..a8535418 100644 --- a/tests/coveragetest.py +++ b/tests/coveragetest.py @@ -12,7 +12,7 @@ import sys import coverage from coverage.backunittest import TestCase from coverage.backward import StringIO, import_local_file, string_class -from coverage.debug import _TEST_NAME_FILE +from coverage.debug import _TEST_NAME_FILE, DebugControl from coverage.test_helpers import ( EnvironmentAwareMixin, StdStreamCapturingMixin, TempDirMixin, ) @@ -373,3 +373,13 @@ class CoverageTest( def last_line_squeezed(self, report): """Return the last line of `report` with the spaces squeezed down.""" return self.squeezed_lines(report)[-1] + + +class DebugControlString(DebugControl): + """A `DebugControl` that writes to a StringIO, for testing.""" + def __init__(self, options): + super(DebugControlString, self).__init__(options, StringIO()) + + def get_output(self): + """Get the output text from the `DebugControl`.""" + return self.output.getvalue() diff --git a/tests/test_data.py b/tests/test_data.py index 4acfd63e..9d909705 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -7,7 +7,7 @@ from coverage.backward import pickle from coverage.data import CoverageData, CoverageDataFiles from coverage.files import PathAliases, canonical_filename -from tests.coveragetest import CoverageTest +from tests.coveragetest import CoverageTest, DebugControlString DATA_1 = { @@ -128,6 +128,38 @@ class DataFilesTest(DataTestHelpers, CoverageTest): self.data_files.read(covdata2) self.assert_line_counts(covdata2, SUMMARY_1) + def test_debug_output_with_debug_option(self): + # With debug option dataio, we get debug output about reading and + # writing files. + debug = DebugControlString(options=["dataio"]) + covdata1 = CoverageData(debug=debug) + covdata1.add_lines(DATA_1) + self.data_files.write(covdata1) + + covdata2 = CoverageData(debug=debug) + self.data_files.read(covdata2) + self.assert_line_counts(covdata2, SUMMARY_1) + + self.assertRegex( + debug.get_output(), + r"^Writing data to '.*\.coverage'\n" + r"Reading data from '.*\.coverage'\n$" + ) + + def test_debug_output_without_debug_option(self): + # With a debug object, but not the dataio option, we don't get debug + # output. + debug = DebugControlString(options=[]) + covdata1 = CoverageData(debug=debug) + covdata1.add_lines(DATA_1) + self.data_files.write(covdata1) + + covdata2 = CoverageData(debug=debug) + self.data_files.read(covdata2) + self.assert_line_counts(covdata2, SUMMARY_1) + + self.assertEqual(debug.get_output(), "") + def test_combining(self): covdata1 = CoverageData() covdata1.add_lines(DATA_1) |