gnu: Add kafs-client
[jackhill/guix/guix.git] / gnu / packages / patches / python-pydot-regression-test.patch
1 This patch is taken from the upstream repository
2 https://github.com/pydot/pydot/commit/a10ced4d132361027a545a471af4541dea8c5cf5.patch
3 It should be included in the 1.4.2 release.
4
5
6 From a10ced4d132361027a545a471af4541dea8c5cf5 Mon Sep 17 00:00:00 2001
7 From: Peter Nowee <peter@peternowee.com>
8 Date: Wed, 26 Jun 2019 15:43:38 +0800
9 Subject: [PATCH] Fix multi.dot Graphviz regression test
10
11 Commit d6602ad of 2018-12-01 fixed the regression test broken by commit
12 2d55978 of 2016-07-01. This revealed that `test/graphs/multi.dot` was
13 failing.
14
15 `multi.dot` was introduced in commit 2b3f088 of 2010-11-07 together
16 with many of the other tests still here today. It has not been touched
17 since. It is a DOT-file containing two digraphs. The regression test
18 compares the JPEG images rendered from the DOT-file by pydot with those
19 rendered by Graphviz's dot directly.
20
21 Commit 66734d2 of 2016-07-01 is the actual cause of the failure. It
22 changed one of the render methods of the regression test,
23 `_render_with_pydot`, from calculating a single hash for all the JPEG
24 images to calculating separate hashes for each JPEG image and then
25 concatenating those hashes in one long string. The other render method,
26 `_render_with_graphviz`, still calculates a single hash over all data.
27 For DOT-files that generate only one image the end result is the same,
28 but because `multi.dot` has two graphs, it produces two images and this
29 leads to comparing a string of two hashes with one single hash.
30
31 I do not think the change in generating the hash was intentional, for
32 the following reasons:
33 - Commit 66734d2 states that its purpose was to adapt the test to an
34 API change in pydot. It does not mention a deliberate choice to
35 change the testing method.
36 - There was no effort to change `_render_with_graphviz` to also produce
37 multiple hashes.
38 - Except for easier debugging in case of a failing test with multiple
39 images (AFAICT, only `multi.dot`), I do not see much added benefit in
40 checking a concatenation of the hashes of all images vs. checking one
41 hash of all images together: In both cases the test will fail if one
42 or more images is rendered differently.
43 - Given that there were many commits authored that same hour, including
44 commit 2d55978 which broke the regression tests, I suspect the author
45 did not run the tests for each individual commit, but only at the end
46 of that batch, and was therefore also not alerted of this change by
47 the test suite.
48
49 Assuming that the change was not intended, this commit will now revert
50 `_render_with_pydot` to the old behavior of calculating a single hash
51 from all JPEG image data.
52
53 Tested with Debian 9.9, Graphviz 2.38.0-17, Python 2.7.13-2 and 3.5.3-1.
54
55 Fixes https://github.com/pydot/pydot/issues/204.
56 ---
57 test/pydot_unittest.py | 8 ++++----
58 1 file changed, 4 insertions(+), 4 deletions(-)
59
60 diff --git a/test/pydot_unittest.py b/test/pydot_unittest.py
61 index 881ee16..64aa856 100644
62 --- a/test/pydot_unittest.py
63 +++ b/test/pydot_unittest.py
64 @@ -194,11 +194,11 @@ def _render_with_graphviz(self, filename, encoding):
65
66 def _render_with_pydot(self, filename, encoding):
67 c = pydot.graph_from_dot_file(filename, encoding=encoding)
68 - sha = ''
69 + jpe_data = bytearray()
70 for g in c:
71 - jpe_data = g.create(prog=TEST_PROGRAM, format='jpe', encoding=encoding)
72 - sha += sha256(jpe_data).hexdigest()
73 - return sha
74 + jpe_data.extend(g.create(prog=TEST_PROGRAM, format='jpe',
75 + encoding=encoding))
76 + return sha256(jpe_data).hexdigest()
77
78 def test_my_regression_tests(self):
79 path = os.path.join(test_dir, TESTS_DIR_1)