Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testAddStyleNoDefs(self):
svg = self.svg.replace('', '')
new = style.add_style(svg, self.css)
result = minidom.parseString(new).getElementsByTagName('defs').item(0).getElementsByTagName('style').item(0)
assert self.css in result.toxml()
def test_add_style(self):
new = style.add_style(self.file, self.css)
result = minidom.parseString(new).getElementsByTagName('defs').item(0).getElementsByTagName('style').item(0)
assert self.css in result.toxml()
def test_replace_style(self):
new = style.add_style(self.file, self.css, replace=True)
result = minidom.parseString(new).getElementsByTagName('defs').item(0).getElementsByTagName('style').item(0)
assert self.css in result.toxml()
def test_add_style_missing_def(self):
with open(self.file) as f:
replaced_svg = re.sub(r'', '', f.read())
try:
io_svg = BytesIO(replaced_svg)
except TypeError:
io_svg = StringIO(replaced_svg)
new = style.add_style(io_svg, self.css)
result = minidom.parseString(new).getElementsByTagName('defs').item(0).getElementsByTagName('style').item(0)
self.assertIn(self.css, result.toxml())
def testAddCli(self):
result = style.add_style(self.file, self.css)
self.assertIn(self.css, result[0:2000])
cssfile = 'tmp.css'
with open(cssfile, 'w') as w:
w.write(self.css)
try:
result = style.add_style(self.file, cssfile)
self.assertIn(self.css, result[0:2000])
finally:
os.remove('tmp.css')
def testAddCli(self):
result = style.add_style(self.file, self.css)
self.assertIn(self.css, result[0:2000])
cssfile = 'tmp.css'
with open(cssfile, 'w') as w:
w.write(self.css)
try:
result = style.add_style(self.file, cssfile)
self.assertIn(self.css, result[0:2000])
finally:
os.remove('tmp.css')
def style(layer, output, **kwargs):
"""Add or inline the CSS styles of an SVG"""
result = _style.add_style(layer, kwargs['style'], kwargs['replace'])
if kwargs['inline']:
result = _style.inline(result)
click.echo(result.encode('utf-8'), file=output)