Skip to content

Commit 30a9ccf

Browse files
committed
tests/basics: Move str/bytes tests that give SyntaxWarning to sep file.
In CPython 3.12 these invalid str/bytes/fstring escapes will issue a SyntaxWarning, and so differ to MicroPython. Signed-off-by: Damien George <[email protected]>
1 parent dd4767a commit 30a9ccf

9 files changed

+26
-17
lines changed

tests/basics/bytes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
print(b'123')
33
print(br'123')
44
print(rb'123')
5-
print(b'\u1234')
65

76
# construction
87
print(bytes())

tests/basics/bytes_escape_unicode.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Coverage test for unicode escape in a bytes literal.
2+
# CPython issues a SyntaxWarning for this.
3+
print(b"\u1234")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b'\\u1234'

tests/basics/string1.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
print(r'abc')
66
print(u'abc')
77
print(repr('\a\b\t\n\v\f\r'))
8-
print('\z') # unrecognised escape char
98

109
# construction
1110
print(str())

tests/basics/string_escape_invalid.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Test invalid escape characters.
2+
# CPython issues a SyntaxWarning for this.
3+
4+
print("\z")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
\z

tests/basics/string_fstring.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,6 @@ def foo(a, b):
2929
# Nested '{' and '}' characters.
3030
print(f"a{ {0,1,2}}")
3131

32-
# PEP-0498 specifies that '\\' and '#' must be disallowed explicitly, whereas
33-
# MicroPython relies on the syntax error as a result of the substitution.
34-
35-
print(f"\\")
36-
print(f'#')
37-
try:
38-
eval("f'{\}'")
39-
except SyntaxError:
40-
print('SyntaxError')
41-
try:
42-
eval("f'{#}'")
43-
except SyntaxError:
44-
print('SyntaxError')
45-
46-
4732
# PEP-0498 specifies that handling of double braces '{{' or '}}' should
4833
# behave like str.format.
4934
print(f'{{}}')
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# PEP-0498 specifies that '\\' and '#' must be disallowed explicitly, whereas
2+
# MicroPython relies on the syntax error as a result of the substitution.
3+
4+
print(f"\\")
5+
print(f"#")
6+
try:
7+
eval("f'{\}'")
8+
except SyntaxError:
9+
print("SyntaxError")
10+
try:
11+
eval("f'{#}'")
12+
except SyntaxError:
13+
print("SyntaxError")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
\
2+
#
3+
SyntaxError
4+
SyntaxError

0 commit comments

Comments
 (0)