aboutsummaryrefslogtreecommitdiff
path: root/svg-flatten/src/test
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2024-09-23 22:46:04 +0200
committerjaseg <git@jaseg.de>2024-09-23 22:46:04 +0200
commitd2ef9d19ce29aeba9740011f303db9de89b397d2 (patch)
treec82bcffd27d31f63728956b0f904d9b2dd8bcd6f /svg-flatten/src/test
parent67e4563a8f07fa8d9f566dbeb84bcc4b9ccb90ee (diff)
downloadgerbolyze-d2ef9d19ce29aeba9740011f303db9de89b397d2.tar.gz
gerbolyze-d2ef9d19ce29aeba9740011f303db9de89b397d2.tar.bz2
gerbolyze-d2ef9d19ce29aeba9740011f303db9de89b397d2.zip
Add regression test for github issue #48
This bug caused a hang when deholing certain concave polygons
Diffstat (limited to 'svg-flatten/src/test')
-rw-r--r--svg-flatten/src/test/svg_tests.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/svg-flatten/src/test/svg_tests.py b/svg-flatten/src/test/svg_tests.py
index 6afefda..36cf9f1 100644
--- a/svg-flatten/src/test/svg_tests.py
+++ b/svg-flatten/src/test/svg_tests.py
@@ -6,13 +6,14 @@ import unittest
from pathlib import Path
import subprocess
import itertools
+import textwrap
import os
import sys
from PIL import Image
import numpy as np
-def run_svg_flatten(input_file, output_file, *args, **kwargs):
+def run_svg_flatten(input_file, output_file, *args, timeout=None, **kwargs):
if 'SVG_FLATTEN' in os.environ:
svg_flatten = os.environ.get('SVG_FLATTEN')
if not hasattr(run_svg_flatten, 'custom_svg_flatten_warned'):
@@ -36,7 +37,7 @@ def run_svg_flatten(input_file, output_file, *args, **kwargs):
args.append(str(output_file))
try:
- proc = subprocess.run(args, capture_output=True, check=True, text=True)
+ proc = subprocess.run(args, capture_output=True, check=True, text=True, timeout=timeout)
except subprocess.CalledProcessError as e:
print('Subprocess stdout:')
print(e.stdout)
@@ -225,6 +226,25 @@ class StrokeMappingTests(unittest.TestCase):
num_strokes = sum(1 for l in f.readlines() if 'stroke=' in l)
self.assertEqual(num_strokes, 84)
+class RegressionTests(unittest.TestCase):
+ def test_regression_dehole_concave_infinite_loop(self):
+ test_svg = textwrap.dedent('''<svg width="185.19685" height="132.28346" xmlns="http://www.w3.org/2000/svg">
+ <defs/>
+ <g transform="matrix(3.7795274 0 0 3.7795274 0.00000763 0)">
+ <g id="g-bottom-silk">
+ <path fill="#000000" stroke="#000000" stroke-miterlimit="10" stroke-width="0.025" stroke-linecap="round" d="M 29.1075 7.2762494 L 29.1075 29.296247 L 32.26216 34.975 L 16.74945 34.975 L 19.8675 29.376247 L 19.8675 7.2762494 Z"/>
+ </g>
+ </g>
+ </svg>''')
+
+ with tempfile.NamedTemporaryFile(suffix='.svg') as tmp_svg,\
+ tempfile.NamedTemporaryFile(suffix='.gbr') as tmp_gbr:
+ tmp_svg.write(test_svg.encode())
+ tmp_svg.flush()
+
+ # This will raise subprocess.TimeoutExpired if the test fails.
+ run_svg_flatten(tmp_svg.name, tmp_gbr.name, format='svg', timeout=15)
+
for test_in_svg in Path('testdata/svg').glob('*.svg'):
# We need to make sure we capture the loop variable's current value here.