summaryrefslogtreecommitdiffstats
path: root/share/extensions/tests/test_inkex_inx.py
blob: 5a55efa266159ec9624399c39b1edb2181a6910a (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python
# coding=utf-8
"""
Test elements extra logic from svg xml lxml custom classes.
"""

import os
from glob import glob

from inkex.utils import PY3
from inkex.tester import TestCase
from inkex.tester.inx import InxMixin
from inkex.inx import InxFile


class InxTestCase(InxMixin, TestCase):
    """Test INX files"""

    def test_inx_effect(self):
        inx = InxFile(
            """
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
    <name>TestOne</name>
    <id>org.inkscape.test.inx_one</id>
    <effect needs-live-preview="false">
        <object-type>all</object-type>
        <effects-menu>
            <submenu name="Banana">
                <submenu name="Ice Cream"/>
            </submenu>
        </effects-menu>
    </effect>
    <script>
        <command location="inx" interpreter="python">inx_test.py</command>
    </script>
</inkscape-extension>"""
        )
        self.assertEqual(inx.name, "TestOne")
        self.assertEqual(inx.ident, "org.inkscape.test.inx_one")
        self.assertEqual(inx.slug, "InxOne")
        self.assertEqual(
            inx.metadata, {"type": "effect", "preview": False, "objects": "all"}
        )
        self.assertEqual(inx.menu, ["Banana", "Ice Cream", "TestOne"])
        self.assertEqual(inx.warnings, [])

    def test_inx_output(self):
        inx = InxFile(
            """
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
    <_name>TestTwo</_name>
    <id>org.inkscape.test.inx_two</id>
    <output>
        <extension>.inx</extension>
        <mimetype>text/xml+inx</mimetype>
        <filetypename>Extension (*.inx)</filetypename>
        <_filetypetooltip>The extension extension repention suspension.</_filetypetooltip>
        <dataloss>true</dataloss>
    </output>
</inkscape-extension>"""
        )
        self.assertEqual(inx.name, "TestTwo")
        self.assertEqual(inx.ident, "org.inkscape.test.inx_two")
        self.assertEqual(
            inx.metadata,
            {
                "dataloss": True,
                "extension": ".inx",
                "mimetype": "text/xml+inx",
                "name": "Extension (*.inx)",
                "tooltip": "The extension extension repention suspension.",
                "type": "output",
            },
        )
        self.assertEqual(
            inx.warnings,
            [
                "Use of old translation scheme: <_filetypetooltip...>",
                "Use of old translation scheme: <_name...>",
            ],
        )

    def test_inx_input(self):
        inx = InxFile(
            """<inkscape-extension>
    <name>TestThree</name>
    <id>org.inkscape.test.inx_three</id>
    <input>
        <extension>.inx</extension>
        <mimetype>text/xml+inx</mimetype>
        <filetypename>Extension (*.inx)</filetypename>
        <filetypetooltip>The extension extension repention suspension.</filetypetooltip>
    </input>
</inkscape-extension>"""
        )
        self.assertEqual(inx.name, "TestThree")
        self.assertEqual(
            inx.metadata,
            {
                "extension": ".inx",
                "mimetype": "text/xml+inx",
                "name": "Extension (*.inx)",
                "tooltip": "The extension extension repention suspension.",
                "type": "input",
            },
        )
        self.assertEqual(inx.warnings, ["No inx xml prefix."])

    def test_inx_template(self):
        inx = InxFile(
            """<inkscape-extension xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape">
    <name>TestFour</name>
    <id>org.inkscape.test.inx_four</id>
        <effect needs-live-preview="false">
        <object-type>all</object-type>
        <effects-menu hidden="true" />
    </effect>
    <inkscape:templateinfo>
      <inkscape:name>Magic Number</inkscape:name>
      <inkscape:author>Donky Oaty</inkscape:author>
      <inkscape:shortdesc>Something might happen.</inkscape:shortdesc>
      <inkscape:date>2070-01-01</inkscape:date>
      <inkscape:keywords>word food strawberry</inkscape:keywords>
    </inkscape:templateinfo>
</inkscape-extension>"""
        )
        self.assertEqual(inx.name, "TestFour")
        self.assertEqual(
            inx.metadata,
            {
                "author": "Donky Oaty",
                "desc": "Something might happen.",
                "type": "template",
            },
        )
        self.assertEqual(inx.warnings, ["No inx xml prefix."])

    def test_inx_files(self):
        """Get all inx files and test each of them"""
        if not PY3:
            self.skipTest("No INX testing in python2")
            return
        for inx_file in glob(os.path.join(self._testdir(), "..", "*.inx")):
            self.assertInxIsGood(inx_file)