xflr6 / graphviz

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

0.17: pytest is failing #140

Closed kloczek closed 3 years ago

kloczek commented 3 years ago

I'm trying to package your module as rpm packag. So I'm using typical in such case build, install and test cycle used on building package from non-root account:

May I ask for help because few units are failing:

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-graphviz-0.17-3.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-graphviz-0.17-3.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.11, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
benchmark: 3.4.1 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
Using --randomly-seed=2401462028
rootdir: /home/tkloczko/rpmbuild/BUILD/graphviz-0.17, configfile: setup.cfg, testpaths: README.rst, docs, graphviz, tests
plugins: forked-1.3.0, shutil-1.7.0, virtualenv-1.7.0, expect-1.1.0, flake8-1.0.7, timeout-1.4.2, betamax-0.8.1, freezegun-0.4.2, aspectlib-1.5.2, toolbox-0.5, rerunfailures-9.1.1, requests-mock-1.9.3, cov-2.12.1, pyfakefs-4.5.0, flaky-3.7.0, benchmark-3.4.1, xdist-2.3.0, pylama-7.7.1, datadir-1.3.1, regressions-2.2.0, cases-3.6.3, xprocess-0.18.1, black-0.3.12, checkdocs-2.7.1, anyio-3.3.0, Faker-8.11.0, asyncio-0.15.1, trio-0.7.0, httpbin-1.0.0, subtests-0.5.0, isort-2.0.0, hypothesis-6.14.6, mock-3.6.1, profiling-1.7.0, randomly-3.8.0
collected 141 items

tests/test_backend.py .....                                                                                                                                          [  3%]
graphviz/lang.py .                                                                                                                                                   [  4%]
graphviz/backend.py .                                                                                                                                                [  4%]
tests/test_backend.py ..................                                                                                                                             [ 17%]
graphviz/backend.py .                                                                                                                                                [ 18%]
graphviz/tools.py .                                                                                                                                                  [ 19%]
tests/test_backend.py .                                                                                                                                              [ 19%]
README.rst .                                                                                                                                                         [ 20%]
tests/test_backend.py ..                                                                                                                                             [ 21%]
docs/manual.rst .                                                                                                                                                    [ 22%]
tests/test_backend.py .                                                                                                                                              [ 23%]
graphviz/__init__.py .                                                                                                                                               [ 24%]
graphviz/lang.py .                                                                                                                                                   [ 24%]
graphviz/tools.py .                                                                                                                                                  [ 25%]
tests/test_backend.py .....                                                                                                                                          [ 29%]
graphviz/lang.py ..                                                                                                                                                  [ 30%]
tests/test_backend.py .F......                                                                                                                                       [ 36%]
graphviz/lang.py .                                                                                                                                                   [ 36%]
graphviz/dot.py .                                                                                                                                                    [ 37%]
tests/test_backend.py ....                                                                                                                                           [ 40%]
graphviz/lang.py .                                                                                                                                                   [ 41%]
tests/test_backend.py ..                                                                                                                                             [ 42%]
tests/test_files.py ......................                                                                                                                           [ 58%]
tests/test_tools.py ..                                                                                                                                               [ 59%]
tests/test_lang.py .......................                                                                                                                           [ 75%]
tests/test_dot.py ..................................                                                                                                                 [100%]

================================================================================= FAILURES =================================================================================
_________________________________________________________ test_pipe[sfdp-svg-None-None-(?s)^<\\?xml .+</svg>\\s*$] _________________________________________________________

capsys = <_pytest.capture.CaptureFixture object at 0x7fa8f1c3b2b0>, engine = 'sfdp', format_ = 'svg', renderer = None, formatter = None
pattern = '(?s)^<\\?xml .+</svg>\\s*$', data = b'graph { spam }'

    @pytest.mark.exe
    @pytest.mark.parametrize('engine, format_, renderer, formatter, pattern', [
        ('dot', 'svg', None, None, SVG_PATTERN),
        ('dot', 'ps', 'ps', 'core', r'%!PS-'),
        # Error: remove_overlap: Graphviz not built with triangulation library
        pytest.param('sfdp', 'svg', None, None, SVG_PATTERN,
            marks=pytest.mark.xfail('version() > (2, 38, 0)'
                                    " and platform.system().lower() == 'windows'",
            reason='https://gitlab.com/graphviz/graphviz/-/issues/1269')),
    ])
    def test_pipe(capsys, engine, format_, renderer, formatter, pattern,
                  data=b'graph { spam }'):
