summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coverage/cmdline.py2
-rw-r--r--coverage/collector.py11
-rw-r--r--coverage/control.py2
-rw-r--r--coverage/data.py58
-rw-r--r--coverage/tracer.c8
-rw-r--r--lab/new-data.js28
-rw-r--r--tests/test_cmdline.py2
-rw-r--r--tests/test_data.py52
8 files changed, 91 insertions, 72 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index af5ff0c..10d0f61 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -599,7 +599,7 @@ class CoverageScript(object):
print("\n%d files:" % len(filenames))
for f in filenames:
line = "%s: %d lines" % (f, summary[f])
- plugin = data.plugin_name(f)
+ plugin = data.file_tracer(f)
if plugin:
line += " [%s]" % plugin
print(line)
diff --git a/coverage/collector.py b/coverage/collector.py
index 52a80f6..b8e0841 100644
--- a/coverage/collector.py
+++ b/coverage/collector.py
@@ -140,8 +140,9 @@ class Collector(object):
# pairs as keys (if branch coverage).
self.data = {}
- # A dictionary mapping filenames to plugin names that will handle them.
- self.plugin_data = {}
+ # A dictionary mapping filenames to file tracer plugin names that will
+ # handle them.
+ self.file_tracers = {}
# The .should_trace_cache attribute is a cache from filenames to
# coverage.FileDisposition objects, or None. When a file is first
@@ -193,8 +194,8 @@ class Collector(object):
)
)
- if hasattr(tracer, 'plugin_data'):
- tracer.plugin_data = self.plugin_data
+ if hasattr(tracer, 'file_tracers'):
+ tracer.file_tracers = self.file_tracers
if hasattr(tracer, 'threading'):
tracer.threading = self.threading
if hasattr(tracer, 'check_include'):
@@ -309,6 +310,6 @@ class Collector(object):
covdata.set_arcs(abs_file_dict(self.data))
else:
covdata.set_lines(abs_file_dict(self.data))
- covdata.set_plugins(abs_file_dict(self.plugin_data))
+ covdata.set_file_tracers(abs_file_dict(self.file_tracers))
self.reset()
diff --git a/coverage/control.py b/coverage/control.py
index d565013..48ee47b 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -834,7 +834,7 @@ class Coverage(object):
if isinstance(morf, string_class):
abs_morf = abs_file(morf)
- plugin_name = self.data.plugin_name(abs_morf)
+ plugin_name = self.data.file_tracer(abs_morf)
if plugin_name:
plugin = self.plugins.get(plugin_name)
diff --git a/coverage/data.py b/coverage/data.py
index 930e04a..929c521 100644
--- a/coverage/data.py
+++ b/coverage/data.py
@@ -42,7 +42,7 @@ class CoverageData(object):
To read a coverage.py data file, use :meth:`read_file`, or :meth:`read` if
you have an already-opened file. You can then access the line, arc, or
- plugin data with :meth:`lines`, :meth:`arcs`, or :meth:`plugin_name`.
+ plugin data with :meth:`lines`, :meth:`arcs`, or :meth:`file_tracer`.
The :meth:`has_arcs` method indicates whether arc data is available. You
can get a list of the files in the data with :meth:`measured_files`.
@@ -53,9 +53,9 @@ class CoverageData(object):
Most data files will be created by coverage.py itself, but you can use
methods here to create data files if you like. The :meth:`set_lines`,
- :meth:`set_arcs`, and :meth:`set_plugins` methods add data, in ways that
- are convenient for coverage.py. To add a file without any measured data,
- use :meth:`touch_file`.
+ :meth:`set_arcs`, and :meth:`set_file_tracers` methods add data, in ways
+ that are convenient for coverage.py. To add a file without any measured
+ data, use :meth:`touch_file`.
You write to a named file with :meth:`write_file`, or to an already opened
file with :meth:`write`.
@@ -77,7 +77,7 @@ class CoverageData(object):
#
# { 'file1': [[17,23], [17,25], [25,26]], ... }
#
- # * plugins: a dict mapping filenames to plugin names::
+ # * file_tracers: a dict mapping filenames to plugin names::
#
# { 'file1': "django.coverage", ... }
#
@@ -113,7 +113,7 @@ class CoverageData(object):
#
# { 'filename1.py': 'django.coverage', ... }
#
- self._plugins = {}
+ self._file_tracers = {}
##
## Reading data
@@ -156,8 +156,8 @@ class CoverageData(object):
return self._arcs[filename]
return None
- def plugin_name(self, filename):
- """Get the plugin name for a file.
+ def file_tracer(self, filename):
+ """Get the plugin name of the file tracer for a file.
Arguments:
filename: the name of the file you're interested in.
@@ -169,10 +169,10 @@ class CoverageData(object):
"""
# Because the vast majority of files involve no plugin, we don't store
- # them explicitly in self._plugins. Check the measured data instead
+ # them explicitly in self._file_tracers. Check the measured data instead
# to see if it was a known file with no plugin.
if filename in (self._arcs or self._lines):
- return self._plugins.get(filename, "")
+ return self._file_tracers.get(filename, "")
return None
def measured_files(self):
@@ -217,7 +217,7 @@ class CoverageData(object):
(fname, [tuple(pair) for pair in arcs])
for fname, arcs in iitems(data.get('arcs', {}))
)
- self._plugins = data.get('plugins', {})
+ self._file_tracers = data.get('file_tracers', {})
self._validate()
@@ -301,26 +301,26 @@ class CoverageData(object):
self._validate()
- def set_plugins(self, plugin_data):
+ def set_file_tracers(self, file_tracers):
"""Add per-file plugin information.
- `plugin_data` is { filename: plugin_name, ... }
+ `file_tracers` is { filename: plugin_name, ... }
"""
existing_files = self._arcs or self._lines
- for filename, plugin_name in iitems(plugin_data):
+ for filename, plugin_name in iitems(file_tracers):
if filename not in existing_files:
raise CoverageException(
"Can't add plugin data for unmeasured file '%s'" % (filename,)
)
- existing_plugin = self._plugins.get(filename)
+ existing_plugin = self._file_tracers.get(filename)
if existing_plugin is not None and plugin_name != existing_plugin:
raise CoverageException(
"Conflicting plugin name for '%s': %r vs %r" % (
filename, existing_plugin, plugin_name,
)
)
- self._plugins[filename] = plugin_name
+ self._file_tracers[filename] = plugin_name
self._validate()
@@ -340,8 +340,8 @@ class CoverageData(object):
else:
file_data['lines'] = self._lines
- if self._plugins:
- file_data['plugins'] = self._plugins
+ if self._file_tracers:
+ file_data['file_tracers'] = self._file_tracers
# Write the data to the file.
file_obj.write(self.GO_AWAY)
@@ -358,7 +358,7 @@ class CoverageData(object):
"""Erase the data in this object."""
self._lines = {}
self._arcs = {}
- self._plugins = {}
+ self._file_tracers = {}
self._validate()
def update(self, other_data, aliases=None):
@@ -375,16 +375,16 @@ class CoverageData(object):
aliases = aliases or PathAliases()
- # _plugins: only have a string, so they have to agree.
+ # _file_tracers: only have a string, so they have to agree.
# Have to do these first, so that our examination of self._arcs and
# self._lines won't be confused by data updated from other_data.
for filename in other_data.measured_files():
- other_plugin = other_data.plugin_name(filename)
+ other_plugin = other_data.file_tracer(filename)
filename = aliases.map(filename)
- this_plugin = self.plugin_name(filename)
+ this_plugin = self.file_tracer(filename)
if this_plugin is None:
if other_plugin:
- self._plugins[filename] = other_plugin
+ self._file_tracers[filename] = other_plugin
elif this_plugin != other_plugin:
raise CoverageException(
"Conflicting plugin name for '%s': %r vs %r" % (
@@ -442,11 +442,13 @@ class CoverageData(object):
"_arcs[%r] shouldn't be %r" % (fname, arcs)
)
- # _plugins should have only non-empty strings as values.
- for fname, plugin in iitems(self._plugins):
- assert isinstance(fname, string_class), "Key in _plugins shouldn't be %r" % (fname,)
+ # _file_tracers should have only non-empty strings as values.
+ for fname, plugin in iitems(self._file_tracers):
+ assert isinstance(fname, string_class), (
+ "Key in _file_tracers shouldn't be %r" % (fname,)
+ )
assert plugin and isinstance(plugin, string_class), (
- "_plugins[%r] shoudn't be %r" % (fname, plugin)
+ "_file_tracers[%r] shoudn't be %r" % (fname, plugin)
)
def add_to_hash(self, filename, hasher):
@@ -462,7 +464,7 @@ class CoverageData(object):
hasher.update(sorted(self.arcs(filename)))
else:
hasher.update(sorted(self.lines(filename)))
- hasher.update(self.plugin_name(filename))
+ hasher.update(self.file_tracer(filename))
##
## Internal
diff --git a/coverage/tracer.c b/coverage/tracer.c
index 11606eb..5c08b39 100644
--- a/coverage/tracer.c
+++ b/coverage/tracer.c
@@ -107,7 +107,7 @@ typedef struct {
PyObject * warn;
PyObject * concur_id_func;
PyObject * data;
- PyObject * plugin_data;
+ PyObject * file_tracers;
PyObject * should_trace_cache;
PyObject * arcs;
@@ -248,7 +248,7 @@ CTracer_dealloc(CTracer *self)
Py_XDECREF(self->warn);
Py_XDECREF(self->concur_id_func);
Py_XDECREF(self->data);
- Py_XDECREF(self->plugin_data);
+ Py_XDECREF(self->file_tracers);
Py_XDECREF(self->should_trace_cache);
DataStack_dealloc(self, &self->data_stack);
@@ -612,7 +612,7 @@ CTracer_handle_call(CTracer *self, PyFrameObject *frame)
/* If the disposition mentions a plugin, record that. */
if (file_tracer != Py_None) {
- ret2 = PyDict_SetItem(self->plugin_data, tracename, plugin_name);
+ ret2 = PyDict_SetItem(self->file_tracers, tracename, plugin_name);
if (ret2 < 0) {
goto error;
}
@@ -1104,7 +1104,7 @@ CTracer_members[] = {
{ "data", T_OBJECT, offsetof(CTracer, data), 0,
PyDoc_STR("The raw dictionary of trace data.") },
- { "plugin_data", T_OBJECT, offsetof(CTracer, plugin_data), 0,
+ { "file_tracers", T_OBJECT, offsetof(CTracer, file_tracers), 0,
PyDoc_STR("Mapping from filename to plugin name.") },
{ "should_trace_cache", T_OBJECT, offsetof(CTracer, should_trace_cache), 0,
diff --git a/lab/new-data.js b/lab/new-data.js
index 95f16a8..973aa11 100644
--- a/lab/new-data.js
+++ b/lab/new-data.js
@@ -1,15 +1,31 @@
{
- "collector": "coverage.py 4.0",
- "config": {
- "branch": true,
- "source": ".",
+ "run" {
+ "collector": "coverage.py 4.0",
+ "config": {
+ "branch": true,
+ "source": ".",
+ },
+ "collected": "20150711T090600",
+ },
+
+ // As of now:
+ "lines": {
+ "a/b/c.py": [1, 2, 3, 4, 5],
+ "a/b/d.py": [4, 5, 6, 7, 8],
},
- "collected": "20150711T090600",
+ "arcs": {
+ "a/b/c.py: [[1, 2], [2, 3], [4, 5]],
+ },
+ "plugins: {
+ "a/b/c.py": "fooey.plugin",
+ },
+
+ // Maybe in the future?
"files": {
"a/b/c.py": {
"lines": [1, 2, 3, 4, 5],
"arcs": [
- "1.2", "3.4", "5.-1"
+ [1, 2], [3, 4], [5, -1],
],
"plugin": "django.coverage",
diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py
index 0621ec3..a74498d 100644
--- a/tests/test_cmdline.py
+++ b/tests/test_cmdline.py
@@ -529,7 +529,7 @@ class CmdLineWithFilesTest(BaseCmdLineTest):
"file1.py": dict.fromkeys(range(1, 18)),
"file2.py": dict.fromkeys(range(1, 24)),
})
- data.set_plugins({"file1.py": "a_plugin"})
+ data.set_file_tracers({"file1.py": "a_plugin"})
data_files = CoverageDataFiles()
data_files.write(data)
diff --git a/tests/test_data.py b/tests/test_data.py
index 92233a6..c54c13f 100644
--- a/tests/test_data.py
+++ b/tests/test_data.py
@@ -167,29 +167,29 @@ class CoverageDataTest(DataTestHelpers, CoverageTest):
"p2.html": dict.fromkeys([10, 11, 12]),
"main.py": dict.fromkeys([20]),
})
- covdata.set_plugins({"p1.foo": "p1.plugin", "p2.html": "p2.plugin"})
- self.assertEqual(covdata.plugin_name("p1.foo"), "p1.plugin")
- self.assertEqual(covdata.plugin_name("main.py"), "")
- self.assertIsNone(covdata.plugin_name("p3.not_here"))
+ covdata.set_file_tracers({"p1.foo": "p1.plugin", "p2.html": "p2.plugin"})
+ self.assertEqual(covdata.file_tracer("p1.foo"), "p1.plugin")
+ self.assertEqual(covdata.file_tracer("main.py"), "")
+ self.assertIsNone(covdata.file_tracer("p3.not_here"))
def test_cant_plugin_unmeasured_files(self):
covdata = CoverageData()
msg = "Can't add plugin data for unmeasured file 'p1.foo'"
with self.assertRaisesRegex(CoverageException, msg):
- covdata.set_plugins({"p1.foo": "p1.plugin"})
+ covdata.set_file_tracers({"p1.foo": "p1.plugin"})
covdata.set_lines({"p2.html": dict.fromkeys([10, 11, 12])})
with self.assertRaisesRegex(CoverageException, msg):
- covdata.set_plugins({"p1.foo": "p1.plugin"})
+ covdata.set_file_tracers({"p1.foo": "p1.plugin"})
def test_cant_change_plugin_name(self):
covdata = CoverageData()
covdata.set_lines({"p1.foo": dict.fromkeys([1, 2, 3])})
- covdata.set_plugins({"p1.foo": "p1.plugin"})
+ covdata.set_file_tracers({"p1.foo": "p1.plugin"})
msg = "Conflicting plugin name for 'p1.foo': 'p1.plugin' vs 'p1.plugin.foo'"
with self.assertRaisesRegex(CoverageException, msg):
- covdata.set_plugins({"p1.foo": "p1.plugin.foo"})
+ covdata.set_file_tracers({"p1.foo": "p1.plugin.foo"})
def test_update_lines(self):
covdata1 = CoverageData()
@@ -239,7 +239,7 @@ class CoverageDataTest(DataTestHelpers, CoverageTest):
"p2.html": dict.fromkeys([5, 6, 7]),
"main.py": dict.fromkeys([10, 11, 12]),
})
- covdata1.set_plugins({
+ covdata1.set_file_tracers({
"p1.html": "html.plugin",
"p2.html": "html.plugin2",
})
@@ -251,7 +251,7 @@ class CoverageDataTest(DataTestHelpers, CoverageTest):
"p3.foo": dict.fromkeys([1000, 1001]),
"main.py": dict.fromkeys([10, 11, 12]),
})
- covdata2.set_plugins({
+ covdata2.set_file_tracers({
"p1.html": "html.plugin",
"p2.html": "html.plugin2",
"p3.foo": "foo_plugin",
@@ -260,19 +260,19 @@ class CoverageDataTest(DataTestHelpers, CoverageTest):
covdata3 = CoverageData()
covdata3.update(covdata1)
covdata3.update(covdata2)
- self.assertEqual(covdata3.plugin_name("p1.html"), "html.plugin")
- self.assertEqual(covdata3.plugin_name("p2.html"), "html.plugin2")
- self.assertEqual(covdata3.plugin_name("p3.foo"), "foo_plugin")
- self.assertEqual(covdata3.plugin_name("main.py"), "")
+ self.assertEqual(covdata3.file_tracer("p1.html"), "html.plugin")
+ self.assertEqual(covdata3.file_tracer("p2.html"), "html.plugin2")
+ self.assertEqual(covdata3.file_tracer("p3.foo"), "foo_plugin")
+ self.assertEqual(covdata3.file_tracer("main.py"), "")
def test_update_conflicting_plugins(self):
covdata1 = CoverageData()
covdata1.set_lines({"p1.html": dict.fromkeys([1, 2, 3])})
- covdata1.set_plugins({"p1.html": "html.plugin"})
+ covdata1.set_file_tracers({"p1.html": "html.plugin"})
covdata2 = CoverageData()
covdata2.set_lines({"p1.html": dict.fromkeys([1, 2, 3])})
- covdata2.set_plugins({"p1.html": "html.other_plugin"})
+ covdata2.set_file_tracers({"p1.html": "html.other_plugin"})
msg = "Conflicting plugin name for 'p1.html': 'html.plugin' vs 'html.other_plugin'"
with self.assertRaisesRegex(CoverageException, msg):
@@ -285,7 +285,7 @@ class CoverageDataTest(DataTestHelpers, CoverageTest):
def test_update_plugin_vs_no_plugin(self):
covdata1 = CoverageData()
covdata1.set_lines({"p1.html": dict.fromkeys([1, 2, 3])})
- covdata1.set_plugins({"p1.html": "html.plugin"})
+ covdata1.set_file_tracers({"p1.html": "html.plugin"})
covdata2 = CoverageData()
covdata2.set_lines({"p1.html": dict.fromkeys([1, 2, 3])})
@@ -311,7 +311,7 @@ class CoverageDataTest(DataTestHelpers, CoverageTest):
def test_add_to_hash_with_arcs(self):
covdata = CoverageData()
covdata.set_arcs(ARCS_3)
- covdata.set_plugins({"y.py": "hologram_plugin"})
+ covdata.set_file_tracers({"y.py": "hologram_plugin"})
hasher = mock.Mock()
covdata.add_to_hash("y.py", hasher)
self.assertEqual(hasher.method_calls, [
@@ -378,7 +378,7 @@ class CoverageDataTestInTempDir(DataTestHelpers, CoverageTest):
covdata2 = CoverageData()
covdata2.set_arcs(ARCS_3)
- covdata2.set_plugins({"y.py": "magic_plugin"})
+ covdata2.set_file_tracers({"y.py": "magic_plugin"})
covdata2.write_file("arcs.dat")
covdata3 = CoverageData()
@@ -397,7 +397,7 @@ class CoverageDataTestInTempDir(DataTestHelpers, CoverageTest):
"x.py": [[-1, 1], [1, 2], [2, 3], [3, -1]],
"y.py": [[-1, 17], [17, 23], [23, -1]],
},
- "plugins": {"y.py": "magic_plugin"}
+ "file_tracers": {"y.py": "magic_plugin"}
},
"empty.dat": {"lines": {}},
}
@@ -558,8 +558,8 @@ class CoverageDataFilesTest(DataTestHelpers, CoverageTest):
self.assertCountEqual(lines['b.py'], B_PY_LINES_1)
# If not measuring branches, there's no arcs entry.
self.assertNotIn('arcs', data)
- # If no plugins were involved, there's no plugins entry.
- self.assertNotIn('plugins', data)
+ # If no plugins were involved, there's no file_tracers entry.
+ self.assertNotIn('file_tracers', data)
def test_file_format_with_arcs(self):
# Write with CoverageData, then read the JSON explicitly.
@@ -574,8 +574,8 @@ class CoverageDataFilesTest(DataTestHelpers, CoverageTest):
self.assertCountEqual(arcs.keys(), MEASURED_FILES_3)
self.assertCountEqual(arcs['x.py'], map(list, X_PY_ARCS_3))
self.assertCountEqual(arcs['y.py'], map(list, Y_PY_ARCS_3))
- # If no plugins were involved, there's no plugins entry.
- self.assertNotIn('plugins', data)
+ # If no plugins were involved, there's no file_tracers entry.
+ self.assertNotIn('file_tracers', data)
def test_writing_to_other_file(self):
data_files = CoverageDataFiles(".otherfile")
@@ -596,7 +596,7 @@ class CoverageDataFilesTest(DataTestHelpers, CoverageTest):
'/home/ned/proj/src/sub/b.py': {3: None},
'/home/ned/proj/src/template.html': {10: None},
})
- covdata1.set_plugins({
+ covdata1.set_file_tracers({
'/home/ned/proj/src/template.html': 'html.plugin',
})
self.data_files.write(covdata1, suffix='1')
@@ -620,7 +620,7 @@ class CoverageDataFilesTest(DataTestHelpers, CoverageTest):
self.assert_line_counts(covdata3, {apy: 4, sub_bpy: 2, template_html: 1}, fullpath=True)
self.assert_measured_files(covdata3, [apy, sub_bpy, template_html])
- self.assertEqual(covdata3.plugin_name(template_html), 'html.plugin')
+ self.assertEqual(covdata3.file_tracer(template_html), 'html.plugin')
def test_combining_from_different_directories(self):
covdata1 = CoverageData()