File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222 run : |
2323 python -m pip install --upgrade pip
2424 pip install .[dev]
25+ sudo apt-get update
26+ sudo apt-get install -y graphviz
2527 - name : Test with pytest
2628 run : pytest
2729
5961 run : |
6062 python -m pip install --upgrade pip
6163 pip install -e .[dev]
64+ sudo apt-get update
65+ sudo apt-get install -y graphviz
6266 - name : Run coverage
6367 run : |
6468 pytest --cov=pgraph --cov-report=xml:coverage.xml
Original file line number Diff line number Diff line change @@ -781,6 +781,7 @@ def test_plot(self):
781781
782782 def test_dotfile (self ):
783783 import pathlib
784+ import unittest .mock
784785
785786 g = UGraph ()
786787 v1 = g .add_vertex (coord = [0 ,0 ], name = 'v1' )
@@ -795,7 +796,17 @@ def test_dotfile(self):
795796 g .dotfile (str (path ))
796797 self .assertTrue (path .is_file ())
797798
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-' )
799810
800811class TestDGraph (unittest .TestCase ):
801812
You can’t perform that action at this time.
0 commit comments