>       out = pipe(engine, format_, data, renderer, formatter).decode('ascii')

tests/test_backend.py:189:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
graphviz/backend.py:268: in pipe
    out, _ = run(cmd, input=data, capture_output=True, check=True, quiet=quiet)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cmd = ['dot', '-Ksfdp', '-Tsvg'], input = b'graph { spam }', capture_output = True, check = True, encoding = None, quiet = False
kwargs = {'stderr': -1, 'stdin': -1, 'stdout': -1}, proc = <subprocess.Popen object at 0x7fa8f1a92370>
out = b'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"\n "http://www...text-anchor="middle" x="35.75" y="-14.3" font-family="Times,serif" font-size="14.00">spam</text>\n</g>\n</g>\n</svg>\n'
err = b'Error: remove_overlap: Graphviz not built with triangulation library\n', err_encoding = 'UTF-8'

    def run(cmd, input=None,
            capture_output: bool = False,
            check: bool = False,
            encoding: typing.Optional[str] = None,
            quiet: bool = False,
            **kwargs) -> typing.Tuple:
        """Run the command described by cmd and return its ``(stdout, stderr)`` tuple."""
        log.debug('run %r', cmd)

        if input is not None:
            kwargs['stdin'] = subprocess.PIPE
            if encoding is not None:
                input = input.encode(encoding)

        if capture_output:  # Python 3.6 compat
            kwargs['stdout'] = kwargs['stderr'] = subprocess.PIPE

        try:
            proc = subprocess.Popen(cmd, startupinfo=get_startupinfo(), **kwargs)
        except OSError as e:
            if e.errno == errno.ENOENT:
                raise ExecutableNotFound(cmd) from e
            else:
                raise

        out, err = proc.communicate(input)

        if not quiet and err:
            err_encoding = sys.stderr.encoding or sys.getdefaultencoding()
            sys.stderr.write(err.decode(err_encoding))
            sys.stderr.flush()

        if encoding is not None:
            if out is not None:
                out = out.decode(encoding)
            if err is not None:
                err = err.decode(encoding)

        if check and proc.returncode:
>           raise CalledProcessError(proc.returncode, cmd,
                                     output=out, stderr=err)
E           graphviz.backend.CalledProcessError: Command '['dot', '-Ksfdp', '-Tsvg']' returned non-zero exit status 1. [stderr: b'Error: remove_overlap: Graphviz not built with triangulation library\n']

graphviz/backend.py:191: CalledProcessError
---------------------------------------------------------------------------- Captured log setup ----------------------------------------------------------------------------
DEBUG    graphviz.backend:backend.py:159 run ['dot', '-V']
--------------------------------------------------------------------------- Captured stderr call ---------------------------------------------------------------------------
Error: remove_overlap: Graphviz not built with triangulation library
---------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------
DEBUG    graphviz.backend:backend.py:159 run ['dot', '-V']
DEBUG    graphviz.backend:backend.py:159 run ['dot', '-Ksfdp', '-Tsvg']
DEBUG    graphviz.backend:backend.py:159 run ['dot', '-V']

---------- coverage: platform linux, python 3.8.11-final-0 -----------
Name                   Stmts   Miss  Cover
------------------------------------------
graphviz/__init__.py      17      0   100%
graphviz/backend.py      131      0   100%
graphviz/dot.py          116      0   100%
graphviz/files.py        138      0   100%
graphviz/lang.py          49      0   100%
graphviz/tools.py         18      0   100%
------------------------------------------
TOTAL                    469      0   100%
Coverage HTML written to dir htmlcov

