diff --git a/enable/savage/svg/pathdata.py b/enable/savage/svg/pathdata.py index 6355e9322..c93bf78b8 100644 --- a/enable/savage/svg/pathdata.py +++ b/enable/savage/svg/pathdata.py @@ -40,8 +40,13 @@ class CaselessPreservingLiteral(CaselessLiteral): def __init__(self, matchString): super().__init__(matchString.upper()) - self.name = "'%s'" % matchString - self.errmsg = "Expected " + self.name + + quoted_name = f"'{matchString}'" + if hasattr(self, "set_name"): + # Only available in pyparsing >= 3 + self.set_name(quoted_name) + else: + self.setName(quoted_name) def parseImpl(self, instring, loc, doActions=True): test = instring[loc:loc + self.matchLen] diff --git a/enable/savage/svg/tests/test_pathdata.py b/enable/savage/svg/tests/test_pathdata.py index 0ce0f910f..3ded3122c 100644 --- a/enable/savage/svg/tests/test_pathdata.py +++ b/enable/savage/svg/tests/test_pathdata.py @@ -14,10 +14,18 @@ from enable.savage.svg.pathdata import ( Sequence, closePath, coordinatePair, curve, ellipticalArc, horizontalLine, lineTo, moveTo, number, quadraticBezierCurveto, - smoothQuadraticBezierCurveto, svg, verticalLine + smoothQuadraticBezierCurveto, svg, verticalLine, CaselessLiteral, ) +class TestCaselessLiteral(unittest.TestCase): + def test_instantiation(self): + # regression test for https://github.com/enthought/enable/issues/887 + # observed with pyparsing v >= 3 + # we just test that instantiating the class doesnt raise exceptions + CaselessLiteral("test") + + class TestNumber(unittest.TestCase): parser = number valid = ["1.e10", "1e2", "1e+4", "1e-10", "1.", "1.0", "0.1", ".2"]