add unit tests

This commit is contained in:
Tobias Oberstein 2016-04-02 17:41:20 +02:00
parent d710fb3f6c
commit 6a23a4cd71
2 changed files with 17 additions and 2 deletions

View file

@ -2884,9 +2884,11 @@ def scourString(in_string, options=None):
# flowRoot elements don't render at all on current browsers (04/2016) # flowRoot elements don't render at all on current browsers (04/2016)
cnt_flowText_el = len(doc.getElementsByTagName('flowRoot')) cnt_flowText_el = len(doc.getElementsByTagName('flowRoot'))
if cnt_flowText_el: if cnt_flowText_el:
print("SVG input document uses {} flow text elements, which won't render on browsers!".format(cnt_flowText_el)) errmsg = "SVG input document uses {} flow text elements, which won't render on browsers!".format(cnt_flowText_el)
if options.error_on_flowtext: if options.error_on_flowtext:
sys.exit(1) raise Exception(errmsg)
else:
print("WARNING: {}".format(errmsg))
# remove <metadata> if the user wants to # remove <metadata> if the user wants to
if options.remove_metadata: if options.remove_metadata:

View file

@ -1416,6 +1416,19 @@ class DuplicateGradientsUpdateStyle(unittest.TestCase):
self.assertEqual('fill:url(#' + gradientTag.getAttribute('id') + ')', rectTag1.getAttribute('style'), self.assertEqual('fill:url(#' + gradientTag.getAttribute('id') + ')', rectTag1.getAttribute('style'),
'Either of #duplicate-one or #duplicate-two was removed, but style="fill:" was not updated to reflect this') 'Either of #duplicate-one or #duplicate-two was removed, but style="fill:" was not updated to reflect this')
class DocWithFlowtext(unittest.TestCase):
def runTest(self):
with self.assertRaises(Exception):
scour.scourXmlFile('unittests/flowtext.svg',
scour.parse_args(['--error-on-flowtext'])[0])
class DocWithNoFlowtext(unittest.TestCase):
def runTest(self):
try:
scour.scourXmlFile('unittests/flowtext-less.svg',
scour.parse_args(['--error-on-flowtext'])[0])
except Exception as e:
self.fail("exception '{}' was raised, and we didn't expect that!".format(e))
# TODO: write tests for --enable-viewboxing # TODO: write tests for --enable-viewboxing
# TODO; write a test for embedding rasters # TODO; write a test for embedding rasters