(root)/
Python-3.11.7/
Lib/
test/
test_tools/
test_gprof2html.py
       1  """Tests for the gprof2html script in the Tools directory."""
       2  
       3  import os
       4  import sys
       5  import unittest
       6  from unittest import mock
       7  import tempfile
       8  
       9  from test.test_tools import skip_if_missing, import_tool
      10  
      11  skip_if_missing()
      12  
      13  class ESC[4;38;5;81mGprof2htmlTests(ESC[4;38;5;149munittestESC[4;38;5;149m.ESC[4;38;5;149mTestCase):
      14  
      15      def setUp(self):
      16          self.gprof = import_tool('gprof2html')
      17          oldargv = sys.argv
      18          def fixup():
      19              sys.argv = oldargv
      20          self.addCleanup(fixup)
      21          sys.argv = []
      22  
      23      def test_gprof(self):
      24          # Issue #14508: this used to fail with a NameError.
      25          with mock.patch.object(self.gprof, 'webbrowser') as wmock, \
      26                  tempfile.TemporaryDirectory() as tmpdir:
      27              fn = os.path.join(tmpdir, 'abc')
      28              open(fn, 'wb').close()
      29              sys.argv = ['gprof2html', fn]
      30              self.gprof.main()
      31          self.assertTrue(wmock.open.called)
      32  
      33  
      34  if __name__ == '__main__':
      35      unittest.main()