[t2CharStringPen] raise ValueError if tolerance not in range 0 <= t <= 0.5
This commit is contained in:
parent
0a9800b109
commit
456e159a5a
@ -67,7 +67,8 @@ class RelativeCoordinatePen(BasePen):
|
||||
|
||||
|
||||
def makeRoundFunc(tolerance):
|
||||
assert 0 <= tolerance <= 0.5
|
||||
if not (0 <= tolerance <= 0.5):
|
||||
raise ValueError("Rounding tolerance out of range: %g" % tolerance)
|
||||
|
||||
def _round(number):
|
||||
if tolerance == 0:
|
||||
|
@ -6,6 +6,13 @@ import unittest
|
||||
|
||||
class T2CharStringPenTest(unittest.TestCase):
|
||||
|
||||
def __init__(self, methodName):
|
||||
unittest.TestCase.__init__(self, methodName)
|
||||
# Python 3 renamed assertRaisesRegexp to assertRaisesRegex,
|
||||
# and fires deprecation warnings if a program uses the old name.
|
||||
if not hasattr(self, "assertRaisesRegex"):
|
||||
self.assertRaisesRegex = self.assertRaisesRegexp
|
||||
|
||||
def assertAlmostEqualProgram(self, expected, actual):
|
||||
self.assertEqual(len(expected), len(actual))
|
||||
for i1, i2 in zip(expected, actual):
|
||||
@ -106,6 +113,13 @@ class T2CharStringPenTest(unittest.TestCase):
|
||||
'endchar'],
|
||||
charstring.program)
|
||||
|
||||
def test_invalid_tolerance(self):
|
||||
for value in (-0.1, 0.6):
|
||||
self.assertRaisesRegex(
|
||||
ValueError,
|
||||
"Rounding tolerance out of range",
|
||||
T2CharStringPen, None, {}, roundTolerance=value)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
|
Loading…
x
Reference in New Issue
Block a user