add and update tests
parent
381bdaf105
commit
196e65f0dc
|
@ -27,40 +27,32 @@ class TestGeneration(unittest.TestCase):
|
|||
'M 600,350 L 650,325 A 25,25 -30 0,1 700,300 L 750,275',
|
||||
]
|
||||
float_paths = [
|
||||
'M 100.0,100.0 L 300.0,100.0 L 200.0,300.0 L 100.0,100.0',
|
||||
'M 0.0,0.0 L 50.0,20.0 M 100.0,100.0 L 300.0,100.0 L 200.0,300.0 L 100.0,100.0',
|
||||
'M 100.0,100.0 L 200.0,200.0',
|
||||
'M 100.0,200.0 L 200.0,100.0 L -100.0,-200.0',
|
||||
'M 100.0,200.0 C 100.0,100.0 250.0,100.0 250.0,200.0 C 250.0,300.0 400.0,300.0 400.0,200.0',
|
||||
'M 100.0,200.0 C 100.0,100.0 400.0,100.0 400.0,200.0',
|
||||
'M 100.0,500.0 C 25.0,400.0 475.0,400.0 400.0,500.0',
|
||||
'M 100.0,800.0 C 175.0,700.0 325.0,700.0 400.0,800.0',
|
||||
'M 600.0,200.0 C 675.0,100.0 975.0,100.0 900.0,200.0',
|
||||
'M 600.0,500.0 C 600.0,350.0 900.0,650.0 900.0,500.0',
|
||||
'M 600.0,800.0 C 625.0,700.0 725.0,700.0 750.0,800.0 C 775.0,900.0 875.0,900.0 900.0,800.0',
|
||||
'M 200.0,300.0 Q 400.0,50.0 600.0,300.0 Q 800.0,550.0 1000.0,300.0',
|
||||
'M 100,100 L 300,100 L 200,300 L 100,100',
|
||||
'M 0,0 L 50,20 M 100,100 L 300,100 L 200,300 L 100,100',
|
||||
'M 100,100 L 200,200',
|
||||
'M 100,200 L 200,100 L -100,-200',
|
||||
'M 100,200 C 100,100 250,100 250,200 C 250,300 400,300 400,200',
|
||||
'M 100,200 C 100,100 400,100 400,200',
|
||||
'M 100,500 C 25,400 475,400 400,500',
|
||||
'M 100,800 C 175,700 325,700 400,800',
|
||||
'M 600,200 C 675,100 975,100 900,200',
|
||||
'M 600,500 C 600,350 900,650 900,500',
|
||||
'M 600,800 C 625,700 725,700 750,800 C 775,900 875,900 900,800',
|
||||
'M 200,300 Q 400,50 600,300 Q 800,550 1000,300',
|
||||
'M -3.4e+38,3.4e+38 L -3.4e-38,3.4e-38',
|
||||
'M 0.0,0.0 L 50.0,20.0 L 200.0,100.0 L 50.0,20.0',
|
||||
('M 600.0,350.0 L 650.0,325.0 A 27.9508497187,27.9508497187 -30.0 0,1 700.0,300.0 L 750.0,275.0', # Python 2
|
||||
'M 600.0,350.0 L 650.0,325.0 A 27.95084971874737,27.95084971874737 -30.0 0,1 700.0,300.0 L 750.0,275.0') # Python 3
|
||||
'M 0,0 L 50,20 L 200,100 L 50,20',
|
||||
'M 600,350 L 650,325 A 27.9508,27.9508 -30 0,1 700,300 L 750,275'
|
||||
]
|
||||
|
||||
for path, flpath in zip(paths[::-1], float_paths[::-1]):
|
||||
# Note: Python 3 and Python 2 differ in the number of digits
|
||||
# truncated when returning a string representation of a float
|
||||
parsed_path = parse_path(path)
|
||||
res = parsed_path.d()
|
||||
if isinstance(flpath, tuple):
|
||||
option3 = res == flpath[1] # Python 3
|
||||
flpath = flpath[0]
|
||||
else:
|
||||
option3 = False
|
||||
option1 = res == path
|
||||
option2 = res == flpath
|
||||
|
||||
msg = ('\npath =\n {}\nflpath =\n {}\nparse_path(path).d() =\n {}'
|
||||
''.format(path, flpath, res))
|
||||
self.assertTrue(option1 or option2 or option3, msg=msg)
|
||||
self.assertTrue(option1 or option2, msg=msg)
|
||||
|
||||
for flpath in float_paths[:-1]:
|
||||
res = parse_path(flpath).d()
|
||||
|
@ -71,11 +63,17 @@ class TestGeneration(unittest.TestCase):
|
|||
def test_normalizing(self):
|
||||
# Relative paths will be made absolute, subpaths merged if they can,
|
||||
# and syntax will change.
|
||||
path = 'M0 0L3.4E2-10L100.0,100M100,100l100,-100'
|
||||
path = 'M0 0L3.4E2-10L100,100M100,100l100,-100'
|
||||
ps = 'M 0,0 L 340,-10 L 100,100 L 200,0'
|
||||
psf = 'M 0.0,0.0 L 340.0,-10.0 L 100.0,100.0 L 200.0,0.0'
|
||||
psf = 'M 0,0 L 340,-10 L 100,100 L 200,0'
|
||||
self.assertTrue(parse_path(path).d() in (ps, psf))
|
||||
|
||||
def test_floating_point_errors(self):
|
||||
# Check that reading and then outputting a d-string
|
||||
# does not introduce floating point error noise.
|
||||
path = "M 70.63,10.42 C 0.11,0.33 -0.89,2.09 -1.54,2.45 C -4.95,2.73 -17.52,7.24 -39.46,11.04"
|
||||
self.assertTrue(parse_path(path).d(), path)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -245,10 +245,10 @@ class TestGroups(unittest.TestCase):
|
|||
'base_group', 'new_parent', 'new_child', 'new_leaf']))
|
||||
self.check_group_count(doc, 7)
|
||||
|
||||
path_d = ('M 206.07112,858.41289 L 206.07112,-2.02031 '
|
||||
'C -50.738,-81.14814 -20.36402,-105.87055 52.52793,-101.01525 '
|
||||
'L 103.03556,0.0 '
|
||||
'L 0.0,111.11678')
|
||||
path_d = ('M 206.071,858.413 L 206.071,-2.02031 '
|
||||
'C -50.738,-81.1481 -20.364,-105.871 52.5279,-101.015 '
|
||||
'L 103.036,0 '
|
||||
'L 0,111.117')
|
||||
|
||||
svg_path = doc.add_path(path_d, group=new_leaf)
|
||||
self.assertEqual(path_d, svg_path.get('d'))
|
||||
|
|
|
@ -281,8 +281,8 @@ class TestParser(unittest.TestCase):
|
|||
|
||||
def test_issue_99(self):
|
||||
p = Path("M 100 250 S 200 200 200 250 300 300 300 250")
|
||||
self.assertEqual(p.d(useSandT=True), 'M 100.0,250.0 S 200.0,200.0 200.0,250.0 S 300.0,300.0 300.0,250.0')
|
||||
self.assertEqual(p.d(useSandT=True), 'M 100,250 S 200,200 200,250 S 300,300 300,250')
|
||||
self.assertEqual(p.d(),
|
||||
'M 100.0,250.0 C 100.0,250.0 200.0,200.0 200.0,250.0 C 200.0,300.0 300.0,300.0 300.0,250.0')
|
||||
'M 100,250 C 100,250 200,200 200,250 C 200,300 300,300 300,250')
|
||||
self.assertNotEqual(p.d(),
|
||||
'M 100.0,250.0 C 100.0,250.0 200.0,200.0 200.0,250.0 C 200.0,250.0 300.0,300.0 300.0,250.0')
|
||||
'M 100,250 C 100,250 200,200 200,250 C 200,250 300,300 300,250')
|
||||
|
|
|
@ -1187,8 +1187,8 @@ class TestPath(unittest.TestCase):
|
|||
|
||||
def test_d(self):
|
||||
# the following two path represent the same path but in absolute and relative forms
|
||||
abs_s = 'M 38.0,130.0 C 37.0,132.0 38.0,136.0 40.0,137.0 L 85.0,161.0 C 87.0,162.0 91.0,162.0 93.0,160.0 L 127.0,133.0 C 129.0,131.0 129.0,128.0 127.0,126.0 L 80.0,70.0 C 78.0,67.0 75.0,68.0 74.0,70.0 Z'
|
||||
rel_s = 'm 38.0,130.0 c -1.0,2.0 0.0,6.0 2.0,7.0 l 45.0,24.0 c 2.0,1.0 6.0,1.0 8.0,-1.0 l 34.0,-27.0 c 2.0,-2.0 2.0,-5.0 0.0,-7.0 l -47.0,-56.0 c -2.0,-3.0 -5.0,-2.0 -6.0,0.0 z'
|
||||
abs_s = 'M 38,130 C 37,132 38,136 40,137 L 85,161 C 87,162 91,162 93,160 L 127,133 C 129,131 129,128 127,126 L 80,70 C 78,67 75,68 74,70 Z'
|
||||
rel_s = 'm 38,130 c -1,2 0,6 2,7 l 45,24 c 2,1 6,1 8,-1 l 34,-27 c 2,-2 2,-5 0,-7 l -47,-56 c -2,-3 -5,-2 -6,0 z'
|
||||
path1 = parse_path(abs_s)
|
||||
path2 = parse_path(rel_s)
|
||||
self.assertEqual(path1.d(use_closed_attrib=True), abs_s)
|
||||
|
@ -1197,6 +1197,8 @@ class TestPath(unittest.TestCase):
|
|||
self.assertEqual(path2.d(use_closed_attrib=True, rel=True), rel_s)
|
||||
|
||||
|
||||
|
||||
|
||||
class Test_ilength(unittest.TestCase):
|
||||
# See svgpathtools.notes.inv_arclength.py for information on how these
|
||||
# test values were generated (using the .length() method).
|
||||
|
|
Loading…
Reference in New Issue