diff -r dcbbff7e6b56 Lib/test/test_syntax.py --- a/Lib/test/test_syntax.py Sat Feb 15 13:01:41 2014 +0200 +++ b/Lib/test/test_syntax.py Sat Feb 15 15:44:05 2014 +0200 @@ -527,7 +527,8 @@ class SyntaxTestCase(unittest.TestCase): def _check_error(self, code, errtext, - filename="", mode="exec", subclass=None): + filename="", mode="exec", subclass=None, + offset=None): """Check that compiling code raises SyntaxError with errtext. errtest is a regular expression that must be present in the @@ -541,7 +542,13 @@ self.fail("SyntaxError is not a %s" % subclass.__name__) mo = re.search(errtext, str(err)) if mo is None: - self.fail("SyntaxError did not contain '%r'" % (errtext,)) + self.fail("SyntaxError did not contain '%r':\n%s" % (errtext, err)) + if offset is not None and err.offset != offset: + self.fail("SyntaxError has an unexpected offset:\n" + "%*s- expected\n" + "%s\n" + "%*s- actual" + % (offset, ".", code, err.offset, "^")) else: self.fail("compile() did not raise SyntaxError") @@ -584,6 +591,28 @@ def test_kwargs_last(self): self._check_error("int(base=10, '2')", "non-keyword arg") + def test_bad_literals(self): + self._check_error('x = 0b2', 'bad digit in binary literal', + offset=7) + self._check_error('x = 0b020', 'bad digit in binary literal', + offset=8) + self._check_error('x = 0o8', 'bad digit in octal literal', + offset=7) + self._check_error('x = 0o08', 'bad digit in octal literal', + offset=8) + self._check_error('x = 0xz', 'bad digit in hex literal', + offset=7) + self._check_error('x = 0x0z', 'bad digit in hex literal', + offset=8) + self._check_error('x = 0.1e-z', 'bad digit in float literal', + offset=10) + self._check_error('x = 0.1e+z', 'bad digit in float literal', + offset=10) + self._check_error('x = 007', + 'decimal numbers may not have a leading zero', + offset=7) + + def test_main(): support.run_unittest(SyntaxTestCase) from test import test_syntax