[t2CharStringPen] raise ValueError if tolerance not in range 0 <= t <= 0.5

This commit is contained in:
Cosimo Lupo 2017-01-13 09:34:42 +00:00
parent 0a9800b109
commit 456e159a5a
No known key found for this signature in database
GPG Key ID: B61AAAD0B53A6419
2 changed files with 16 additions and 1 deletions

View File

@ -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:

View File

@ -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