diff options
author | Damien George <damien@micropython.org> | 2024-05-28 10:52:12 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2024-05-28 10:58:37 +1000 |
commit | 30a9ccf4caa72c62cb8656a1572518fef34b08a4 (patch) | |
tree | 125f373f880e1b3e1b632d1d5e2f5e90665e8cc3 | |
parent | dd4767a7d1ba57f107a652310fdfbd0f0274a0c8 (diff) | |
download | micropython-30a9ccf4caa72c62cb8656a1572518fef34b08a4.tar.gz micropython-30a9ccf4caa72c62cb8656a1572518fef34b08a4.zip |
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 <damien@micropython.org>
-rw-r--r-- | tests/basics/bytes.py | 1 | ||||
-rw-r--r-- | tests/basics/bytes_escape_unicode.py | 3 | ||||
-rw-r--r-- | tests/basics/bytes_escape_unicode.py.exp | 1 | ||||
-rw-r--r-- | tests/basics/string1.py | 1 | ||||
-rw-r--r-- | tests/basics/string_escape_invalid.py | 4 | ||||
-rw-r--r-- | tests/basics/string_escape_invalid.py.exp | 1 | ||||
-rw-r--r-- | tests/basics/string_fstring.py | 15 | ||||
-rw-r--r-- | tests/basics/string_fstring_invalid.py | 13 | ||||
-rw-r--r-- | tests/basics/string_fstring_invalid.py.exp | 4 |
9 files changed, 26 insertions, 17 deletions
diff --git a/tests/basics/bytes.py b/tests/basics/bytes.py index 0b6b14fa55..ba14c26da8 100644 --- a/tests/basics/bytes.py +++ b/tests/basics/bytes.py @@ -2,7 +2,6 @@ print(b'123') print(br'123') print(rb'123') -print(b'\u1234') # construction print(bytes()) diff --git a/tests/basics/bytes_escape_unicode.py b/tests/basics/bytes_escape_unicode.py new file mode 100644 index 0000000000..1e450696f4 --- /dev/null +++ b/tests/basics/bytes_escape_unicode.py @@ -0,0 +1,3 @@ +# Coverage test for unicode escape in a bytes literal. +# CPython issues a SyntaxWarning for this. +print(b"\u1234") diff --git a/tests/basics/bytes_escape_unicode.py.exp b/tests/basics/bytes_escape_unicode.py.exp new file mode 100644 index 0000000000..6affe51896 --- /dev/null +++ b/tests/basics/bytes_escape_unicode.py.exp @@ -0,0 +1 @@ +b'\\u1234' diff --git a/tests/basics/string1.py b/tests/basics/string1.py index b3abfb9c60..ca8dfd5399 100644 --- a/tests/basics/string1.py +++ b/tests/basics/string1.py @@ -5,7 +5,6 @@ print('abc') print(r'abc') print(u'abc') print(repr('\a\b\t\n\v\f\r')) -print('\z') # unrecognised escape char # construction print(str()) diff --git a/tests/basics/string_escape_invalid.py b/tests/basics/string_escape_invalid.py new file mode 100644 index 0000000000..d9fdd6e546 --- /dev/null +++ b/tests/basics/string_escape_invalid.py @@ -0,0 +1,4 @@ +# Test invalid escape characters. +# CPython issues a SyntaxWarning for this. + +print("\z") diff --git a/tests/basics/string_escape_invalid.py.exp b/tests/basics/string_escape_invalid.py.exp new file mode 100644 index 0000000000..c642929c6e --- /dev/null +++ b/tests/basics/string_escape_invalid.py.exp @@ -0,0 +1 @@ +\z diff --git a/tests/basics/string_fstring.py b/tests/basics/string_fstring.py index 1a3960680e..42d093b37b 100644 --- a/tests/basics/string_fstring.py +++ b/tests/basics/string_fstring.py @@ -29,21 +29,6 @@ print(f"a{[0,15,2][0:2][-1]:04x}") # 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'{{}}') diff --git a/tests/basics/string_fstring_invalid.py b/tests/basics/string_fstring_invalid.py new file mode 100644 index 0000000000..6fce323c5b --- /dev/null +++ b/tests/basics/string_fstring_invalid.py @@ -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") diff --git a/tests/basics/string_fstring_invalid.py.exp b/tests/basics/string_fstring_invalid.py.exp new file mode 100644 index 0000000000..bcb7f259e5 --- /dev/null +++ b/tests/basics/string_fstring_invalid.py.exp @@ -0,0 +1,4 @@ +\ +# +SyntaxError +SyntaxError |