| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6c24cfe commit af31c62
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -781,6 +781,7 @@ def test_plot(self): | |||
| 781 | 781 | ||
| 782 | 782 | def test_dotfile(self): | |
| 783 | 783 | import pathlib | |
| 784 | + import unittest.mock | ||
| 784 | 785 | ||
| 785 | 786 | g = UGraph() | |
| 786 | 787 | v1 = g.add_vertex(coord=[0,0], name='v1') | |
@@ -795,7 +796,17 @@ def test_dotfile(self): | |||
| 795 | 796 | g.dotfile(str(path)) | |
| 796 | 797 | self.assertTrue(path.is_file()) | |
| 797 | 798 | ||
| 798 | - g.showgraph() | ||
| 799 | + # showgraph() pops a PDF up in a browser via webbrowser.open() -- | ||
| 800 | + # mock that so the test runs headless, but still exercise the real | ||
| 801 | + # dot->PDF rendering and check the result is an actual PDF file. | ||
| 802 | + with unittest.mock.patch('pgraph.PGraph.webbrowser.open') as mock_open: | ||
| 803 | + g.showgraph() | ||
| 804 | + | ||
| 805 | + mock_open.assert_called_once() | ||
| 806 | + pdf_url = mock_open.call_args[0][0] | ||
| 807 | + pdf_path = pathlib.Path(pdf_url.removeprefix('file://')) | ||
| 808 | + self.assertTrue(pdf_path.is_file()) | ||
| 809 | + self.assertEqual(pdf_path.read_bytes()[:5], b'%PDF-') | ||
| 799 | 810 | ||
| 800 | 811 | class TestDGraph(unittest.TestCase): | |
| 801 | 812 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments