From fb07857ab135233de7dab547ddd75411a19d84cf Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 2 Nov 2009 10:08:02 -0500 Subject: CodeParser couldn't deal with being passed the text directly. --- TODO.txt | 2 ++ coverage/parser.py | 3 ++- test/test_coverage.py | 6 +++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/TODO.txt b/TODO.txt index 293ffcc..ebf9ad7 100644 --- a/TODO.txt +++ b/TODO.txt @@ -7,6 +7,7 @@ Coverage TODO - parser is doing some redundant work. - while TRUE claims to be partial? - Analysis class should do rolling up of stats also. +- Update docs for --branch. * Speed @@ -167,6 +168,7 @@ x Why can't you specify execute (-x) and report (-r) in the same invocation? + Switch to a real test runner, like nose. + Test both the C trace function and the Python trace function. +- parser.py has no direct tests. - Tests about the .coverage file. + Tests about the --long-form of arguments. + Tests about overriding the .coverage filename. diff --git a/coverage/parser.py b/coverage/parser.py index 8c8593c..7721d8d 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -19,7 +19,8 @@ class CodeParser(object): """ assert text or filename, "CodeParser needs either text or filename" self.filename = filename or "" - if not text: + self.text = text + if not self.text: try: sourcef = open(self.filename, 'rU') self.text = sourcef.read() diff --git a/test/test_coverage.py b/test/test_coverage.py index 7d6df25..d3ba6a4 100644 --- a/test/test_coverage.py +++ b/test/test_coverage.py @@ -2,7 +2,7 @@ # Copyright 2004-2009, Ned Batchelder # http://nedbatchelder.com/code/coverage -import os, sys, unittest +import os, re, sys, unittest import coverage coverage.use_cache(0) @@ -1654,10 +1654,12 @@ class ProcessTest(CoverageTest): # --------------------------------------------------------------------- # TOTAL 8 8 100% + self.assert_("error" not in report1.lower()) self.assert_("/coverage/__init__/" not in report1) self.assert_("/test/modules/covmod1 " in report1) self.assert_("/test/zipmods.zip/covmodzip1 " in report1) self.assert_("mycode " in report1) + self.assertEqual(re.sub(r"\s+", " ", report1.split('\n')[-2]), "TOTAL 8 8 100%") for l in report1.split('\n'): if '/test/modules/covmod1' in l: @@ -1672,6 +1674,7 @@ class ProcessTest(CoverageTest): # ---------------------------- # mycode 4 4 100% + self.assert_("error" not in report2.lower()) self.assert_("/coverage/" not in report2) self.assert_("/test/modules/covmod1 " not in report2) self.assert_("/test/zipmods.zip/covmodzip1 " not in report2) @@ -1685,6 +1688,7 @@ class ProcessTest(CoverageTest): # ---------------------------- # mycode 4 4 100% + self.assert_("error" not in report3.lower()) self.assert_("/coverage/" not in report3) self.assert_("/test/modules/covmod1 " not in report3) self.assert_("/test/zipmods.zip/covmodzip1 " not in report3) -- cgit v1.2.1