aboutsummaryrefslogtreecommitdiffstats
path: root/testing/py3-cairosvg/fix-flaky-tests.patch
blob: 3a974d7ca69a92a02508c10e6f195a297d1f403b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
From 1b9542f941dad041a16e49b732d8f2ba9fe28e7d Mon Sep 17 00:00:00 2001
From: Guillaume Ayoub <guillaume.ayoub@kozea.fr>
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)