diff options
-rw-r--r-- | .pylintrc | 5 | ||||
-rw-r--r-- | coverage/__init__.py | 12 | ||||
-rw-r--r-- | coverage/cmdline.py | 1 | ||||
-rw-r--r-- | coverage/collector.py | 12 | ||||
-rw-r--r-- | test/test_templite.py | 21 |
5 files changed, 29 insertions, 22 deletions
@@ -55,10 +55,11 @@ load-plugins= # Disable the message(s) with the given id(s). # Messages that are just silly: # I0011:106: Locally disabling E1101 -# W0603: 28:call_singleton_method: Using the global statement # W0142: 31:call_singleton_method: Used * or ** magic +# W0232: 6:AnyOldObject: Class has no __init__ method # C0323:311:coverage.report: Operator not followed by a space # C0324: 15: Comma not followed by a space +# W0603: 28:call_singleton_method: Using the global statement # Messages that may be silly: # R0201: 42:Tracer.stop: Method could be a function # W0403: 4: Relative import 'coveragetest' @@ -66,7 +67,7 @@ load-plugins= # Messages that are noisy for now, eventually maybe we'll turn them on: # C0111:169:coverage.analyze_morf: Missing docstring # C0103:256:coverage.morf_filename: Invalid name "f" (should match [a-z_][a-z0-9_]{2,30}$) -disable-msg=I0011,W0603,W0142,C0323,C0324, R0201,W0403,E1103, C0111,C0103 +disable-msg=I0011,W0142,W0232,C0323,C0324,W0603, R0201,W0403,E1103, C0111,C0103 [REPORTS] diff --git a/coverage/__init__.py b/coverage/__init__.py index 826c67de..09b1567b 100644 --- a/coverage/__init__.py +++ b/coverage/__init__.py @@ -17,18 +17,18 @@ from coverage.misc import CoverageException # Module-level functions. The original API to this module was based on # functions defined directly in the module, with a singleton of the coverage() -# class. This design hampered programmability. Here we define the top-level +# class. That design hampered programmability. Here we define the top-level # functions to create the singleton when they are first called. # Singleton object for use with module-level functions. The singleton is # created as needed when one of the module-level functions is called. -the_coverage = None +_the_coverage = None def call_singleton_method(name, args, kwargs): - global the_coverage - if not the_coverage: - the_coverage = coverage() - return getattr(the_coverage, name)(*args, **kwargs) + global _the_coverage + if not _the_coverage: + _the_coverage = coverage() + return getattr(_the_coverage, name)(*args, **kwargs) mod_funcs = """ use_cache start stop erase exclude diff --git a/coverage/cmdline.py b/coverage/cmdline.py index 6086c62d..89d0b270 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -58,6 +58,7 @@ class CoverageScript: def __init__(self): import coverage self.covpkg = coverage + self.coverage = None def help(self, error=None): """Display an error message, or the usage for Coverage.""" diff --git a/coverage/collector.py b/coverage/collector.py index f9bb3177..b6ca19bd 100644 --- a/coverage/collector.py +++ b/coverage/collector.py @@ -128,7 +128,7 @@ class Collector: def start(self): """Start collecting trace information.""" if self._collectors: - self._collectors[-1]._pause() + self._collectors[-1].pause() self._collectors.append(self) # Install the tracer on this thread. self._start_tracer() @@ -150,16 +150,16 @@ class Collector: # (if any). self._collectors.pop() if self._collectors: - self._collectors[-1]._resume() + self._collectors[-1].resume() - def _pause(self): - """Stop tracing, but be prepared to _resume.""" + def pause(self): + """Pause tracing, but be prepared to `resume`.""" for tracer in self.tracers: tracer.stop() threading.settrace(None) - def _resume(self): - """Resume tracing after a _pause.""" + def resume(self): + """Resume tracing after a `pause`.""" for tracer in self.tracers: tracer.start() threading.settrace(self._installation_trace) diff --git a/test/test_templite.py b/test/test_templite.py index fd7a3393..436951af 100644 --- a/test/test_templite.py +++ b/test/test_templite.py @@ -3,8 +3,16 @@ from coverage.templite import Templite import unittest -class AnyOldObject: - pass +class AnyOldObject(object): + """Simple testing object. + + Use keyword arguments in the constructor to set attributes on the object. + + """ + def __init__(self, **attrs): + for n, v in attrs.items(): + setattr(self, n, v) + class TemplateTest(unittest.TestCase): @@ -48,18 +56,15 @@ class TemplateTest(unittest.TestCase): def test_attribute(self): # Variables' attributes can be accessed with dots. - obj = AnyOldObject() - obj.a = "Ay" + obj = AnyOldObject(a="Ay") self.try_render("{{obj.a}}", locals(), "Ay") - obj2 = AnyOldObject() - obj2.obj = obj - obj2.b = "Bee" + obj2 = AnyOldObject(obj=obj, b="Bee") self.try_render("{{obj2.obj.a}} {{obj2.b}}", locals(), "Ay Bee") def test_member_function(self): # Variables' member functions can be used, as long as they are nullary. - class WithMemberFns: + class WithMemberFns(object): def ditto(self): return self.txt + self.txt obj = WithMemberFns() |