Skip to content

Commit

Permalink
tests/basics: Move str/bytes tests that give SyntaxWarning to sep file.
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
dpgeorge committed May 28, 2024
1 parent dd4767a commit 30a9ccf
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 17 deletions.
1 change: 0 additions & 1 deletion tests/basics/bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
print(b'123')
print(br'123')
print(rb'123')
print(b'\u1234')

# construction
print(bytes())
Expand Down
3 changes: 3 additions & 0 deletions tests/basics/bytes_escape_unicode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Coverage test for unicode escape in a bytes literal.
# CPython issues a SyntaxWarning for this.
print(b"\u1234")
1 change: 1 addition & 0 deletions tests/basics/bytes_escape_unicode.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b'\\u1234'
1 change: 0 additions & 1 deletion tests/basics/string1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
print(r'abc')
print(u'abc')
print(repr('\a\b\t\n\v\f\r'))
print('\z') # unrecognised escape char

# construction
print(str())
Expand Down
4 changes: 4 additions & 0 deletions tests/basics/string_escape_invalid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Test invalid escape characters.
# CPython issues a SyntaxWarning for this.

print("\z")
1 change: 1 addition & 0 deletions tests/basics/string_escape_invalid.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\z
15 changes: 0 additions & 15 deletions tests/basics/string_fstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,6 @@ def foo(a, b):
# Nested '{' and '}' characters.
print(f"a{ {0,1,2}}")

# PEP-0498 specifies that '\\' and '#' must be disallowed explicitly, whereas
# MicroPython relies on the syntax error as a result of the substitution.

print(f"\\")
print(f'#')
try:
eval("f'{\}'")
except SyntaxError:
print('SyntaxError')
try:
eval("f'{#}'")
except SyntaxError:
print('SyntaxError')


# PEP-0498 specifies that handling of double braces '{{' or '}}' should
# behave like str.format.
print(f'{{}}')
Expand Down
13 changes: 13 additions & 0 deletions tests/basics/string_fstring_invalid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# PEP-0498 specifies that '\\' and '#' must be disallowed explicitly, whereas
# MicroPython relies on the syntax error as a result of the substitution.

print(f"\\")
print(f"#")
try:
eval("f'{\}'")
except SyntaxError:
print("SyntaxError")
try:
eval("f'{#}'")
except SyntaxError:
print("SyntaxError")
4 changes: 4 additions & 0 deletions tests/basics/string_fstring_invalid.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
\
#
SyntaxError
SyntaxError

0 comments on commit 30a9ccf

Please sign in to comment.