diff options
-rw-r--r-- | coverage/backward.py | 17 | ||||
-rw-r--r-- | coverage/collector.py | 11 | ||||
-rw-r--r-- | coverage/pytracer.py | 2 | ||||
-rw-r--r-- | coverage/test_helpers.py | 10 | ||||
-rw-r--r-- | igor.py | 1 | ||||
-rw-r--r-- | tests/test_oddball.py | 66 | ||||
-rw-r--r-- | tests/test_process.py | 3 |
7 files changed, 41 insertions, 69 deletions
diff --git a/coverage/backward.py b/coverage/backward.py index 11f8e00..9597449 100644 --- a/coverage/backward.py +++ b/coverage/backward.py @@ -50,22 +50,7 @@ else: if sys.version_info >= (3, 0): # Python 3.2 provides `tokenize.open`, the best way to open source files. import tokenize - try: - open_python_source = tokenize.open # pylint: disable=E1101 - except AttributeError: - from io import TextIOWrapper - detect_encoding = tokenize.detect_encoding # pylint: disable=E1101 - # Copied from the 3.2 stdlib: - def open_python_source(fname): - """Open a file in read only mode using the encoding detected by - detect_encoding(). - """ - buffer = open(fname, 'rb') - encoding, _ = detect_encoding(buffer.readline) - buffer.seek(0) - text = TextIOWrapper(buffer, encoding, line_buffering=True) - text.mode = 'r' - return text + open_python_source = tokenize.open # pylint: disable=E1101 else: def open_python_source(fname): """Open a source file the best way.""" diff --git a/coverage/collector.py b/coverage/collector.py index dccd797..8ff4db2 100644 --- a/coverage/collector.py +++ b/coverage/collector.py @@ -196,12 +196,11 @@ class Collector(object): # Check to see whether we had a fullcoverage tracer installed. traces0 = [] - if hasattr(sys, "gettrace"): - fn0 = sys.gettrace() - if fn0: - tracer0 = getattr(fn0, '__self__', None) - if tracer0: - traces0 = getattr(tracer0, 'traces', []) + fn0 = sys.gettrace() + if fn0: + tracer0 = getattr(fn0, '__self__', None) + if tracer0: + traces0 = getattr(tracer0, 'traces', []) # Install the tracer on this thread. fn = self._start_tracer() diff --git a/coverage/pytracer.py b/coverage/pytracer.py index a82b32c..7563ae1 100644 --- a/coverage/pytracer.py +++ b/coverage/pytracer.py @@ -151,7 +151,7 @@ class PyTracer(object): # do any more tracing. return - if hasattr(sys, "gettrace") and self.warn: + if self.warn: if sys.gettrace() != self._trace: msg = "Trace function changed, measurement is likely wrong: %r" self.warn(msg % (sys.gettrace(),)) diff --git a/coverage/test_helpers.py b/coverage/test_helpers.py index 1bc1704..efe68dc 100644 --- a/coverage/test_helpers.py +++ b/coverage/test_helpers.py @@ -90,16 +90,6 @@ class EnvironmentAwareMixin(TestCase): self.environ_undos[name] = os.environ.get(name) os.environ[name] = value - def original_environ(self, name, if_missing=None): - """The environment variable `name` from when the test started.""" - if name in self.environ_undos: - ret = self.environ_undos[name] - else: - ret = os.environ.get(name) - if ret is None: - ret = if_missing - return ret - def cleanup_environ(self): """Undo all the changes made by `set_environ`.""" for name, value in self.environ_undos.items(): @@ -80,6 +80,7 @@ def run_tests_with_coverage(tracer, *nose_args): # if we clobber the cover_prefix in the coverage object, we can defeat the # self-detection. cov.cover_prefix = "Please measure coverage.py!" + cov._warn_unimported_source = False cov.erase() cov.start() diff --git a/tests/test_oddball.py b/tests/test_oddball.py index 786ede9..47f492f 100644 --- a/tests/test_oddball.py +++ b/tests/test_oddball.py @@ -116,9 +116,8 @@ class RecursionTest(CoverageTest): self.assertEqual(statements, [1,2,3,5,7,8,9,10,11]) self.assertEqual(missing, expected_missing) - # We can get a warning about the stackoverflow effect on the tracing - # function only if we have sys.gettrace - if pytrace and hasattr(sys, "gettrace"): + # Get a warning about the stackoverflow effect on the tracing function. + if pytrace: self.assertEqual(cov._warnings, ["Trace function changed, measurement is likely wrong: None"] ) @@ -368,35 +367,34 @@ class DoctestTest(CoverageTest): [1,11,12,14,16,17], "") -if hasattr(sys, 'gettrace'): - class GettraceTest(CoverageTest): - """Tests that we work properly with `sys.gettrace()`.""" - def test_round_trip(self): - self.check_coverage('''\ - import sys - def foo(n): - return 3*n - def bar(n): - return 5*n - a = foo(6) +class GettraceTest(CoverageTest): + """Tests that we work properly with `sys.gettrace()`.""" + def test_round_trip(self): + self.check_coverage('''\ + import sys + def foo(n): + return 3*n + def bar(n): + return 5*n + a = foo(6) + sys.settrace(sys.gettrace()) + a = bar(8) + ''', + [1,2,3,4,5,6,7,8], "") + + def test_multi_layers(self): + self.check_coverage('''\ + import sys + def level1(): + a = 3 + level2() + b = 5 + def level2(): + c = 7 sys.settrace(sys.gettrace()) - a = bar(8) - ''', - [1,2,3,4,5,6,7,8], "") - - def test_multi_layers(self): - self.check_coverage('''\ - import sys - def level1(): - a = 3 - level2() - b = 5 - def level2(): - c = 7 - sys.settrace(sys.gettrace()) - d = 9 - e = 10 - level1() - f = 12 - ''', - [1,2,3,4,5,6,7,8,9,10,11,12], "") + d = 9 + e = 10 + level1() + f = 12 + ''', + [1,2,3,4,5,6,7,8,9,10,11,12], "") diff --git a/tests/test_process.py b/tests/test_process.py index d831498..3a0980d 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -470,8 +470,7 @@ class ProcessTest(CoverageTest): self.assertIn("Hello\n", out) self.assertIn("Goodbye\n", out) - if hasattr(sys, "gettrace"): - self.assertIn("Trace function changed", out) + self.assertIn("Trace function changed", out) if sys.version_info >= (3, 0): # This only works on 3.x for now. # It only works with the C tracer, |