From 10669301a14caff853df0b97495a03872e4f507f Mon Sep 17 00:00:00 2001 From: jaseg Date: Wed, 29 Mar 2023 22:42:49 +0200 Subject: svg-flatten: Add stroke mapping test --- svg-flatten/src/test/svg_tests.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'svg-flatten/src') diff --git a/svg-flatten/src/test/svg_tests.py b/svg-flatten/src/test/svg_tests.py index d91bc0d..6afefda 100644 --- a/svg-flatten/src/test/svg_tests.py +++ b/svg-flatten/src/test/svg_tests.py @@ -36,12 +36,12 @@ 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) - except: + proc = subprocess.run(args, capture_output=True, check=True, text=True) + except subprocess.CalledProcessError as e: print('Subprocess stdout:') - print(proc.stdout.decode()) + print(e.stdout) print('Subprocess stderr:') - print(proc.stderr.decode()) + print(e.stderr) raise def run_cargo_cmd(cmd, args, **kwargs): @@ -213,6 +213,19 @@ class SVGRoundTripTests(unittest.TestCase): e.args = (msg, *rest) raise e +class StrokeMappingTests(unittest.TestCase): + def test_stroke_mapping(self): + test_in_svg = 'testdata/svg/xform_uniformity_threshold.svg' + + with tempfile.NamedTemporaryFile(suffix='.svg') as tmp_out_svg: + + run_svg_flatten(test_in_svg, tmp_out_svg.name, format='svg') + + with open(tmp_out_svg.name, 'r') as f: + num_strokes = sum(1 for l in f.readlines() if 'stroke=' in l) + self.assertEqual(num_strokes, 84) + + for test_in_svg in Path('testdata/svg').glob('*.svg'): # We need to make sure we capture the loop variable's current value here. gen = lambda testcase: lambda self: self.run_svg_round_trip_test(testcase) -- cgit