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