Add unittests for --protect-ids-_ options
This commit is contained in:
parent
829b630d64
commit
45a2869a17
2 changed files with 67 additions and 0 deletions
59
testscour.py
59
testscour.py
|
|
@ -389,6 +389,65 @@ class RemoveUnreferencedIDsWhenEnabled(unittest.TestCase):
|
|||
'<svg> ID not stripped')
|
||||
|
||||
|
||||
class ProtectIDs(unittest.TestCase):
|
||||
|
||||
def test_protect_none(self):
|
||||
doc = scourXmlFile('unittests/ids-protect.svg',
|
||||
parse_args(['--enable-id-stripping']))
|
||||
self.assertEqual(doc.getElementsByTagNameNS(SVGNS, 'text')[0].getAttribute('id'), '',
|
||||
"ID 'text1' not stripped when none of the '--protect-ids-_' options was specified")
|
||||
self.assertEqual(doc.getElementsByTagNameNS(SVGNS, 'text')[1].getAttribute('id'), '',
|
||||
"ID 'text2' not stripped when none of the '--protect-ids-_' options was specified")
|
||||
self.assertEqual(doc.getElementsByTagNameNS(SVGNS, 'text')[2].getAttribute('id'), '',
|
||||
"ID 'text3' not stripped when none of the '--protect-ids-_' options was specified")
|
||||
self.assertEqual(doc.getElementsByTagNameNS(SVGNS, 'text')[3].getAttribute('id'), '',
|
||||
"ID 'text_custom' not stripped when none of the '--protect-ids-_' options was specified")
|
||||
self.assertEqual(doc.getElementsByTagNameNS(SVGNS, 'text')[4].getAttribute('id'), '',
|
||||
"ID 'my_text1' not stripped when none of the '--protect-ids-_' options was specified")
|
||||
|
||||
def test_protect_ids_noninkscape(self):
|
||||
doc = scourXmlFile('unittests/ids-protect.svg',
|
||||
parse_args(['--enable-id-stripping', '--protect-ids-noninkscape']))
|
||||
self.assertEqual(doc.getElementsByTagNameNS(SVGNS, 'text')[0].getAttribute('id'), '',
|
||||
"ID 'text1' should have been stripped despite '--protect-ids-noninkscape' being specified")
|
||||
self.assertEqual(doc.getElementsByTagNameNS(SVGNS, 'text')[1].getAttribute('id'), '',
|
||||
"ID 'text2' should have been stripped despite '--protect-ids-noninkscape' being specified")
|
||||
self.assertEqual(doc.getElementsByTagNameNS(SVGNS, 'text')[2].getAttribute('id'), '',
|
||||
"ID 'text3' should have been stripped despite '--protect-ids-noninkscape' being specified")
|
||||
self.assertEqual(doc.getElementsByTagNameNS(SVGNS, 'text')[3].getAttribute('id'), 'text_custom',
|
||||
"ID 'text_custom' should NOT have been stripped because of '--protect-ids-noninkscape'")
|
||||
self.assertEqual(doc.getElementsByTagNameNS(SVGNS, 'text')[4].getAttribute('id'), '',
|
||||
"ID 'my_text1' should have been stripped despite '--protect-ids-noninkscape' being specified")
|
||||
|
||||
def test_protect_ids_list(self):
|
||||
doc = scourXmlFile('unittests/ids-protect.svg',
|
||||
parse_args(['--enable-id-stripping', '--protect-ids-list=text2,text3']))
|
||||
self.assertEqual(doc.getElementsByTagNameNS(SVGNS, 'text')[0].getAttribute('id'), '',
|
||||
"ID 'text1' should have been stripped despite '--protect-ids-list' being specified")
|
||||
self.assertEqual(doc.getElementsByTagNameNS(SVGNS, 'text')[1].getAttribute('id'), 'text2',
|
||||
"ID 'text2' should NOT have been stripped because of '--protect-ids-list'")
|
||||
self.assertEqual(doc.getElementsByTagNameNS(SVGNS, 'text')[2].getAttribute('id'), 'text3',
|
||||
"ID 'text3' should NOT have been stripped because of '--protect-ids-list'")
|
||||
self.assertEqual(doc.getElementsByTagNameNS(SVGNS, 'text')[3].getAttribute('id'), '',
|
||||
"ID 'text_custom' should have been stripped despite '--protect-ids-list' being specified")
|
||||
self.assertEqual(doc.getElementsByTagNameNS(SVGNS, 'text')[4].getAttribute('id'), '',
|
||||
"ID 'my_text1' should have been stripped despite '--protect-ids-list' being specified")
|
||||
|
||||
def test_protect_ids_prefix(self):
|
||||
doc = scourXmlFile('unittests/ids-protect.svg',
|
||||
parse_args(['--enable-id-stripping', '--protect-ids-prefix=my']))
|
||||
self.assertEqual(doc.getElementsByTagNameNS(SVGNS, 'text')[0].getAttribute('id'), '',
|
||||
"ID 'text1' should have been stripped despite '--protect-ids-prefix' being specified")
|
||||
self.assertEqual(doc.getElementsByTagNameNS(SVGNS, 'text')[1].getAttribute('id'), '',
|
||||
"ID 'text2' should have been stripped despite '--protect-ids-prefix' being specified")
|
||||
self.assertEqual(doc.getElementsByTagNameNS(SVGNS, 'text')[2].getAttribute('id'), '',
|
||||
"ID 'text3' should have been stripped despite '--protect-ids-prefix' being specified")
|
||||
self.assertEqual(doc.getElementsByTagNameNS(SVGNS, 'text')[3].getAttribute('id'), '',
|
||||
"ID 'text_custom' should have been stripped despite '--protect-ids-prefix' being specified")
|
||||
self.assertEqual(doc.getElementsByTagNameNS(SVGNS, 'text')[4].getAttribute('id'), 'my_text1',
|
||||
"ID 'my_text1' should NOT have been stripped because of '--protect-ids-prefix'")
|
||||
|
||||
|
||||
class RemoveUselessNestedGroups(unittest.TestCase):
|
||||
|
||||
def runTest(self):
|
||||
|
|
|
|||
8
unittests/ids-protect.svg
Normal file
8
unittests/ids-protect.svg
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="110" width="100">
|
||||
<text id="text1" x="10" y="20">Text 1</text>
|
||||
<text id="text2" x="10" y="40">Text 2</text>
|
||||
<text id="text3" x="10" y="60">Text 3</text>
|
||||
<text id="text_custom" x="10" y="80">Text custom</text>
|
||||
<text id="my_text1" x="10" y="100">My text</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 358 B |
Loading…
Add table
Add a link
Reference in a new issue