summary refs log tree commit diff
path: root/gnu/packages
diff options
context:
space:
mode:
authorEfraim Flashner <efraim@flashner.co.il>2020-11-23 09:44:57 +0200
committerEfraim Flashner <efraim@flashner.co.il>2020-11-23 15:43:36 +0200
commitb1aac582caee711020c078217c58b15aeeef550e (patch)
treed159b2f8d4cb6844fd25b676fbdf5e97ee030abf /gnu/packages
parent79f3e2618410481d7798a3bd26e0aa97f27a0763 (diff)
downloadguix-b1aac582caee711020c078217c58b15aeeef550e.tar.gz
gnu: python-pydot: Run tests.
* gnu/packges/graphviz.scm (python-pydot)[source]: Add patch.
[arguments]: Override check phase.
[native-inputs]: Add graphviz.
* gnu/packages/patches/python-pydot-regression-test.patch: New file.
* gnu/local.mk (dist_patch_DATA): Register it.
Diffstat (limited to 'gnu/packages')
-rw-r--r--gnu/packages/graphviz.scm18
-rw-r--r--gnu/packages/patches/python-pydot-regression-test.patch79
2 files changed, 95 insertions, 2 deletions
diff --git a/gnu/packages/graphviz.scm b/gnu/packages/graphviz.scm
index bd70c87c9a..86f20bf23f 100644
--- a/gnu/packages/graphviz.scm
+++ b/gnu/packages/graphviz.scm
@@ -32,6 +32,7 @@
   #:use-module (guix download)
   #:use-module (guix git-download)
   #:use-module (guix utils)
+  #:use-module (gnu packages)
   #:use-module (gnu packages autotools)
   #:use-module (gnu packages bison)
   #:use-module (gnu packages check)
@@ -331,11 +332,24 @@ can be used either as a standalone application, or as a Python library.")
        (uri (pypi-uri "pydot" version))
        (sha256
         (base32
-         "00az4cbf8bv447lkk9xi6pjm7gcc7ia33y4pm71fwfwis56rv76l"))))
+         "00az4cbf8bv447lkk9xi6pjm7gcc7ia33y4pm71fwfwis56rv76l"))
+       (patches (search-patches "python-pydot-regression-test.patch"))))
     (build-system python-build-system)
+    (arguments
+     '(#:phases
+       (modify-phases %standard-phases
+         (replace 'check
+           ;; Taken from .travis.yaml
+           (lambda* (#:key tests? inputs outputs #:allow-other-keys)
+             (when tests?
+               (add-installed-pythonpath inputs outputs)
+               (with-directory-excursion "test"
+                 (invoke "python" "pydot_unittest.py")))
+             #t)))))
     (native-inputs
      ;; For tests.
-     `(("python-chardet" ,python-chardet)))
+     `(("graphviz" ,graphviz)
+       ("python-chardet" ,python-chardet)))
     (propagated-inputs
      `(("python-pyparsing" ,python-pyparsing)))
     (home-page "https://github.com/erocarrera/pydot")
diff --git a/gnu/packages/patches/python-pydot-regression-test.patch b/gnu/packages/patches/python-pydot-regression-test.patch
new file mode 100644
index 0000000000..d2f0f5996e
--- /dev/null
+++ b/gnu/packages/patches/python-pydot-regression-test.patch
@@ -0,0 +1,79 @@
+This patch is taken from the upstream repository
+https://github.com/pydot/pydot/commit/a10ced4d132361027a545a471af4541dea8c5cf5.patch
+It should be included in the 1.4.2 release.
+
+
+From a10ced4d132361027a545a471af4541dea8c5cf5 Mon Sep 17 00:00:00 2001
+From: Peter Nowee <peter@peternowee.com>
+Date: Wed, 26 Jun 2019 15:43:38 +0800
+Subject: [PATCH] Fix multi.dot Graphviz regression test
+
+Commit d6602ad of 2018-12-01 fixed the regression test broken by commit
+2d55978 of 2016-07-01. This revealed that `test/graphs/multi.dot` was
+failing.
+
+`multi.dot` was introduced in commit 2b3f088 of 2010-11-07 together
+with many of the other tests still here today. It has not been touched
+since. It is a DOT-file containing two digraphs. The regression test
+compares the JPEG images rendered from the DOT-file by pydot with those
+rendered by Graphviz's dot directly.
+
+Commit 66734d2 of 2016-07-01 is the actual cause of the failure. It
+changed one of the render methods of the regression test,
+`_render_with_pydot`, from calculating a single hash for all the JPEG
+images to calculating separate hashes for each JPEG image and then
+concatenating those hashes in one long string. The other render method,
+`_render_with_graphviz`, still calculates a single hash over all data.
+For DOT-files that generate only one image the end result is the same,
+but because `multi.dot` has two graphs, it produces two images and this
+leads to comparing a string of two hashes with one single hash.
+
+I do not think the change in generating the hash was intentional, for
+the following reasons:
+- Commit 66734d2 states that its purpose was to adapt the test to an
+  API change in pydot. It does not mention a deliberate choice to
+  change the testing method.
+- There was no effort to change `_render_with_graphviz` to also produce
+  multiple hashes.
+- Except for easier debugging in case of a failing test with multiple
+  images (AFAICT, only `multi.dot`), I do not see much added benefit in
+  checking a concatenation of the hashes of all images vs. checking one
+  hash of all images together: In both cases the test will fail if one
+  or more images is rendered differently.
+- Given that there were many commits authored that same hour, including
+  commit 2d55978 which broke the regression tests, I suspect the author
+  did not run the tests for each individual commit, but only at the end
+  of that batch, and was therefore also not alerted of this change by
+  the test suite.
+
+Assuming that the change was not intended, this commit will now revert
+`_render_with_pydot` to the old behavior of calculating a single hash
+from all JPEG image data.
+
+Tested with Debian 9.9, Graphviz 2.38.0-17, Python 2.7.13-2 and 3.5.3-1.
+
+Fixes https://github.com/pydot/pydot/issues/204.
+---
+ test/pydot_unittest.py | 8 ++++----
+ 1 file changed, 4 insertions(+), 4 deletions(-)
+
+diff --git a/test/pydot_unittest.py b/test/pydot_unittest.py
+index 881ee16..64aa856 100644
+--- a/test/pydot_unittest.py
++++ b/test/pydot_unittest.py
+@@ -194,11 +194,11 @@ def _render_with_graphviz(self, filename, encoding):
+ 
+     def _render_with_pydot(self, filename, encoding):
+         c = pydot.graph_from_dot_file(filename, encoding=encoding)
+-        sha = ''
++        jpe_data = bytearray()
+         for g in c:
+-            jpe_data = g.create(prog=TEST_PROGRAM, format='jpe', encoding=encoding)
+-            sha += sha256(jpe_data).hexdigest()
+-        return sha
++            jpe_data.extend(g.create(prog=TEST_PROGRAM, format='jpe',
++                                     encoding=encoding))
++        return sha256(jpe_data).hexdigest()
+ 
+     def test_my_regression_tests(self):
+         path = os.path.join(test_dir, TESTS_DIR_1)