diff options
| author | Ned Batchelder <ned@nedbatchelder.com> | 2015-08-10 07:35:50 -0400 |
|---|---|---|
| committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-08-10 07:35:50 -0400 |
| commit | 1279923a1d4e6c0844656bc6aaa75a496f070536 (patch) | |
| tree | 57c1252884d1488cef8d7a005d7c56ffeb6e8d24 | |
| parent | 8f3e7d8b69a145304c212925b260659b5a706304 (diff) | |
| download | python-coveragepy-1279923a1d4e6c0844656bc6aaa75a496f070536.tar.gz | |
Add docstring for source_token_lines
| -rw-r--r-- | coverage/plugin.py | 22 | ||||
| -rw-r--r-- | coverage/plugin_support.py | 2 | ||||
| -rw-r--r-- | tests/modules/plugins/a_plugin.py | 2 | ||||
| -rw-r--r-- | tests/modules/plugins/another.py | 2 | ||||
| -rw-r--r-- | tests/test_plugins.py | 2 |
5 files changed, 26 insertions, 4 deletions
diff --git a/coverage/plugin.py b/coverage/plugin.py index aa2d208..5d61e7f 100644 --- a/coverage/plugin.py +++ b/coverage/plugin.py @@ -204,9 +204,27 @@ class FileReporter(object): return f.read() def source_token_lines(self): - """Return the 'tokenized' text for the code. + """Generate a series of tokenized lines, one for each line in `source`. + + These tokens are used for syntax-colored reports. + + Each line is a list of pairs, each pair is a token:: + + [('key', 'def'), ('ws', ' '), ('nam', 'hello'), ('op', '('), ... ] + + Each pair has a token class, and the token text. The token classes are: + + * `'com'`: a comment + * `'key'`: a keyword + * `'nam'`: a name, or identifier + * `'num'`: a number + * `'op'`: an operator + * `'str'`: a string literal + * `'txt'`: some other kind of text + + If you concatenate all the token texts, and then join them with newlines, + you should have your original `source` back. - 'str', 'nam', 'num', 'key', 'com', 'op' """ # A generic implementation, each line is one "txt" token. for line in self.source().splitlines(): diff --git a/coverage/plugin_support.py b/coverage/plugin_support.py index 8863b43..f88342e 100644 --- a/coverage/plugin_support.py +++ b/coverage/plugin_support.py @@ -160,7 +160,7 @@ class DebugFileTracerWrapper(FileTracer): return "%s@%d" % ( os.path.basename(frame.f_code.co_filename), frame.f_lineno, - ) + ) def source_filename(self): sfilename = self.tracer.source_filename() diff --git a/tests/modules/plugins/a_plugin.py b/tests/modules/plugins/a_plugin.py index 2a9910d..0cc96e5 100644 --- a/tests/modules/plugins/a_plugin.py +++ b/tests/modules/plugins/a_plugin.py @@ -2,8 +2,10 @@ from coverage import CoveragePlugin + class Plugin(CoveragePlugin): pass + def coverage_init(reg, options): reg.add_file_tracer(Plugin()) diff --git a/tests/modules/plugins/another.py b/tests/modules/plugins/another.py index 096d3b9..80902d3 100644 --- a/tests/modules/plugins/another.py +++ b/tests/modules/plugins/another.py @@ -5,8 +5,10 @@ from coverage import CoveragePlugin + class Plugin(CoveragePlugin): pass + def coverage_init(reg, options): reg.add_file_tracer(Plugin()) diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 5218f6c..686dcf9 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -459,7 +459,7 @@ class GoodPluginTest(FileTracerTest): for snip in [ 'filename="bar_4.html" line-rate="0.5" name="bar_4.html"', 'filename="foo_7.html" line-rate="0.2857" name="foo_7.html"', - ]: + ]: self.assertIn(snip, xml) def test_defer_to_python(self): |
