~louis-simard-deactivatedaccount/scour/rework

« back to all changes in this revision

Viewing changes to testscour.py

  • Committer: Cynthia Gauthier
  • Date: 2010-06-01 23:13:44 UTC
  • Revision ID: cynthia@jolteon-20100601231344-dftf47m2poq1lbhe
svg_regex.py:
 * Modify the parser's output so it's already like what cleanPath wants.
scour.py:
 * Actually make scientific notation work.
testscour.py:
 * In an earlier revision of scour.py, I made 1E+4 become 1e4, which the SVG spec accepts. Make this acceptable.
 * Made tests accept the new format of path data introduced in svg_regex.py.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
        strip_xml_prolog = False
49
49
        indent_type = "space"
50
50
        enable_viewboxing = False
 
51
        shorten_ids = False
 
52
        strip_comments = False
 
53
        remove_metadata = False
51
54
 
52
55
class NoInkscapeElements(unittest.TestCase):
53
56
        def runTest(self):
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')
509
512
 
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')
518
521
 
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' )
527
530
                        
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' )
534
537
 
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' )
550
553
 
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' )
559
562
 
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')
674
677
 
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')
680
683
 
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
1033
1039
 
1034
1040
if __name__ == '__main__':
1035
1041
        testcss = __import__('testcss')