Esempio n. 1
0
    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')
Esempio n. 2
0
    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')
Esempio n. 3
0
    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()
Esempio n. 4
0
    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())
Esempio n. 5
0
    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)
Esempio n. 6
0
 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()
Esempio n. 7
0
 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()
Esempio n. 8
0
 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()
Esempio n. 9
0
 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()