Skip to content

Commit

Permalink
Make return codes consistent: 1 for no data and 2 for fail_under. Now…
Browse files Browse the repository at this point in the history
… the `report` command will properly report `No data to report` if there's no data.
  • Loading branch information
ionelmc committed Jun 28, 2015
1 parent 7840acd commit d20a77c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
3 changes: 1 addition & 2 deletions coverage/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ def report(self, morfs):
self.index_file()

self.make_local_static_report_files()

return self.totals.pc_covered
return self.totals.n_statements and self.totals.pc_covered

def make_local_static_report_files(self):
"""Make local instances of static files for HTML report."""
Expand Down
3 changes: 2 additions & 1 deletion coverage/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,6 @@ def report(self, morfs, outfile=None):
if self.config.show_missing:
args += ("",)
outfile.write(fmt_coverage % args)

if not total.n_files:
raise CoverageException("No data to report.")
return total.n_statements and total.pc_covered
32 changes: 26 additions & 6 deletions tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,17 +703,15 @@ def test_fail_under_in_config(self):
st, _ = self.run_command_status("coverage report")
self.assertEqual(st, 2)

class FailUnderNoDataTest(CoverageTest):
def setUp(self):
super(FailUnderNoDataTest, self).setUp()

class FailUnderNoFilesTest(CoverageTest):
def setUp(self):
super(FailUnderNoFilesTest, self).setUp()
self.make_file(".coveragerc", "[report]\nfail_under = 99\n")
if os.path.exists('.coverage'):
os.remove('.coverage')

def test_report(self):
st, _ = self.run_command_status("coverage report")
self.assertEqual(st, 2)
self.assertEqual(st, 1)

def test_xml(self):
st, _ = self.run_command_status("coverage xml")
Expand All @@ -724,6 +722,28 @@ def test_html(self):
self.assertEqual(st, 1)


class FailUnderEmptyFilesTest(CoverageTest):
def setUp(self):
super(FailUnderEmptyFilesTest, self).setUp()

self.make_file(".coveragerc", "[report]\nfail_under = 99\n")
self.make_file("empty.py", "")
st, _ = self.run_command_status("coverage run empty.py")
self.assertEqual(st, 0)

def test_report(self):
st, _ = self.run_command_status("coverage report")
self.assertEqual(st, 2)

def test_xml(self):
st, _ = self.run_command_status("coverage xml")
self.assertEqual(st, 2)

def test_html(self):
st, _ = self.run_command_status("coverage html")
self.assertEqual(st, 2)


def possible_pth_dirs():
"""Produce a sequence of directories for trying to write .pth files."""
# First look through sys.path, and we find a .pth file, then it's a good
Expand Down

0 comments on commit d20a77c

Please sign in to comment.