Skip to content

Commit 1fe9f30

Browse files
committed
Ensure that exception message do not contain u'' on Py2
* string representation on Python2 come with a u prefix by default This makes testing for exception messages harder. Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent bee384c commit 1fe9f30

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

boolean/boolean.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,17 @@ def __init__(self, token_type=None, token_string='', position=-1, error_code=0):
8787
self.error_code = error_code
8888

8989
def __str__(self, *args, **kwargs):
90+
emsg = PARSE_ERRORS.get(self.error_code, 'Unknown parsing error')
91+
9092
tstr = ''
9193
if self.token_string:
92-
tstr = ' for token: %r' % (self.token_string)
94+
tstr = ' for token: "%s"' % self.token_string
9395

9496
pos = ''
9597
if self.position > 0:
96-
pos = ' at position: %d' % (self.position)
97-
emsg = PARSE_ERRORS.get(self.error_code, 'Unknown parsing error')
98+
pos = ' at position: %d' % self.position
9899

99-
return '{emsg}{tstr}{pos}.'.format(tstr=tstr, pos=pos, emsg=emsg)
100+
return '{emsg}{tstr}{pos}'.format(**locals())
100101

101102

102103
class BooleanAlgebra(object):

0 commit comments

Comments
 (0)