110 In your ``coverage_init`` function, use the ``add_dynamic_context`` method to |
110 In your ``coverage_init`` function, use the ``add_dynamic_context`` method to |
111 register your dynamic context switcher. |
111 register your dynamic context switcher. |
112 |
112 |
113 """ |
113 """ |
114 |
114 |
|
115 import functools |
|
116 |
115 from coverage import files |
117 from coverage import files |
116 from coverage.misc import contract, _needs_to_implement |
118 from coverage.misc import contract, _needs_to_implement |
117 |
119 |
118 |
120 |
119 class CoveragePlugin: |
121 class CoveragePlugin: |
313 """ |
315 """ |
314 lineno = frame.f_lineno |
316 lineno = frame.f_lineno |
315 return lineno, lineno |
317 return lineno, lineno |
316 |
318 |
317 |
319 |
|
320 @functools.total_ordering |
318 class FileReporter: |
321 class FileReporter: |
319 """Support needed for files during the analysis and reporting phases. |
322 """Support needed for files during the analysis and reporting phases. |
320 |
323 |
321 File tracer plug-ins implement a subclass of `FileReporter`, and return |
324 File tracer plug-ins implement a subclass of `FileReporter`, and return |
322 instances from their :meth:`CoveragePlugin.file_reporter` method. |
325 instances from their :meth:`CoveragePlugin.file_reporter` method. |
507 |
510 |
508 """ |
511 """ |
509 for line in self.source().splitlines(): |
512 for line in self.source().splitlines(): |
510 yield [('txt', line)] |
513 yield [('txt', line)] |
511 |
514 |
512 # Annoying comparison operators. Py3k wants __lt__ etc, and Py2k needs all |
|
513 # of them defined. |
|
514 |
|
515 def __eq__(self, other): |
515 def __eq__(self, other): |
516 return isinstance(other, FileReporter) and self.filename == other.filename |
516 return isinstance(other, FileReporter) and self.filename == other.filename |
517 |
517 |
518 def __ne__(self, other): |
|
519 return not (self == other) |
|
520 |
|
521 def __lt__(self, other): |
518 def __lt__(self, other): |
522 return self.filename < other.filename |
519 return isinstance(other, FileReporter) and self.filename < other.filename |
523 |
|
524 def __le__(self, other): |
|
525 return self.filename <= other.filename |
|
526 |
|
527 def __gt__(self, other): |
|
528 return self.filename > other.filename |
|
529 |
|
530 def __ge__(self, other): |
|
531 return self.filename >= other.filename |
|
532 |
520 |
533 __hash__ = None # This object doesn't need to be hashed. |
521 __hash__ = None # This object doesn't need to be hashed. |