From cca66b9ec4e494c1d919bff0f71a820d8afab1fa Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:24:48 +0200 Subject: Adding upstream version 1.2.2. Signed-off-by: Daniel Baumann --- share/extensions/tests/test_dxf_outlines.py | 76 +++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 share/extensions/tests/test_dxf_outlines.py (limited to 'share/extensions/tests/test_dxf_outlines.py') diff --git a/share/extensions/tests/test_dxf_outlines.py b/share/extensions/tests/test_dxf_outlines.py new file mode 100644 index 0000000..9639c28 --- /dev/null +++ b/share/extensions/tests/test_dxf_outlines.py @@ -0,0 +1,76 @@ +# coding=utf-8 +from io import BytesIO +from dxf_outlines import DxfOutlines +from inkex.tester import ComparisonMixin, InkscapeExtensionTestMixin, TestCase +from inkex.tester.filters import WindowsTextCompat +from inkex.elements._parser import load_svg + +from inkex.utils import AbortExtension +from inkex.base import SvgOutputMixin +from inkex.elements import Rectangle + + +class DFXOutlineBasicTest(ComparisonMixin, InkscapeExtensionTestMixin, TestCase): + effect_class = DxfOutlines + comparisons = [ + (), + ("--id=p1", "--id=r3"), + ("--POLY=true",), + ("--ROBO=true",), + ] + compare_filters = [WindowsTextCompat()] + + +def run_extension(document, *args) -> str: + output = BytesIO() + ext = DxfOutlines() + ext.parse_arguments([*args]) + ext.svg = document.getroot() + ext.document = document + ext.effect() + ext.save(output) + output.seek(0) + return output.read() + + +class DXFDeeplyNestedTest(TestCase): + """Check that a deeply nested SVG raises an AbortExtension""" + + @staticmethod + def create_deep_svg(amount): + """Create a very deep svg and test getting ancestors""" + svg = '' + for i in range(amount): + svg += f'' + svg = load_svg(svg + ("" * amount) + "") + return svg + + def test_deeply_nested(self): + "Run test" + with self.assertRaisesRegex(AbortExtension, "Deep Ungroup"): + run_extension(self.create_deep_svg(1500)) + + +class TestDxfUnits(TestCase): + """Test ensuring that units work properly""" + + def test_mm(self): + """Test that the documents created with/without scaling and base units are + identical.""" + document = SvgOutputMixin.get_template(width=210, height=297, unit="mm") + document.getroot().namedview.set("inkscape:document-units", "mm") + document.getroot().add(Rectangle.new(200, 0, 10, 16)) + out1 = run_extension(document) + + document = SvgOutputMixin.get_template(width=210, height=297, unit="mm") + document.getroot().add(Rectangle.new(200, 0, 10, 16)) + out2 = run_extension(document, "--unit_from_document=False", "--units=mm") + + self.assertEqual(out1, out2) + # Now with scaling - should result in the same document + document = SvgOutputMixin.get_template(width=210, height=297, unit="mm") + document.getroot().set("viewBox", "0 0 105 148.5") + document.getroot().add(Rectangle.new(100, 0, 5, 8)) + out3 = run_extension(document, "--unit_from_document=False", "--units=mm") + + self.assertEqual(out1, out3) -- cgit v1.2.3