Subject: [PATCH v2] testing/py3-cairosvg: upgrade to 2.4.1

From: Drew DeVault <[email-masked]>
Date: Thu, 22 Aug 2019 19:51:11 +0900

---
 testing/py3-cairosvg/APKBUILD              | 10 ++-
 testing/py3-cairosvg/fix-flaky-tests.patch | 71 ++++++++++++++++++++++
 2 files changed, 78 insertions(+), 3 deletions(-)
 create mode 100644 testing/py3-cairosvg/fix-flaky-tests.patch

diff --git a/testing/py3-cairosvg/APKBUILD b/testing/py3-cairosvg/APKBUILD
index 917c18cd36..cf6a39ce78 100644
--- a/testing/py3-cairosvg/APKBUILD
+++ b/testing/py3-cairosvg/APKBUILD
@@ -1,7 +1,7 @@
 # Maintainer: Drew DeVault <[email-masked]>
 pkgname=py3-cairosvg
 _pyname=CairoSVG
-pkgver=2.4.0
+pkgver=2.4.1
 pkgrel=0
 pkgdesc="Cairo-based SVG renderer for python"
 url="https://cairosvg.org"
@@ -11,7 +11,10 @@ depends="python3 py3-tinycss2 py3-cssselect2 py3-defusedxml py3-cairocffi"
 checkdepends="py3-pytest py3-pillow py3-pytest-flake8 py3-pytest-isort"
 makedepends="python3-dev py3-setuptools cairo-dev"
 _pypiprefix="${_pyname%${_pyname#?}}"
-source="https://files.pythonhosted.org/packages/source/$_pypiprefix/$_pyname/$_pyname-$pkgver.tar.gz"
+source="
+	https://files.pythonhosted.org/packages/source/$_pypiprefix/$_pyname/$_pyname-$pkgver.tar.gz
+	fix-flaky-tests.patch
+"
 builddir="$srcdir"/CairoSVG-$pkgver
 replaces="py-cairosvg" # Backwards compat
 provides="py-cairosvg=$pkgver-r$pkgrel" # Backwards compat
@@ -28,4 +31,5 @@ package() {
 	python3 setup.py install --prefix=/usr --root="$pkgdir"
 }
 
-sha512sums="07eeaffa584b1c40c88c3d287b041c3f097700e49b8d85ba80e8dbc1f27aee6e5cf488db0174fc72783a727c29b6b578b1ff31d86833723681cc7fb084226c46  CairoSVG-2.4.0.tar.gz"
+sha512sums="bccc4f5aeccede49fa62d4384869d5d5602a368f6dc034c9c00217f4b527bd60beecd4026aac763551d6ec03bc951014042bfd96602b9a78d9c66f87270a8ac6  CairoSVG-2.4.1.tar.gz
+007b99675ed0ad01a30b59e4bdc58fff9e31b1e8966aac758ffbf1c29526cceeda6b239ee35e239ee44ad216111a2e0d70471ac458907a445169888f5124c72c  fix-flaky-tests.patch"
diff --git a/testing/py3-cairosvg/fix-flaky-tests.patch b/testing/py3-cairosvg/fix-flaky-tests.patch
new file mode 100644
index 0000000000..3a974d7ca6
--- /dev/null
+++ b/testing/py3-cairosvg/fix-flaky-tests.patch
@@ -0,0 +1,71 @@
+From 1b9542f941dad041a16e49b732d8f2ba9fe28e7d Mon Sep 17 00:00:00 2001
+From: Guillaume Ayoub <[email-masked]>
+Date: Thu, 22 Aug 2019 12:11:21 +0200
+Subject: [PATCH] Only use 100 bytes of generated documents for API testing
+
+As we mainly test the format here (and not the content), using the whole file
+is useless. It also allows small differences between reference and tested
+documents, like the generation date for PDF files.
+
+Fix #247.
+---
+ cairosvg/test_api.py | 16 ++++++++--------
+ 1 file changed, 8 insertions(+), 8 deletions(-)
+
+diff --git a/cairosvg/test_api.py b/cairosvg/test_api.py
+index f29db80..7d8835f 100644
+--- a/cairosvg/test_api.py
++++ b/cairosvg/test_api.py
+@@ -144,10 +144,10 @@ def test_low_level_api():
+ 
+ def test_script():
+     """Test the ``cairosvg`` script and the ``main`` function."""
+-    expected_png = svg2png(SVG_SAMPLE)
+-    expected_pdf = svg2pdf(SVG_SAMPLE)
++    expected_png = svg2png(SVG_SAMPLE)[:100]
++    expected_pdf = svg2pdf(SVG_SAMPLE)[:100]
+ 
+-    def test_main(args, exit_=False, input_=None):
++    def test_main(args, exit_=False, input_=None, full=False):
+         """Test main called with given ``args``.
+ 
+         If ``exit_`` is ``True``, check that ``SystemExit`` is raised. We then
+@@ -179,7 +179,7 @@ def test_main(args, exit_=False, input_=None):
+         sys.stdout.flush()
+         output = output_buffer.getvalue()
+         sys.stdin, sys.stdout = old_stdin, old_stdout
+-        return output
++        return output if full else output[:100]
+ 
+     with tempfile.NamedTemporaryFile(delete=False) as file_object:
+         file_object.write(SVG_SAMPLE)
+@@ -198,7 +198,7 @@ def test_main(args, exit_=False, input_=None):
+         assert test_main(['-'], input_=svg_filename) == expected_pdf
+ 
+         # Test DPI
+-        output = test_main([svg_filename, '-d', '10', '-f', 'png'])
++        output = test_main([svg_filename, '-d', '10', '-f', 'png'], full=True)
+         image = cairo.ImageSurface.create_from_png(io.BytesIO(output))
+         assert image.get_width() == 40
+         assert image.get_height() == 50
+@@ -208,17 +208,17 @@ def test_main(args, exit_=False, input_=None):
+             temp_1 = os.path.join(temp, 'result_1')
+             # Default to PDF
+             assert not test_main([svg_filename, '-o', temp_1])
+-            assert read_file(temp_1) == expected_pdf
++            assert read_file(temp_1)[:100] == expected_pdf
+ 
+             temp_2 = os.path.join(temp, 'result_2.png')
+             # Guess from the file extension
+             assert not test_main([svg_filename, '-o', temp_2])
+-            assert read_file(temp_2) == expected_png
++            assert read_file(temp_2)[:100] == expected_png
+ 
+             temp_3 = os.path.join(temp, 'result_3.png')
+             # Explicit -f wins
+             assert not test_main([svg_filename, '-o', temp_3, '-f', 'pdf'])
+-            assert read_file(temp_3) == expected_pdf
++            assert read_file(temp_3)[:100] == expected_pdf
+         finally:
+             shutil.rmtree(temp)
+ 
-- 
2.23.0