504
507
def runTest(self):
505
508
doc = scour.scourXmlFile('unittests/path-use-scientific-notation.svg')
506
509
path = doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('d')
507
self.assertEquals(path, 'M1E+4,0',
510
self.assertEquals(path, 'M1e4,0',
508
511
'Not using scientific notation for path coord when representation is shorter')
510
513
class ConvertAbsoluteToRelativePathCommands(unittest.TestCase):
513
516
path = svg_parser.parse(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('d'))
514
517
self.assertEquals(path[1][0], 'v',
515
518
'Absolute V command not converted to relative v command')
516
self.assertEquals(path[1][1][0], -20.0,
519
self.assertEquals(float(path[1][1][0]), -20.0,
517
520
'Absolute V value not converted to relative v value')
519
522
class RoundPathData(unittest.TestCase):
520
523
def runTest(self):
521
524
doc = scour.scourXmlFile('unittests/path-precision.svg')
522
525
path = svg_parser.parse(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('d'))
523
self.assertEquals(path[0][1][0][0], 100.0,
526
self.assertEquals(float(path[0][1][0]), 100.0,
524
527
'Not rounding down' )
525
self.assertEquals(path[0][1][0][1], 100.0,
528
self.assertEquals(float(path[0][1][1]), 100.0,
526
529
'Not rounding up' )
528
531
class LimitPrecisionInPathData(unittest.TestCase):
529
532
def runTest(self):
530
533
doc = scour.scourXmlFile('unittests/path-precision.svg')
531
534
path = svg_parser.parse(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('d'))
532
self.assertEquals(path[1][1][0], 100.01,
535
self.assertEquals(float(path[1][1][0]), 100.01,
533
536
'Not correctly limiting precision on path data' )
535
538
class RemoveEmptyLineSegmentsFromPath(unittest.TestCase):
545
548
path = svg_parser.parse(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('d'))
546
549
self.assertEquals(path[1][0], 'h',
547
550
'Did not change line to horizontal line segment in path' )
548
self.assertEquals(path[1][1][0], 200.0,
551
self.assertEquals(float(path[1][1][0]), 200.0,
549
552
'Did not calculate horizontal line segment in path correctly' )
551
554
class ChangeLineToVerticalLineSegmentInPath(unittest.TestCase):
554
557
path = svg_parser.parse(doc.getElementsByTagNameNS(SVGNS, 'path')[0].getAttribute('d'))
555
558
self.assertEquals(path[2][0], 'v',
556
559
'Did not change line to vertical line segment in path' )
557
self.assertEquals(path[2][1][0], 100.0,
560
self.assertEquals(float(path[2][1][0]), 100.0,
558
561
'Did not calculate vertical line segment in path correctly' )
560
563
class ChangeBezierToShorthandInPath(unittest.TestCase):
669
672
class ScourPolygonCoordsSciNo(unittest.TestCase):
670
673
def runTest(self):
671
674
p = scour.scourXmlFile('unittests/polygon-coord.svg').getElementsByTagNameNS(SVGNS, 'polygon')[0]
672
self.assertEquals(p.getAttribute('points'), '1E+4,50',
675
self.assertEquals(p.getAttribute('points'), '1e4,50',
673
676
'Polygon coordinates not scoured')
675
678
class ScourPolylineCoordsSciNo(unittest.TestCase):
676
679
def runTest(self):
677
680
p = scour.scourXmlFile('unittests/polyline-coord.svg').getElementsByTagNameNS(SVGNS, 'polyline')[0]
678
self.assertEquals(p.getAttribute('points'), '1E+4,50',
681
self.assertEquals(p.getAttribute('points'), '1e4,50',
679
682
'Polyline coordinates not scoured')
681
684
class ScourPolygonNegativeCoords(unittest.TestCase):
1030
1033
# TODO: write a test for --disable-embed-rasters
1031
1034
# TODO: write tests for --keep-editor-data
1032
1035
# TODO: write tests for --strip-xml-prolog
1036
# TODO: write tests for --enable-comment-stripping
1037
# TODO: write tests for --shorten-ids
1038
# TODO: write tests for --remove-metadata
1034
1040
if __name__ == '__main__':
1035
1041
testcss = __import__('testcss')