summaryrefslogtreecommitdiff
path: root/tests/test_elements_utils.py
blob: 2c0a64eb575aaf5aa89d66a710e97829724369b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from inkex import Group, Rectangle, Style
from inkex.tester import TestCase
from inkex.tester.svg import svg

from lib.elements import FillStitch, utils

from .utils import element_count


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) -> None:
        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), element_count())
        self.assertEqual(type(elements[0]), FillStitch)
        self.assertEqual(elements[0].node, rect)

    def test_iterate_nodes_to_elements_root_embroiderable(self) -> None:
        """ 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), element_count())
        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)