xflr6 / graphviz

Simple Python interface for Graphviz
https://graphviz.readthedocs.io
MIT License
1.59k stars 209 forks source link

`graphviz-5.0.1` fails `tests/backend/test_rendering.py::test_render[dot-plain-dot-core-core.dot.plain]` test #178

Closed trofi closed 1 year ago

trofi commented 1 year ago

NixOS recently updated graphviz from 5.0.0 to 5.0.1. This caused one test to fail on graphviz-0.20.1 https://github.com/NixOS/nixpkgs/pull/188175#issuecomment-1228962452 :

python3.10-graphviz> =================================== FAILURES ===================================
python3.10-graphviz> ________________ test_render[dot-plain-dot-core-core.dot.plain] ________________
python3.10-graphviz> capsys = <_pytest.capture.CaptureFixture object at 0x7ffff5c2fb50>
python3.10-graphviz> tmp_path = PosixPath('/build/pytest-of-nixbld/pytest-0/test_render_dot_plain_dot_core0')
python3.10-graphviz> engine = 'dot', format_ = 'plain', renderer = 'dot', formatter = 'core'
python3.10-graphviz> expected_suffix = 'core.dot.plain', filename = 'hello.gv'
python3.10-graphviz> data = b'digraph { hello -> world }'
python3.10-graphviz>     @pytest.mark.exe
python3.10-graphviz>     @pytest.mark.parametrize(
python3.10-graphviz>         'format_, renderer, formatter, expected_suffix',
python3.10-graphviz>         [('pdf', None, None, 'pdf'),
python3.10-graphviz>          ('plain', 'dot', 'core', 'core.dot.plain')])
python3.10-graphviz>     @pytest.mark.parametrize('engine', ['dot'])
python3.10-graphviz>     def test_render(capsys, tmp_path, engine, format_, renderer, formatter,
python3.10-graphviz>                     expected_suffix, filename='hello.gv',
python3.10-graphviz>                     data=b'digraph { hello -> world }'):
python3.10-graphviz>         lpath = tmp_path / filename
python3.10-graphviz>         assert lpath.write_bytes(data) == len(data) == lpath.stat().st_size
python3.10-graphviz>         rendered = lpath.with_suffix(f'{lpath.suffix}.{expected_suffix}')
python3.10-graphviz>         with pytest.deprecated_call():
python3.10-graphviz>             result = graphviz.render(engine, format_, str(lpath),
python3.10-graphviz>                                      renderer, formatter)
python3.10-graphviz>         assert result == str(rendered)
python3.10-graphviz> >       assert rendered.stat().st_size
python3.10-graphviz> tests/backend/test_rendering.py:62:
python3.10-graphviz> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
python3.10-graphviz> self = PosixPath('/build/pytest-of-nixbld/pytest-0/test_render_dot_plain_dot_core0/hello.gv.core.dot.plain')
python3.10-graphviz>     def stat(self, *, follow_symlinks=True):
python3.10-graphviz>         """
python3.10-graphviz>         Return the result of the stat() system call on this path, like
python3.10-graphviz>         os.stat() does.
python3.10-graphviz>         """
python3.10-graphviz> >       return self._accessor.stat(self, follow_symlinks=follow_symlinks)
python3.10-graphviz> E       FileNotFoundError: [Errno 2] No such file or directory: '/build/pytest-of-nixbld/pytest-0/test_render_dot_plain_dot_core0/hello.gv.core.dot.plain'
python3.10-graphviz> /nix/store/sz0j8k8ljh7y8qgyfxgqb3ws11bcy4gs-python3-3.10.6/lib/python3.10/pathlib.py:1097: FileNotFoundError
python3.10-graphviz> ------------------------------ Captured log call -------------------------------
python3.10-graphviz> DEBUG    graphviz.backend.execute:execute.py:61 run [PosixPath('/nix/store/rhgy5ylsbqy3s2bihd4mizkm9829ndin-graphviz-5.0.1/bin/dot'), '-Kdot', '-Tplain:dot:core', '-O', 'hello.gv']
python3.10-graphviz> ============================= slowest 10 durations =============================
python3.10-graphviz> 0.03s setup    tests/backend/test_viewing.py::test_view_mocked[platform='linux'-quiet=False]
python3.10-graphviz> 0.02s call     graphviz/jupyter_integration.py::graphviz.jupyter_integration.JupyterIntegration._repr_mimebundle_
python3.10-graphviz> 0.02s call     graphviz/backend/rendering.py::graphviz.backend.rendering.render
python3.10-graphviz> 0.02s call     graphviz/piping.py::graphviz.piping.Pipe.pipe
python3.10-graphviz> 0.02s call     docs/piped_output.rst::piped_output.rst
python3.10-graphviz> 0.02s call     tests/backend/test_piping.py::test_pipe[sfdp-svg-None-None-(?s)^<\\?xml .+</svg>\\s*$]
python3.10-graphviz> 0.02s teardown tests/backend/test_viewing.py::test_view_mocked[platform='windows'-quiet=True]
python3.10-graphviz> 0.01s call     README.rst::README.rst
python3.10-graphviz> 0.01s setup    tests/backend/test_viewing.py::test_view_mocked[platform='freebsd'-quiet=True]
python3.10-graphviz> 0.01s setup    tests/backend/test_piping.py::test_pipe_lines_mocked[quiet=True]
python3.10-graphviz> =========================== short test summary info ============================
python3.10-graphviz> FAILED tests/backend/test_rendering.py::test_render[dot-plain-dot-core-core.dot.plain]
python3.10-graphviz> SKIPPED [4] tests/backend/test_execute.py:18: empty $PATH has no effect
python3.10-graphviz> =================== 1 failed, 361 passed, 4 skipped in 1.32s ===================

I bisected graphviz and found https://gitlab.com/graphviz/graphviz/-/commit/4291cc769a3eeef8b1c171e5479194733a4da6cd to be the trigger.

xflr6 commented 1 year ago

Thanks so much for the detailed report.

Looks like the behavior was changed unintendetly upstream. Possibly unrecognized due to lack of test coverage.

Opened upstream https://gitlab.com/graphviz/graphviz/-/issues/2270 for this.

Smattr commented 1 year ago

Indeed it is an upstream bug. And you're right about poor test coverage being the indirect cause. The fix will go into the next release, 6.0.0.

xflr6 commented 1 year ago

Thanks for the quick fix. Closing (upstream bug to be fixed in 6.0.0 release).