def test_get_css_style04(self): parser = SVGParser() svg = ''' <svg width="5cm" height="4cm" viewBox="0 0 500 400" xmlns="http://www.w3.org/2000/svg"> <style type="text/css"> @import url(svg/style8.css); @media screen { /* rule (1) */ /* hide navigation controls when printing */ #navigation { display: none } @media (max-width: 12cm) { /* rule (2) */ /* keep notes in flow when printing to narrow pages */ .note { float: none } } } @media screen and (min-width: 35em), print and (min-width: 40em) { #section_navigation { float: left; width: 10em; } } .Border { fill:none; stroke:blue; stroke-width:1 } .Connect { fill:none; stroke:#888888; stroke-width:2 } .SamplePath { fill:none; stroke:red; stroke-width:5 } .EndPoint { fill:none; stroke:#888888; stroke-width:2 } .CtlPoint { fill:#888888; stroke:none } .AutoCtlPoint { fill:none; stroke:blue; stroke-width:4 } .Label { font-size:22; font-family:Verdana } </style> <text id="heading" x="-280" y="-270"> SVG demonstration</text> <rect class="Border" x="1" y="1" width="498" height="398" id="rect01" /> <polyline class="Connect" points="100,200 100,100" id="polyline01" /> <path class="SamplePath" d="M100,200 C100,100 250,100 250,200 S400,300 400,200" id="path01" /> <circle class="EndPoint" cx="100" cy="200" r="10" id="circle01" /> <text class="Label" x="25" y="70" id="text01"> M100,200 C100,100 250,100 250,200</text> </svg> ''' root = parser.fromstring(svg) rect = root.get_element_by_id('rect01') css_rules = get_css_rules(rect) css_style, css_style_important = get_css_style(rect, css_rules) self.assertEqual(4, len(css_style)) self.assertEqual(0, len(css_style_important)) css_style = rect.get_computed_style() self.assertEqual('none', css_style.get('fill')) self.assertEqual('blue', css_style.get('stroke')) self.assertEqual(1, css_style.get('stroke-width')) text = root.get_element_by_id('heading') css_style = text.get_computed_style() self.assertEqual(24, css_style.get('font-size'), msg='http server may not be working.') self.assertEqual(700, css_style.get('font-weight'))
def test_get_css_style03(self): parser = SVGParser() svg = ''' <svg width="5cm" height="4cm" viewBox="0 0 500 400" xmlns="http://www.w3.org/2000/svg"> <style type="text/css"><![CDATA[ .Border { fill:none; stroke:blue; stroke-width:1 } .Connect { fill:none; stroke:#888888; stroke-width:2 } .SamplePath { fill:none; stroke:red; stroke-width:5 } .EndPoint { fill:none; stroke:#888888; stroke-width:2 } .CtlPoint { fill:#888888; stroke:none } .AutoCtlPoint { fill:none; stroke:blue; stroke-width:4 } .Label { font-size:22; font-family:Verdana } ]]></style> <rect class="Border" x="1" y="1" width="498" height="398" id="rect01" /> <polyline class="Connect" points="100,200 100,100" id="polyline01" /> <path class="SamplePath" d="M100,200 C100,100 250,100 250,200 S400,300 400,200" id="path01" /> <circle class="EndPoint" cx="100" cy="200" r="10" id="circle01" /> <text class="Label" x="25" y="70" id="text01"> M100,200 C100,100 250,100 250,200</text> </svg> ''' root = parser.fromstring(svg) rect = root.get_element_by_id('rect01') css_style = rect.get_computed_style() self.assertEqual('none', css_style.get('fill')) self.assertEqual('blue', css_style.get('stroke')) self.assertEqual(1, css_style.get('stroke-width')) path = root.get_element_by_id('path01') css_style = path.get_computed_style() self.assertEqual('none', css_style.get('fill')) self.assertEqual('red', css_style.get('stroke')) self.assertEqual(5, css_style.get('stroke-width')) text = root.get_element_by_id('text01') css_style = text.get_computed_style() self.assertEqual(['Verdana'], css_style.get('font-family')) self.assertEqual(22, css_style.get('font-size'))