1"""Tests for the gprof2html script in the Tools directory.""" 2 3import os 4import sys 5import unittest 6from unittest import mock 7import tempfile 8 9from test.test_tools import skip_if_missing, import_tool 10 11skip_if_missing() 12 13class Gprof2htmlTests(unittest.TestCase): 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, 'w').close() 29 sys.argv = ['gprof2html', fn] 30 self.gprof.main() 31 self.assertTrue(wmock.open.called) 32 33 34if __name__ == '__main__': 35 unittest.main() 36