ยปCore Development>Code coverage>Lib/test/test_tools/test_gprof2html.py

Python code coverage for Lib/test/test_tools/test_gprof2html.py

#countcontent
1n/a"""Tests for the gprof2html script in the Tools directory."""
2n/a
3n/aimport os
4n/aimport sys
5n/aimport unittest
6n/afrom unittest import mock
7n/aimport tempfile
8n/a
9n/afrom test.test_tools import skip_if_missing, import_tool
10n/a
11n/askip_if_missing()
12n/a
13n/aclass Gprof2htmlTests(unittest.TestCase):
14n/a
15n/a def setUp(self):
16n/a self.gprof = import_tool('gprof2html')
17n/a oldargv = sys.argv
18n/a def fixup():
19n/a sys.argv = oldargv
20n/a self.addCleanup(fixup)
21n/a sys.argv = []
22n/a
23n/a def test_gprof(self):
24n/a # Issue #14508: this used to fail with a NameError.
25n/a with mock.patch.object(self.gprof, 'webbrowser') as wmock, \
26n/a tempfile.TemporaryDirectory() as tmpdir:
27n/a fn = os.path.join(tmpdir, 'abc')
28n/a open(fn, 'w').close()
29n/a sys.argv = ['gprof2html', fn]
30n/a self.gprof.main()
31n/a self.assertTrue(wmock.open.called)
32n/a
33n/a
34n/aif __name__ == '__main__':
35n/a unittest.main()