From 84b99d022bd2e65e7758fd3499f64de44c857cf0 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 18 May 2014 14:00:46 -0400 Subject: A test that the report command can use wildcards --- tests/test_summary.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/test_summary.py') diff --git a/tests/test_summary.py b/tests/test_summary.py index 29167bf8..2b655fff 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -72,6 +72,22 @@ class SummaryTest(CoverageTest): self.assertIn("mycode ", report) self.assertEqual(self.last_line_squeezed(report), "mycode 4 0 100%") + def test_report_wildcard(self): + # Try reporting using wildcards to get the modules. + self.run_command("coverage run mycode.py") + report = self.report_from_command("coverage report my*.py") + + # Name Stmts Miss Cover + # ---------------------------- + # mycode 4 0 100% + + self.assertEqual(self.line_count(report), 3) + self.assertNotIn("/coverage/", report) + self.assertNotIn("/tests/modules/covmod1 ", report) + self.assertNotIn("/tests/zipmods.zip/covmodzip1 ", report) + self.assertIn("mycode ", report) + self.assertEqual(self.last_line_squeezed(report), "mycode 4 0 100%") + def test_report_omitting(self): # Try reporting while omitting some modules prefix = os.path.split(__file__)[0] -- cgit v1.2.1 From ae924ecc7dd74205ff0555742a19092021c60701 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 18 May 2014 21:48:13 -0400 Subject: Switch some uses of old command line syntax to new --- tests/test_summary.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'tests/test_summary.py') diff --git a/tests/test_summary.py b/tests/test_summary.py index 2b655fff..79e32169 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -38,9 +38,9 @@ class SummaryTest(CoverageTest): return re.sub(r"\s+", " ", last_line) def test_report(self): - out = self.run_command("coverage -x mycode.py") + out = self.run_command("coverage run mycode.py") self.assertEqual(out, 'done\n') - report = self.report_from_command("coverage -r") + report = self.report_from_command("coverage report") # Name Stmts Miss Cover # --------------------------------------------------------------------- @@ -58,8 +58,8 @@ class SummaryTest(CoverageTest): def test_report_just_one(self): # Try reporting just one module - self.run_command("coverage -x mycode.py") - report = self.report_from_command("coverage -r mycode.py") + self.run_command("coverage run mycode.py") + report = self.report_from_command("coverage report mycode.py") # Name Stmts Miss Cover # ---------------------------- @@ -91,8 +91,8 @@ class SummaryTest(CoverageTest): def test_report_omitting(self): # Try reporting while omitting some modules prefix = os.path.split(__file__)[0] - self.run_command("coverage -x mycode.py") - report = self.report_from_command("coverage -r -o '%s/*'" % prefix) + self.run_command("coverage run mycode.py") + report = self.report_from_command("coverage report --omit '%s/*'" % prefix) # Name Stmts Miss Cover # ---------------------------- @@ -148,7 +148,7 @@ class SummaryTest(CoverageTest): self.run_command("coverage run mycode.py") self.make_file("mycode.py", "This isn't python at all!") - report = self.report_from_command("coverage -r mycode.py") + report = self.report_from_command("coverage report mycode.py") # pylint: disable=C0301 # Name Stmts Miss Cover @@ -171,7 +171,7 @@ class SummaryTest(CoverageTest): # but we've said to ignore errors, so there's no error reported. self.run_command("coverage run mycode.py") self.make_file("mycode.py", "This isn't python at all!") - report = self.report_from_command("coverage -r -i mycode.py") + report = self.report_from_command("coverage report -i mycode.py") # Name Stmts Miss Cover # ---------------------------- @@ -187,7 +187,7 @@ class SummaryTest(CoverageTest): self.run_command("coverage run mycode.html") # Before reporting, change it to be an HTML file. self.make_file("mycode.html", "

This isn't python at all!

") - report = self.report_from_command("coverage -r mycode.html") + report = self.report_from_command("coverage report mycode.html") # Name Stmts Miss Cover # ---------------------------- -- cgit v1.2.1 From 8cfec5d9e75dd95a313af08b7f0dcd27c3585371 Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 26 May 2014 13:26:02 -0400 Subject: Tests for --branch --show-missing summary; update AUTHORS.txt --- tests/test_summary.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'tests/test_summary.py') diff --git a/tests/test_summary.py b/tests/test_summary.py index 79e32169..61bdf37a 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -142,6 +142,55 @@ class SummaryTest(CoverageTest): self.assertEqual(self.last_line_squeezed(report), "mybranch 5 0 2 1 86%") + def test_report_show_missing(self): + self.make_file("mymissing.py", """\ + def missing(x, y): + if x: + print("x") + return x + if y: + print("y") + return x + return y + missing(0, 1) + """) + out = self.run_command("coverage run mymissing.py") + self.assertEqual(out, 'y\n') + report = self.report_from_command("coverage report --show-missing") + + # Name Stmts Miss Cover Missing + # ----------------------------------------- + # tests/tmp 9 3 67% 3-4, 8 + + self.assertEqual(self.line_count(report), 3) + self.assertIn("mymissing ", report) + self.assertEqual(self.last_line_squeezed(report), + "mymissing 9 3 67% 3-4, 8") + + def test_report_show_missing_branches(self): + self.make_file("mybranch.py", """\ + def branch(x, y): + if x: + print("x") + if y: + print("y") + return x + branch(1, 0) + """) + out = self.run_command("coverage run --branch mybranch.py") + self.assertEqual(out, 'x\n') + report = self.report_from_command("coverage report --show-missing") + + # pylint: disable=C0301 + # Name Stmts Miss Branch BrMiss Cover Missing + # ------------------------------------------------------- + # mybranch 7 1 4 2 73% 5, Branches: 2->4, 4->5 + + self.assertEqual(self.line_count(report), 3) + self.assertIn("mybranch ", report) + self.assertEqual(self.last_line_squeezed(report), + "mybranch 7 1 4 2 73% 5, Branches: 2->4, 4->5") + def test_dotpy_not_python(self): # We run a .py file, and when reporting, we can't parse it as Python. # We should get an error message in the report. -- cgit v1.2.1 From ad32797629dfe2fe18d7301203e7afb2fcaa15d7 Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 26 May 2014 13:42:02 -0400 Subject: Fix formatting when no missing lines; improve tests --- tests/test_summary.py | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'tests/test_summary.py') diff --git a/tests/test_summary.py b/tests/test_summary.py index 61bdf37a..7fd11a0e 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -160,7 +160,7 @@ class SummaryTest(CoverageTest): # Name Stmts Miss Cover Missing # ----------------------------------------- - # tests/tmp 9 3 67% 3-4, 8 + # mymissing 9 3 67% 3-4, 8 self.assertEqual(self.line_count(report), 3) self.assertIn("mymissing ", report) @@ -175,21 +175,48 @@ class SummaryTest(CoverageTest): if y: print("y") return x - branch(1, 0) + branch(1, 1) """) out = self.run_command("coverage run --branch mybranch.py") - self.assertEqual(out, 'x\n') + self.assertEqual(out, 'x\ny\n') + report = self.report_from_command("coverage report --show-missing") + + # Name Stmts Miss Branch BrMiss Cover Missing + # ------------------------------------------------------- + # tests/tmp 7 0 4 2 82% Branches: 2->4, 4->6 + + self.assertEqual(self.line_count(report), 3) + self.assertIn("mybranch ", report) + self.assertEqual(self.last_line_squeezed(report), + "mybranch 7 0 4 2 82% Branches: 2->4, 4->6") + + def test_report_show_missing_branches_and_lines(self): + self.make_file("mybranch.py", """\ + def branch(x, y, z): + if x: + print("x") + if y: + print("y") + if z: + if x and y: + print("z") + return x + branch(1, 1, 0) + """) + out = self.run_command("coverage run --branch mybranch.py") + self.assertEqual(out, 'x\ny\n') report = self.report_from_command("coverage report --show-missing") # pylint: disable=C0301 # Name Stmts Miss Branch BrMiss Cover Missing # ------------------------------------------------------- - # mybranch 7 1 4 2 73% 5, Branches: 2->4, 4->5 + # tests/tmp 10 2 8 5 61% 7-8, Branches: 2->4, 4->6, 6->7, 7->8, 7->9 self.assertEqual(self.line_count(report), 3) self.assertIn("mybranch ", report) self.assertEqual(self.last_line_squeezed(report), - "mybranch 7 1 4 2 73% 5, Branches: 2->4, 4->5") + "mybranch 10 2 8 5 61% " + "7-8, Branches: 2->4, 4->6, 6->7, 7->8, 7->9") def test_dotpy_not_python(self): # We run a .py file, and when reporting, we can't parse it as Python. -- cgit v1.2.1 From 232b546e7325be1626f940e5358fe468f3f06872 Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 26 May 2014 13:44:54 -0400 Subject: minor comment fix --- tests/test_summary.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/test_summary.py') diff --git a/tests/test_summary.py b/tests/test_summary.py index 7fd11a0e..88be7761 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -183,7 +183,7 @@ class SummaryTest(CoverageTest): # Name Stmts Miss Branch BrMiss Cover Missing # ------------------------------------------------------- - # tests/tmp 7 0 4 2 82% Branches: 2->4, 4->6 + # mybranch 7 0 4 2 82% Branches: 2->4, 4->6 self.assertEqual(self.line_count(report), 3) self.assertIn("mybranch ", report) @@ -210,7 +210,7 @@ class SummaryTest(CoverageTest): # pylint: disable=C0301 # Name Stmts Miss Branch BrMiss Cover Missing # ------------------------------------------------------- - # tests/tmp 10 2 8 5 61% 7-8, Branches: 2->4, 4->6, 6->7, 7->8, 7->9 + # mybranch 10 2 8 5 61% 7-8, Branches: 2->4, 4->6, 6->7, 7->8, 7->9 self.assertEqual(self.line_count(report), 3) self.assertIn("mybranch ", report) -- cgit v1.2.1 From a38286c663af6bba730c5e05c3d32b764e949440 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 1 Jun 2014 22:06:36 -0400 Subject: Clean up the merged pull request --- tests/test_summary.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'tests/test_summary.py') diff --git a/tests/test_summary.py b/tests/test_summary.py index 88be7761..2ceaffd9 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -92,7 +92,9 @@ class SummaryTest(CoverageTest): # Try reporting while omitting some modules prefix = os.path.split(__file__)[0] self.run_command("coverage run mycode.py") - report = self.report_from_command("coverage report --omit '%s/*'" % prefix) + report = self.report_from_command( + "coverage report --omit '%s/*'" % prefix + ) # Name Stmts Miss Cover # ---------------------------- @@ -151,7 +153,6 @@ class SummaryTest(CoverageTest): if y: print("y") return x - return y missing(0, 1) """) out = self.run_command("coverage run mymissing.py") @@ -160,12 +161,12 @@ class SummaryTest(CoverageTest): # Name Stmts Miss Cover Missing # ----------------------------------------- - # mymissing 9 3 67% 3-4, 8 + # mymissing 8 2 75% 3-4 self.assertEqual(self.line_count(report), 3) self.assertIn("mymissing ", report) self.assertEqual(self.last_line_squeezed(report), - "mymissing 9 3 67% 3-4, 8") + "mymissing 8 2 75% 3-4") def test_report_show_missing_branches(self): self.make_file("mybranch.py", """\ -- cgit v1.2.1 From 43fa1eef17b4e8dd3fd0976110ef287970d2d7da Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 2 Jun 2014 20:46:40 -0400 Subject: Restore the intent of this test --- tests/test_summary.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'tests/test_summary.py') diff --git a/tests/test_summary.py b/tests/test_summary.py index 2ceaffd9..2612fe36 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -152,21 +152,27 @@ class SummaryTest(CoverageTest): return x if y: print("y") + try: + print("z") + 1/0 + print("Never!") + except ZeroDivisionError: + pass return x missing(0, 1) """) out = self.run_command("coverage run mymissing.py") - self.assertEqual(out, 'y\n') + self.assertEqual(out, 'y\nz\n') report = self.report_from_command("coverage report --show-missing") # Name Stmts Miss Cover Missing # ----------------------------------------- - # mymissing 8 2 75% 3-4 + # mymissing 14 3 79% 3-4, 10 self.assertEqual(self.line_count(report), 3) self.assertIn("mymissing ", report) self.assertEqual(self.last_line_squeezed(report), - "mymissing 8 2 75% 3-4") + "mymissing 14 3 79% 3-4, 10") def test_report_show_missing_branches(self): self.make_file("mybranch.py", """\ -- cgit v1.2.1 From dfe2fa5e5db2cf29a1b43b0abf61be3b545db270 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Tue, 3 Jun 2014 21:41:12 -0400 Subject: Round fail-under result same as others. Fixed #284. --- tests/test_summary.py | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'tests/test_summary.py') diff --git a/tests/test_summary.py b/tests/test_summary.py index 2612fe36..336a2af3 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -21,22 +21,6 @@ class SummaryTest(CoverageTest): # Parent class saves and restores sys.path, we can just modify it. sys.path.append(self.nice_file(os.path.dirname(__file__), 'modules')) - def report_from_command(self, cmd): - """Return the report from the `cmd`, with some convenience added.""" - report = self.run_command(cmd).replace('\\', '/') - self.assertNotIn("error", report.lower()) - return report - - def line_count(self, report): - """How many lines are in `report`?""" - self.assertEqual(report.split('\n')[-1], "") - return len(report.split('\n')) - 1 - - def last_line_squeezed(self, report): - """Return the last line of `report` with the spaces squeezed down.""" - last_line = report.split('\n')[-2] - return re.sub(r"\s+", " ", last_line) - def test_report(self): out = self.run_command("coverage run mycode.py") self.assertEqual(out, 'done\n') -- cgit v1.2.1 From c317727542e303ae9dd5ed4db73217508e367d74 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Tue, 8 Jul 2014 06:25:17 -0400 Subject: Improve branch summarization It failed completely on more than one file! Removed the Branches label, and no longer report missing branches implied by missing lines. --- tests/test_summary.py | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'tests/test_summary.py') diff --git a/tests/test_summary.py b/tests/test_summary.py index 336a2af3..7bd1c496 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -174,14 +174,17 @@ class SummaryTest(CoverageTest): # Name Stmts Miss Branch BrMiss Cover Missing # ------------------------------------------------------- - # mybranch 7 0 4 2 82% Branches: 2->4, 4->6 + # mybranch 7 0 4 2 82% 2->4, 4->6 self.assertEqual(self.line_count(report), 3) self.assertIn("mybranch ", report) self.assertEqual(self.last_line_squeezed(report), - "mybranch 7 0 4 2 82% Branches: 2->4, 4->6") + "mybranch 7 0 4 2 82% 2->4, 4->6") def test_report_show_missing_branches_and_lines(self): + self.make_file("main.py", """\ + import mybranch + """) self.make_file("mybranch.py", """\ def branch(x, y, z): if x: @@ -194,20 +197,32 @@ class SummaryTest(CoverageTest): return x branch(1, 1, 0) """) - out = self.run_command("coverage run --branch mybranch.py") + out = self.run_command("coverage run --branch main.py") self.assertEqual(out, 'x\ny\n') report = self.report_from_command("coverage report --show-missing") # pylint: disable=C0301 # Name Stmts Miss Branch BrMiss Cover Missing # ------------------------------------------------------- - # mybranch 10 2 8 5 61% 7-8, Branches: 2->4, 4->6, 6->7, 7->8, 7->9 - - self.assertEqual(self.line_count(report), 3) - self.assertIn("mybranch ", report) - self.assertEqual(self.last_line_squeezed(report), - "mybranch 10 2 8 5 61% " - "7-8, Branches: 2->4, 4->6, 6->7, 7->8, 7->9") + # main 1 0 0 0 100% + # mybranch 10 2 8 5 61% 7-8, 2->4, 4->6 + # ------------------------------------------------------- + # TOTAL 11 2 8 5 63% + + self.assertEqual(self.line_count(report), 6) + squeezed = self.squeezed_lines(report) + self.assertEqual( + squeezed[2], + "main 1 0 0 0 100%" + ) + self.assertEqual( + squeezed[3], + "mybranch 10 2 8 5 61% 7-8, 2->4, 4->6" + ) + self.assertEqual( + squeezed[5], + "TOTAL 11 2 8 5 63%" + ) def test_dotpy_not_python(self): # We run a .py file, and when reporting, we can't parse it as Python. -- cgit v1.2.1