diff options
Diffstat (limited to 'Lib/test/test_tools.py')
| -rw-r--r-- | Lib/test/test_tools.py | 36 | 
1 files changed, 33 insertions, 3 deletions
| diff --git a/Lib/test/test_tools.py b/Lib/test/test_tools.py index cfe13ac..cbe6d80 100644 --- a/Lib/test/test_tools.py +++ b/Lib/test/test_tools.py @@ -6,8 +6,9 @@ Tools directory of a Python checkout or tarball, such as reindent.py.  import os  import sys -import imp +import importlib.machinery  import unittest +from unittest import mock  import sysconfig  import tempfile  from test import support @@ -40,7 +41,7 @@ class TestSundryScripts(unittest.TestCase):      # added for a script it should be added to the whitelist below.      # scripts that have independent tests. -    whitelist = ['reindent.py'] +    whitelist = ['reindent.py', 'pdeps.py', 'gprof2html']      # scripts that can't be imported without running      blacklist = ['make_ctype.py']      # scripts that use windows-only modules @@ -79,7 +80,8 @@ class PdepsTests(unittest.TestCase):      @classmethod      def setUpClass(self):          path = os.path.join(scriptsdir, 'pdeps.py') -        self.pdeps = imp.load_source('pdeps', path) +        loader = importlib.machinery.SourceFileLoader('pdeps', path) +        self.pdeps = loader.load_module()      @classmethod      def tearDownClass(self): @@ -99,6 +101,34 @@ class PdepsTests(unittest.TestCase):          self.pdeps.inverse({'a': []}) +class Gprof2htmlTests(unittest.TestCase): + +    def setUp(self): +        path = os.path.join(scriptsdir, 'gprof2html.py') +        loader = importlib.machinery.SourceFileLoader('gprof2html', path) +        self.gprof = loader.load_module() +        oldargv = sys.argv +        def fixup(): +            sys.argv = oldargv +        self.addCleanup(fixup) +        sys.argv = [] + +    def test_gprof(self): +        # Issue #14508: this used to fail with an NameError. +        with mock.patch.object(self.gprof, 'webbrowser') as wmock, \ +                tempfile.TemporaryDirectory() as tmpdir: +            fn = os.path.join(tmpdir, 'abc') +            open(fn, 'w').close() +            sys.argv = ['gprof2html', fn] +            self.gprof.main() +        self.assertTrue(wmock.open.called) + + +# Run the tests in Tools/parser/test_unparse.py +with support.DirsOnSysPath(os.path.join(basepath, 'parser')): +    from test_unparse import UnparseTestCase + +  def test_main():      support.run_unittest(*[obj for obj in globals().values()                                 if isinstance(obj, type)]) | 
