summaryrefslogtreecommitdiffstats
path: root/share/extensions/tests/test_dxf_outlines.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--share/extensions/tests/test_dxf_outlines.py76
1 files changed, 76 insertions, 0 deletions
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 = '<svg xmlns="http://www.w3.org/2000/svg">'
+ for i in range(amount):
+ svg += f'<g id="{i}">'
+ svg = load_svg(svg + ("</g>" * amount) + "</svg>")
+ 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)