========================================================================= short test summary info ==========================================================================
FAILED tests/test_backend.py::test_pipe[sfdp-svg-None-None-(?s)^<\\?xml .+</svg>\\s*$] - graphviz.backend.CalledProcessError: Command '['dot', '-Ksfdp', '-Tsvg']' return...
====================================================================== 1 failed, 140 passed in 3.56s =======================================================================
kloczek commented 3 years ago

Just checked build logs of my graphviz 2.48.0 package and I don't see anything about triangulation library

graphviz-2.48.0 will be compiled with the following:

options:
  cgraph:        Yes (always enabled)
  digcola:       Yes
  expat:         Yes
  fontconfig:    Yes
  freetype:      Yes
  glut:          Yes
  ann:           Yes
  gts:           No (disabled)
  ipsepcola:     Yes
  ltdl:          Yes
  ortho:         Yes
  sfdp:          Yes
  swig:          Yes ( 4.0.1 )
  shared:        Yes
  static:        No (disabled by default)
  qt:            Yes
  x:             Yes

commands:
  dot:           Yes (always enabled)
  neato:         Yes (always enabled)
  fdp:           Yes (always enabled)
  circo:         Yes (always enabled)
  twopi:         Yes (always enabled)
  gvpr:          Yes (always enabled)
  gvmap:         Yes (always enabled)
  lefty:         Yes
  smyrna:        No (requires: gtk+ gtkglext glade gts)
  gvedit:        Yes

plugin libraries:
  dot_layout:    Yes (always enabled)
  neato_layout:  Yes (always enabled)
  core:          Yes (always enabled)
  devil:         No (disabled)
  gd:            Yes
  gdiplus:       No (disabled by default - Windows only)
  gdk:
  gdk_pixbuf:    Yes
  ghostscript:   Yes
  glitz:         No (disabled by default - incomplete)
  gtk:           No (gtk library not available)
  lasi:          Yes
  ming:          No (disabled by default - incomplete)
  pangocairo:    Yes
  poppler:       Yes
  quartz:        No (disabled by default - Mac only)
  rsvg:          Yes
  visio:         Yes
  webp:          Yes
  xlib:          Yes

language extensions:
  gv_sharp:      No (disabled)
  gv_d:          No (disabled by default - incomplete
  gv_go:         Yes
  gv_guile:      Yes
  gv_io:         No (disabled by default - no swig support yet)
  gv_java:       Yes
  gv_javascript: No (disabled by default - incomplete
  gv_lua:        Yes
  gv_ocaml:      Yes
  gv_perl:       Yes
  gv_php:        No (disabled)
  gv_python:     Yes
  gv_python3:    Yes
  gv_R:          No (disabled)
  gv_ruby:       No (disabled)
  gv_tcl:        Yes

  tcldot:        Yes
  tclpathplan:   Yes
  gdtclft:       Yes

Testing utilities:
  criterion:     No (Criterion unit testing framework not installed)
xflr6 commented 3 years ago

Thanks (and sorry for the late response).

For the Windows build of (upstream) Graphviz, there is a known/open upstream issue that sfdp stopped working after version 2.38 due to the missing dependency you point out; but as you build on Linux (and the test at hand does pass e.g. on Ubuntu) this might be slightly different:

https://github.com/xflr6/graphviz/blob/b737195649e0d73df33f68c4709b32406868015c/tests/test_backend.py#L181-L185

build logs of my graphviz 2.48.0 package

I suspect what you see indicates an issue with your local Graphviz build (dependencies). I would propose to try to seek help from the upstream build instructions at https://www.graphviz.org/download/source/ and/or upstream https://forum.graphviz.org (I have no experience with building it), HTH.

kloczek commented 3 years ago

Reported issue is not about graphviz build issue. It is about testing graphviz python module using pytest.

xflr6 commented 3 years ago

I understand. My understanding is that this test fails because the dot binary you are using is missing a dependency (triangulation library for sfdp renderer). In other words the test failiure does not indicate an issue inside this package but with your environment/versions/setup.