summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-02-10 09:36:12 -0500
committerNed Batchelder <ned@nedbatchelder.com>2015-02-10 09:36:12 -0500
commit08c37202cb992865e502e6f80e430b5125be1afc (patch)
tree9e36b74bc3cb0d524b754aa703dbe3df3ce0d208
parent2869cbd23e637ffeb52536b3b218d8ef91d2d7d7 (diff)
downloadpython-coveragepy-git-08c37202cb992865e502e6f80e430b5125be1afc.tar.gz
Fix a bad check that was causing mysterious py2/py3 differences
-rw-r--r--coverage/control.py4
-rw-r--r--coverage/tracer.c4
-rw-r--r--tests/test_plugins.py10
3 files changed, 13 insertions, 5 deletions
diff --git a/coverage/control.py b/coverage/control.py
index ee3ea33f..7532d291 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -541,9 +541,9 @@ class Coverage(object):
reason = self._check_include_omit_etc_internal(filename, frame)
if self.debug.should('trace'):
if not reason:
- msg = "Tracing %r" % (filename,)
+ msg = "Including %r" % (filename,)
else:
- msg = "Not tracing %r: %s" % (filename, reason)
+ msg = "Not including %r: %s" % (filename, reason)
self.debug.write(msg)
return not reason
diff --git a/coverage/tracer.c b/coverage/tracer.c
index 0d3a527f..102c474e 100644
--- a/coverage/tracer.c
+++ b/coverage/tracer.c
@@ -20,7 +20,6 @@
#if PY_MAJOR_VERSION >= 3
#define MyText_Type PyUnicode_Type
-#define MyText_Check(o) PyUnicode_Check(o)
#define MyText_AS_BYTES(o) PyUnicode_AsASCIIString(o)
#define MyText_AS_STRING(o) PyBytes_AS_STRING(o)
#define MyInt_FromInt(i) PyLong_FromLong((long)i)
@@ -31,7 +30,6 @@
#else
#define MyText_Type PyString_Type
-#define MyText_Check(o) PyString_Check(o)
#define MyText_AS_BYTES(o) (Py_INCREF(o), o)
#define MyText_AS_STRING(o) PyString_AS_STRING(o)
#define MyInt_FromInt(i) PyInt_FromLong((long)i)
@@ -562,7 +560,7 @@ CTracer_trace(CTracer *self, PyFrameObject *frame, int what, PyObject *arg_unuse
Py_INCREF(tracename);
}
- if (MyText_Check(tracename)) {
+ if (tracename != Py_None) {
PyObject * file_data = PyDict_GetItem(self->data, tracename);
PyObject * disp_plugin_name = NULL;
diff --git a/tests/test_plugins.py b/tests/test_plugins.py
index 2b4b2ee1..0d57bc97 100644
--- a/tests/test_plugins.py
+++ b/tests/test_plugins.py
@@ -284,6 +284,10 @@ class FileTracerTest(CoverageTest):
# quux_5.html will be omitted from the results.
assert render("quux_5.html", 3) == "[quux_5.html @ 3]"
+
+ # In Python 2, either kind of string should be OK.
+ if type("") == type(b""):
+ assert render(u"unicode_3.html", 2) == "[unicode_3.html @ 2]"
""")
cov = coverage.Coverage(omit=["*quux*"])
@@ -307,3 +311,9 @@ class FileTracerTest(CoverageTest):
self.assertIn("bar_4.html", cov.data.summary())
self.assertNotIn("quux_5.html", cov.data.summary())
+
+ if env.PY2:
+ _, statements, missing, _ = cov.analysis("unicode_3.html")
+ self.assertEqual(statements, [1, 2, 3])
+ self.assertEqual(missing, [1])
+ self.assertIn("unicode_3.html", cov.data.summary())