diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py --- a/Lib/test/test_trace.py +++ b/Lib/test/test_trace.py @@ -1,13 +1,15 @@ import os import sys from test.support import (run_unittest, TESTFN, rmtree, unlink, captured_stdout) +import tempfile import unittest +import warnings import trace from trace import CoverageResults, Trace from test.tracedmodules import testmod #------------------------------- Utilities -----------------------------------# @@ -356,14 +358,55 @@ class Test_Ignore(unittest.TestCase): self.assertFalse(ignore.names('xy.py', 'xy')) self.assertFalse(ignore.names('y.py', 'y')) self.assertTrue(ignore.names(jn('foo', 'bar', 'baz.py'), 'baz')) self.assertFalse(ignore.names(jn('bar', 'z.py'), 'z')) # Matched before. self.assertTrue(ignore.names(jn('bar', 'baz.py'), 'baz')) +class TestDeprecatedMethods(unittest.TestCase): + + def test_deprecated_usage(self): + with self.assertWarns(DeprecationWarning): + trace.usage(sys.stderr) + + def test_deprecated_Ignore(self): + with self.assertWarns(DeprecationWarning): + trace.Ignore() + + def test_deprecated_modname(self): + with self.assertWarns(DeprecationWarning): + self.assertEqual("spam", trace.modname("spam")) + + def test_deprecated_fullmodname(self): + with self.assertWarns(DeprecationWarning): + self.assertEqual("spam", trace.fullmodname("spam")) + + def test_deprecated_find_lines_from_code(self): + with self.assertWarns(DeprecationWarning): + def foo(): + pass + trace.find_lines_from_code(foo.__code__, ["eggs"]) + + def test_deprecated_find_lines(self): + with self.assertWarns(DeprecationWarning): + def foo(): + pass + trace.find_lines(foo.__code__, ["eggs"]) + + def test_deprecated_find_strings(self): + with self.assertWarns(DeprecationWarning): + with tempfile.NamedTemporaryFile() as fd: + trace.find_strings(fd.name) + + def test_deprecated_find_executable_linenos(self): + with self.assertWarns(DeprecationWarning): + with tempfile.NamedTemporaryFile() as fd: + trace.find_executable_linenos(fd.name) + + def test_main(): run_unittest(__name__) if __name__ == '__main__': test_main() diff --git a/Lib/trace.py b/Lib/trace.py --- a/Lib/trace.py +++ b/Lib/trace.py @@ -53,16 +53,17 @@ import os import re import sys import token import tokenize import inspect import gc import dis import pickle +from warnings import warn as _warn try: from time import monotonic as _time except ImportError: from time import time as _time try: import threading except ImportError: