diff options
Diffstat (limited to 'tests/test_summary.py')
-rw-r--r-- | tests/test_summary.py | 59 |
1 files changed, 45 insertions, 14 deletions
diff --git a/tests/test_summary.py b/tests/test_summary.py index bda65681..7c9f4c12 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -1,4 +1,4 @@ -# coding: utf8 +# coding: utf-8 # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 # For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt @@ -361,6 +361,27 @@ class SummaryTest(CoverageTest): squeezed = self.squeezed_lines(report) self.assertEqual(squeezed[3], "1 file skipped due to complete coverage.") + def test_report_skip_covered_longfilename(self): + self.make_file("long_______________filename.py", """ + def foo(): + pass + foo() + """) + out = self.run_command("coverage run --branch long_______________filename.py") + self.assertEqual(out, "") + report = self.report_from_command("coverage report --skip-covered") + + # Name Stmts Miss Branch BrPart Cover + # ----------------------------------------- + # + # 1 file skipped due to complete coverage. + + self.assertEqual(self.line_count(report), 4, report) + lines = self.report_lines(report) + self.assertEqual(lines[0], "Name Stmts Miss Branch BrPart Cover") + squeezed = self.squeezed_lines(report) + self.assertEqual(squeezed[3], "1 file skipped due to complete coverage.") + def test_report_skip_covered_no_data(self): report = self.report_from_command("coverage report --skip-covered") @@ -381,22 +402,25 @@ class SummaryTest(CoverageTest): self.make_file("mycode.py", "This isn't python at all!") report = self.report_from_command("coverage report mycode.py") + # mycode NotPython: Couldn't parse '...' as Python source: 'invalid syntax' at line 1 # Name Stmts Miss Cover # ---------------------------- - # mycode NotPython: Couldn't parse '...' as Python source: 'invalid syntax' at line 1 # No data to report. - last = self.squeezed_lines(report)[-2] + errmsg = self.squeezed_lines(report)[0] # The actual file name varies run to run. - last = re.sub(r"parse '.*mycode.py", "parse 'mycode.py", last) + errmsg = re.sub(r"parse '.*mycode.py", "parse 'mycode.py", errmsg) # The actual error message varies version to version - last = re.sub(r": '.*' at", ": 'error' at", last) + errmsg = re.sub(r": '.*' at", ": 'error' at", errmsg) self.assertEqual( - last, + errmsg, "mycode.py NotPython: Couldn't parse 'mycode.py' as Python source: 'error' at line 1" ) def test_accenteddotpy_not_python(self): + if env.JYTHON: + self.skipTest("Jython doesn't like accented file names") + # We run a .py file with a non-ascii name, and when reporting, we can't # parse it as Python. We should get an error message in the report. @@ -405,24 +429,23 @@ class SummaryTest(CoverageTest): self.make_file(u"accented\xe2.py", "This isn't python at all!") report = self.report_from_command(u"coverage report accented\xe2.py") + # xxxx NotPython: Couldn't parse '...' as Python source: 'invalid syntax' at line 1 # Name Stmts Miss Cover # ---------------------------- - # xxxx NotPython: Couldn't parse '...' as Python source: 'invalid syntax' at line 1 # No data to report. - last = self.squeezed_lines(report)[-2] + errmsg = self.squeezed_lines(report)[0] # The actual file name varies run to run. - last = re.sub(r"parse '.*(accented.*?\.py)", r"parse '\1", last) + errmsg = re.sub(r"parse '.*(accented.*?\.py)", r"parse '\1", errmsg) # The actual error message varies version to version - last = re.sub(r": '.*' at", ": 'error' at", last) + errmsg = re.sub(r": '.*' at", ": 'error' at", errmsg) expected = ( u"accented\xe2.py NotPython: " u"Couldn't parse 'accented\xe2.py' as Python source: 'error' at line 1" ) if env.PY2: - # pylint: disable=redefined-variable-type expected = expected.encode(output_encoding()) - self.assertEqual(last, expected) + self.assertEqual(errmsg, expected) def test_dotpy_not_python_ignored(self): # We run a .py file, and when reporting, we can't parse it as Python, @@ -564,7 +587,7 @@ class SummaryTest(CoverageTest): # Python 3 puts the .pyc files in a __pycache__ directory, and will # not import from there without source. It will import a .pyc from # the source location though. - if not os.path.exists("mod.pyc"): + if env.PY3 and not env.JYTHON: pycs = glob.glob("__pycache__/mod.*.pyc") self.assertEqual(len(pycs), 1) os.rename(pycs[0], "mod.pyc") @@ -656,7 +679,7 @@ class TestSummaryReporterConfiguration(CoverageTest): HERE = os.path.dirname(__file__) LINES_1 = { - os.path.join(HERE, "test_api.py"): dict.fromkeys(range(300)), + os.path.join(HERE, "test_api.py"): dict.fromkeys(range(400)), os.path.join(HERE, "test_backward.py"): dict.fromkeys(range(20)), os.path.join(HERE, "test_coverage.py"): dict.fromkeys(range(15)), } @@ -738,6 +761,14 @@ class TestSummaryReporterConfiguration(CoverageTest): report = self.get_summary_text(data, opts) self.assert_ordering(report, "test_backward.py", "test_coverage.py", "test_api.py") + def test_sort_report_by_missing(self): + # Sort the text report by the Missing column. + data = self.get_coverage_data(self.LINES_1) + opts = CoverageConfig() + opts.from_args(sort='Miss') + report = self.get_summary_text(data, opts) + self.assert_ordering(report, "test_backward.py", "test_api.py", "test_coverage.py") + def test_sort_report_by_cover(self): # Sort the text report by the Cover column. data = self.get_coverage_data(self.LINES_1) |