diff options
| author | capellancitizen <thecapellancitizen@gmail.com> | 2024-08-28 20:12:16 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-28 20:12:16 -0400 |
| commit | 7474aa7a3a6c2a7cacd3b3c5067201bb608029c4 (patch) | |
| tree | 2a6982a8654a3be2e435456be723b1476106f8f1 /tests/test_elements_utils.py | |
| parent | f8a093ea306ce01f45936c6b34065ab57f6ccded (diff) | |
Fixed hidden objects being stitched out when cloned (Fix #3167) (#3171)
Extracted Base.descendants into a util function
Diffstat (limited to 'tests/test_elements_utils.py')
| -rw-r--r-- | tests/test_elements_utils.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/test_elements_utils.py b/tests/test_elements_utils.py new file mode 100644 index 00000000..651635be --- /dev/null +++ b/tests/test_elements_utils.py @@ -0,0 +1,52 @@ +from lib.elements import utils, FillStitch +from inkex import Rectangle, Group, Style +from inkex.tester import TestCase +from inkex.tester.svg import svg + + +class ElementsUtilsTest(TestCase): + # These tests test two functions at once, but they're sort of complimentary. + # Might suggest that they could be combined in a later refactor? + def test_iterate_nodes_to_elements(self): + root = svg() + g = root.add(Group()) + rect = g.add(Rectangle(attrib={ + "width": "10", + "height": "10" + })) + hidden_rect = g.add(Rectangle(attrib={ # noqa: F841 + "width": "10", + "height": "10", + "style": "display:none" + })) + hidden_group = g.add(Group(attrib={ + "style": "display:none" + })) + child_of_hidden = hidden_group.add(Rectangle(attrib={ # noqa: F841 + "width": "10", + "height": "10", + })) + + elements = utils.nodes_to_elements(utils.iterate_nodes(g)) + self.assertEqual(len(elements), 1) + self.assertEqual(type(elements[0]), FillStitch) + self.assertEqual(elements[0].node, rect) + + def test_iterate_nodes_to_elements_root_embroiderable(self): + """ Case where the root node is directly embroiderable """ + root = svg() + rect = root.add(Rectangle(attrib={ + "width": "10", + "height": "10" + })) + + elements = utils.nodes_to_elements(utils.iterate_nodes(rect)) + self.assertEqual(len(elements), 1) + self.assertEqual(type(elements[0]), FillStitch) + self.assertEqual(elements[0].node, rect) + + # Now make the element hidden: It shouldn't return an element + rect.style = rect.style + Style({"display": "none"}) + + elements = utils.nodes_to_elements(utils.iterate_nodes(rect)) + self.assertEqual(len(elements), 0) |
