@@ -313,11 +313,24 @@ def test_parse_boolean(self):
313
313
314
314
def test_parse_bytes (self ):
315
315
self .assertLiteralStatementEqual ('b""' , ast .BytesExpression , b'' )
316
- self .assertLiteralStatementEqual ('b"dead\x13 \x37 "' , ast .BytesExpression , b'dead\x13 \x37 ' )
317
- self .assertLiteralStatementEqual ('b"\\ xde\\ xad"' , ast .BytesExpression , b'\xde \xad ' )
318
- self .assertLiteralStatementEqual ('b"\\ xDE\\ xAD"' , ast .BytesExpression , b'\xde \xad ' )
316
+
317
+ def test_parse_bytes_escape (self ):
318
+ self .assertLiteralStatementEqual ('b""' , ast .BytesExpression , b'' )
319
+ self .assertLiteralStatementEqual (r'b"foo\tbar"' , ast .BytesExpression , b'foo\x09 bar' )
320
+ self .assertLiteralStatementEqual (r'b"foo\nbar"' , ast .BytesExpression , b'foo\x0a bar' )
321
+ self .assertLiteralStatementEqual (r'b"foo\rbar"' , ast .BytesExpression , b'foo\x0d bar' )
322
+ self .assertLiteralStatementEqual (r'b"foo\"bar"' , ast .BytesExpression , b'foo\x22 bar' )
323
+ self .assertLiteralStatementEqual (r'b"foo\'bar"' , ast .BytesExpression , b'foo\x27 bar' )
324
+ self .assertLiteralStatementEqual (r'b"foo\\bar"' , ast .BytesExpression , b'foo\x5c bar' )
325
+ with self .assertRaises (errors .BytesSyntaxError ):
326
+ self ._parse (r'b"\u0123"' , self .context )
327
+
328
+ def test_parse_bytes_escape_hexl (self ):
329
+ self .assertLiteralStatementEqual (r'b"dead\x13\x37"' , ast .BytesExpression , b'dead\x13 \x37 ' )
330
+ self .assertLiteralStatementEqual (r'b"\xde\xad"' , ast .BytesExpression , b'\xde \xad ' )
331
+ self .assertLiteralStatementEqual (r'b"\xDE\xAD"' , ast .BytesExpression , b'\xde \xad ' )
319
332
with self .assertRaises (errors .BytesSyntaxError ):
320
- self ._parse ('b"\ \ xyz"' , self .context )
333
+ self ._parse (r 'b"\xyz"' , self .context )
321
334
322
335
def test_parse_datetime (self ):
323
336
self .assertLiteralStatementEqual ('d"2016-10-15"' , ast .DatetimeExpression , datetime .datetime (2016 , 10 , 15 , tzinfo = dateutil .tz .tzlocal ()))
0 commit comments