summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2014-09-28 19:44:20 -0400
committerNed Batchelder <ned@nedbatchelder.com>2014-09-28 19:44:20 -0400
commit9453fa062539ac28b60c325e39c0fcbfd3b2ea10 (patch)
treebe81d9b59be8c0c9a3b4a4ae59c047df2d332d8b
parentf8455cc745ccbde7ee1cc13bd302a7bdc3369d6c (diff)
downloadpython-coveragepy-git-9453fa062539ac28b60c325e39c0fcbfd3b2ea10.tar.gz
Pragmas for uncovered code
-rw-r--r--coverage/backward.py2
-rw-r--r--coverage/control.py7
-rw-r--r--coverage/misc.py2
-rw-r--r--metacov.ini2
-rw-r--r--tests/coveragetest.py9
-rw-r--r--tests/test_execfile.py4
-rw-r--r--tests/test_farm.py7
-rw-r--r--tests/test_templite.py6
-rw-r--r--tests/test_testing.py4
9 files changed, 23 insertions, 20 deletions
diff --git a/coverage/backward.py b/coverage/backward.py
index 9597449c..e839f6bd 100644
--- a/coverage/backward.py
+++ b/coverage/backward.py
@@ -148,7 +148,7 @@ def import_local_file(modname):
if SourceFileLoader:
mod = SourceFileLoader(modname, modfile).load_module()
else:
- for suff in imp.get_suffixes():
+ for suff in imp.get_suffixes(): # pragma: part covered
if suff[0] == '.py':
break
diff --git a/coverage/control.py b/coverage/control.py
index fe4e5f15..b2ec64ab 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -550,10 +550,9 @@ class Coverage(object):
# `save()` at the last minute so that the pid will be correct even
# if the process forks.
extra = ""
- if _TEST_NAME_FILE:
- f = open(_TEST_NAME_FILE)
- test_name = f.read()
- f.close()
+ if _TEST_NAME_FILE: # pragma: debugging
+ with open(_TEST_NAME_FILE) as f:
+ test_name = f.read()
extra = "." + test_name
data_suffix = "%s%s.%s.%06d" % (
socket.gethostname(), extra, os.getpid(),
diff --git a/coverage/misc.py b/coverage/misc.py
index 6962ae32..a653bb62 100644
--- a/coverage/misc.py
+++ b/coverage/misc.py
@@ -55,7 +55,7 @@ def format_lines(statements, lines):
return ret
-def short_stack():
+def short_stack(): # pragma: debugging
"""Return a string summarizing the call stack."""
stack = inspect.stack()[:0:-1]
return "\n".join("%30s : %s @%d" % (t[3],t[1],t[2]) for t in stack)
diff --git a/metacov.ini b/metacov.ini
index 51af37a9..3bce01e2 100644
--- a/metacov.ini
+++ b/metacov.ini
@@ -15,6 +15,8 @@ exclude_lines =
def __repr__
if __name__ == .__main__.:
raise AssertionError
+ # pragma: debugging
+ # pragma: only failure
partial_branches =
# pragma: part covered
diff --git a/tests/coveragetest.py b/tests/coveragetest.py
index 4053059f..19fc0612 100644
--- a/tests/coveragetest.py
+++ b/tests/coveragetest.py
@@ -37,10 +37,11 @@ class CoverageTest(
def setUp(self):
super(CoverageTest, self).setUp()
- if _TEST_NAME_FILE:
- f = open(_TEST_NAME_FILE, "w")
- f.write("%s_%s" % (self.__class__.__name__, self._testMethodName))
- f.close()
+ if _TEST_NAME_FILE: # pragma: debugging
+ with open(_TEST_NAME_FILE, "w") as f:
+ f.write("%s_%s" % (
+ self.__class__.__name__, self._testMethodName,
+ ))
def clean_local_file_imports(self):
"""Clean up the results of calls to `import_local_file`.
diff --git a/tests/test_execfile.py b/tests/test_execfile.py
index 69616e84..3a92ff76 100644
--- a/tests/test_execfile.py
+++ b/tests/test_execfile.py
@@ -91,9 +91,9 @@ class RunPycFileTest(CoverageTest):
os.remove("compiled.py")
# Find the .pyc file!
- for there, _, files in os.walk("."):
+ for there, _, files in os.walk("."): # pragma: part covered
for f in files:
- if f.endswith(".pyc"):
+ if f.endswith(".pyc"): # pragma: part covered
return os.path.join(there, f)
def test_running_pyc(self):
diff --git a/tests/test_farm.py b/tests/test_farm.py
index 47f9b7b7..d0f0a72a 100644
--- a/tests/test_farm.py
+++ b/tests/test_farm.py
@@ -70,10 +70,9 @@ class FarmTestCase(object):
"""Execute the test from the run.py file.
"""
- if _TEST_NAME_FILE:
- f = open(_TEST_NAME_FILE, "w")
- f.write(self.description.replace("/", "_"))
- f.close()
+ if _TEST_NAME_FILE: # pragma: debugging
+ with open(_TEST_NAME_FILE, "w") as f:
+ f.write(self.description.replace("/", "_"))
cwd = self.cd(self.dir)
diff --git a/tests/test_templite.py b/tests/test_templite.py
index a4667a62..aa697b78 100644
--- a/tests/test_templite.py
+++ b/tests/test_templite.py
@@ -31,8 +31,10 @@ class TempliteTest(CoverageTest):
an exception and never get to the result comparison.
"""
actual = Templite(text).render(ctx or {})
- if result:
- self.assertEqual(actual, result)
+ # If result is None, then an exception should have prevented us getting
+ # to here.
+ assert result is not None
+ self.assertEqual(actual, result)
def assertSynErr(self, msg):
"""Assert that a `TempliteSyntaxError` will happen.
diff --git a/tests/test_testing.py b/tests/test_testing.py
index 4a19098f..05db7298 100644
--- a/tests/test_testing.py
+++ b/tests/test_testing.py
@@ -114,7 +114,7 @@ def same_python_executable(e1, e2):
e2 = os.path.abspath(os.path.realpath(e2))
if os.path.dirname(e1) != os.path.dirname(e2):
- return False
+ return False # pragma: only failure
e1 = os.path.basename(e1)
e2 = os.path.basename(e2)
@@ -126,4 +126,4 @@ def same_python_executable(e1, e2):
# python2.3 and python2.3: ok
return True
- return False
+ return False # pragma: only failure