Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_raster_paths_local_absolute(self):
with open('unittests/raster-formats.svg', 'r') as f:
svg = f.read()
# create a reference string by scouring the original file with relative links
options = ScourOptions
options.infilename = 'unittests/raster-formats.svg'
reference_svg = scourString(svg, options)
# this will not always create formally valid paths but it'll check how robust our implementation is
# (the third path is invalid for sure because file: needs three slashes according to URI spec)
svg = svg.replace('raster.png',
'/' + os.path.abspath(os.path.dirname(__file__)) + '\\unittests\\raster.png')
svg = svg.replace('raster.gif',
'file:///' + os.path.abspath(os.path.dirname(__file__)) + '/unittests/raster.gif')
svg = svg.replace('raster.jpg',
'file:/' + os.path.abspath(os.path.dirname(__file__)) + '/unittests/raster.jpg')
svg = scourString(svg)
self.assertEqual(svg, reference_svg,
"Raster images from absolute local paths not properly embedded.")
# create a reference string by scouring the original file with relative links
options = ScourOptions
options.infilename = 'unittests/raster-formats.svg'
reference_svg = scourString(svg, options)
# this will not always create formally valid paths but it'll check how robust our implementation is
# (the third path is invalid for sure because file: needs three slashes according to URI spec)
svg = svg.replace('raster.png',
'/' + os.path.abspath(os.path.dirname(__file__)) + '\\unittests\\raster.png')
svg = svg.replace('raster.gif',
'file:///' + os.path.abspath(os.path.dirname(__file__)) + '/unittests/raster.gif')
svg = svg.replace('raster.jpg',
'file:/' + os.path.abspath(os.path.dirname(__file__)) + '/unittests/raster.jpg')
svg = scourString(svg)
self.assertEqual(svg, reference_svg,
"Raster images from absolute local paths not properly embedded.")
def runTest(self):
with open('unittests/newlines.svg') as f:
s = scourString(f.read())
self.assertEqual(len(s.splitlines()), 24,
'Did handle reading or outputting line ending characters correctly')
def runTest(self):
with open('unittests/xml-ns-decl.svg') as f:
xmlstring = scourString(f.read())
self.assertTrue(xmlstring.find('xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"') != -1,
'Improperly serialized namespace prefix declarations when not in default namespace')
def test_scourString(self):
options = ScourOptions
try:
scourString(self.MINIMAL_SVG, options)
fail = False
except Exception:
fail = True
self.assertEqual(fail, False,
'Exception when calling "scourString" with empty options object')
def runTest(self):
with open('unittests/style-cdata.svg') as f:
docStr = f.read()
docStr = scourString(docStr,
parse_args(['--shorten-ids']))
self.assertEqual(docStr.find('somethingreallylong'), -1,
'Did not shorten IDs in the internal stylesheet')
def runTest(self):
with open('unittests/quotes-in-styles.svg', "rb") as f:
output = scourString(f.read())
self.assertTrue('use[id="t"]' in output,
'Failed to preserve quote characters in a style element')
self.assertTrue("'Times New Roman'" in output,
'Failed to preserve quote characters in a style attribute')
def runTest(self):
with open('unittests/cdata.svg') as f:
lines = scourString(f.read()).splitlines()
self.assertEqual(lines[3],
" alert('pb&j');",
'CDATA did not come out correctly')
def effect(self):
try:
input = file(self.args[0], "r")
self.options.infilename = self.args[0]
sys.stdout.write(scourString(input.read(), self.options).encode("UTF-8"))
input.close()
sys.stdout.close()
except Exception as e:
inkex.errormsg("Error during optimization.")
inkex.errormsg("\nDetails:\n" + str(e))
inkex.errormsg("\nOS version: " + platform.platform())
inkex.errormsg("Python version: " + sys.version)
inkex.errormsg("Scour version: " + scour.__version__)
sys.exit()