summaryrefslogtreecommitdiff
path: root/coverage/plugin.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-08-15 13:21:53 -0400
committerNed Batchelder <ned@nedbatchelder.com>2015-08-15 13:21:53 -0400
commitbe4a96d85bd5dd8328fcde9a77ee9a25f096881c (patch)
tree0334e2ea6532432bba643f4ae90fe4f504ef617f /coverage/plugin.py
parent7c325cb60eda2aa768ac7a2965bc535f0677223e (diff)
downloadpython-coveragepy-be4a96d85bd5dd8328fcde9a77ee9a25f096881c.tar.gz
Plugin doc tweaking
Diffstat (limited to 'coverage/plugin.py')
-rw-r--r--coverage/plugin.py39
1 files changed, 21 insertions, 18 deletions
diff --git a/coverage/plugin.py b/coverage/plugin.py
index 32ed6a7..ac40704 100644
--- a/coverage/plugin.py
+++ b/coverage/plugin.py
@@ -31,10 +31,13 @@ class CoveragePlugin(object):
def coverage_init(reg, options):
reg.add_file_tracer(MyPlugin())
- The `reg.add_file_tracer` method takes an instance of your plugin. If your
- plugin takes options, the `options` argument is a dictionary of your
- plugin's options from the coverage.py configuration file. Use them as you
- need to configure your object before registering it.
+ You use the `reg` parameter passed to your `coverage_init` function to
+ register your plugin object. It has one method, `add_file_tracer`, which
+ takes a newly created instance of your plugin.
+
+ If your plugin takes options, the `options` parameter is a dictionary of
+ your plugin's options from the coverage.py configuration file. Use them
+ however you want to configure your object before registering it.
"""
@@ -207,6 +210,20 @@ class FileReporter(object):
"""
return files.relative_filename(self.filename)
+ @contract(returns='unicode')
+ def source(self):
+ """Get the source for the file.
+
+ Returns a Unicode string.
+
+ The base implementation simply reads the `self.filename` file and
+ decodes it as UTF8. Override this method if your file isn't readable
+ as a text file, or if you need other encoding support.
+
+ """
+ with open(self.filename, "rb") as f:
+ return f.read().decode("utf8")
+
def lines(self):
"""Get the executable lines in this file.
@@ -304,20 +321,6 @@ class FileReporter(object):
"""
return {}
- @contract(returns='unicode')
- def source(self):
- """Get the source for the file.
-
- Returns a Unicode string.
-
- The base implementation simply reads the `self.filename` file and
- decodes it as UTF8. Override this method if your file isn't readable
- as a text file, or if you need other encoding support.
-
- """
- with open(self.filename, "rb") as f:
- return f.read().decode("utf8")
-
def source_token_lines(self):
"""Generate a series of tokenized lines, one for each line in `source`.