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 test_add_style_missing_def(self): with open(self.file) as f: replaced_svg = re.sub(r'<defs></defs>', '', 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) assert self.css in result.toxml()
def test_add_style_missing_def(self): with open(self.file) as f: replaced_svg = re.sub(r'<defs></defs>', '', 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 testInlineCSS(self): svg = style.add_style(self.svg, self.css) inlined = style.inline(svg) self.assertNotEqual(inlined, self.svg) doc = minidom.parseString(inlined) self.assertIn('fill:purple', inlined) polygon_style = doc.getElementsByTagName('polygon').item(0).getAttribute('style') self.assertIn('stroke:green', polygon_style) self.assertIn('fill:orange', polygon_style) cat_style = doc.getElementsByTagName('polyline').item(1).getAttribute('style') self.assertIn('fill:red', cat_style) polyline_style = doc.getElementsByTagName('polyline').item(0).getAttribute('style') self.assertIn('stroke:blue', polyline_style)
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 testAddStyleNoDefs(self): svg = self.svg.replace('<defs></defs>', '') 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_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()