diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2015-08-15 13:21:53 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-08-15 13:21:53 -0400 |
commit | cac28dc30e095ff336be3df69363fa9100e0038c (patch) | |
tree | 98184b6f0c863b3ecd9eb162ff16a0fe6588b57f /coverage/plugin.py | |
parent | c61920c057d78361a2238baedf2d7218021ac835 (diff) | |
download | python-coveragepy-git-cac28dc30e095ff336be3df69363fa9100e0038c.tar.gz |
Plugin doc tweaking
Diffstat (limited to 'coverage/plugin.py')
-rw-r--r-- | coverage/plugin.py | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/coverage/plugin.py b/coverage/plugin.py index 32ed6a7e..ac407047 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`. |