1414import re
1515import types
1616import decimal
17- import subprocess
1817import unittest
1918import warnings
2019from test import support
2120from test .support .os_helper import temp_cwd
22- from test .support .script_helper import (
23- assert_python_failure , assert_python_ok , spawn_python )
21+ from test .support .script_helper import assert_python_failure , assert_python_ok
2422
2523a_global = 'global variable'
2624
@@ -595,17 +593,6 @@ def test_compile_time_concat_errors(self):
595593 r"""b'' f''""" ,
596594 ])
597595
598- def test_concat_decode_failure_does_not_crash (self ):
599- script = r'''
600- import builtins
601- builtins.__import__ = builtins # Breaks warning machinery so _get_resized_exprs returns NULL
602- try:
603- compile('"x"f"\]"b""', '<test>', 'exec')
604- except Exception:
605- pass
606- '''
607- assert_python_ok ('-c' , script )
608-
609596 def test_literal (self ):
610597 self .assertEqual (f'' , '' )
611598 self .assertEqual (f'a' , 'a' )
@@ -619,34 +606,6 @@ def test_unterminated_string(self):
619606 r"""f'{("x}'""" ,
620607 ])
621608
622- def test_unclosed_multiline_replacement_field (self ):
623- for prefix in ('f' , 't' , 'rf' , 'rt' ):
624- for quote in ('"' , "'" ):
625- triple = quote * 3
626- cases = (
627- # The apparent closing quotes open a string in the field.
628- ('var = "abc"\n a = PREFIXQUOTE {var} extern "C" { QUOTE\n '
629- 'b = QUOTE string QUOTE' , 2 ),
630- # Parentheses and dictionaries inside the field must not
631- # change which opening brace the diagnostic identifies.
632- ('a = PREFIXQUOTE{\n (QUOTE' , 1 ),
633- ('a = PREFIXQUOTE{\n {0: QUOTE' , 1 ),
634- # Use the innermost format field or formatted string.
635- ('a = PREFIXQUOTE{0:\n {1\n QUOTE' , 2 ),
636- ('a = f"{\n PREFIXQUOTE{1\n QUOTE' , 2 ),
637- # Account for parentheses outside the formatted string.
638- ('a = (PREFIXQUOTE{1\n QUOTE' , 1 ),
639- )
640- for source , lineno in cases :
641- source = source .replace ('PREFIX' , prefix ).replace ('QUOTE' , triple )
642- with self .subTest (source = source ):
643- with self .assertRaises (SyntaxError ) as cm :
644- compile (source , '<test>' , 'exec' )
645- self .assertEqual (
646- cm .exception .msg ,
647- f"{ prefix [- 1 ]} -string: expecting '}}' to close '{{' "
648- f"on line { lineno } " )
649-
650609 @unittest .skipIf (support .is_wasi , "exhausts limited stack on WASI" )
651610 def test_mismatched_parens (self ):
652611 self .assertAllRaise (SyntaxError , r"closing parenthesis '\}' "
@@ -852,18 +811,6 @@ def build_fstr(n, extra=''):
852811 s = "f'{1}' 'x' 'y'" * 1024
853812 self .assertEqual (eval (s ), '1xy' * 1024 )
854813
855- @support .requires_resource ('cpu' )
856- def test_many_fstrings_in_module (self ):
857- fields = '' .join (f'{{x{ i } }}' for i in range (100 ))
858- source = '' .join (
859- f"value_{ i } = f'{ fields } '\n " for i in range (1_000 )
860- )
861- namespace = {f'x{ i } ' : str (i ) for i in range (100 )}
862- expected = '' .join (str (i ) for i in range (100 ))
863- exec (source , namespace )
864- self .assertEqual (namespace ['value_0' ], expected )
865- self .assertEqual (namespace ['value_999' ], expected )
866-
867814 def test_format_specifier_expressions (self ):
868815 width = 10
869816 precision = 4
@@ -1295,7 +1242,7 @@ def __format__(self, spec):
12951242 self .assertEqual (f'{ 3 :} ' , '3' )
12961243 self .assertEqual (f'{ 3 !s:} ' , '3' )
12971244
1298- @unittest .expectedFailureIf (unittest .__spec__ .origin == ' frozen' , "TODO: RUSTPYTHON; frozen module repr has no 'from' path" )
1245+ @unittest .expectedFailureIf (unittest .__spec__ .origin == " frozen" , "TODO: RUSTPYTHON; frozen module repr has no 'from' path" )
12991246 def test_global (self ):
13001247 self .assertEqual (f'g:{ a_global } ' , 'g:global variable' )
13011248 self .assertEqual (f'g:{ a_global !r} ' , "g:'global variable'" )
@@ -1381,9 +1328,6 @@ def test_not_equal(self):
13811328 self .assertEqual (f'{ 3 != 4 :} ' , 'True' )
13821329 self .assertEqual (f'{ 3 != 4 !s} ' , 'True' )
13831330 self .assertEqual (f'{ 3 != 4 !s:.3} ' , 'Tru' )
1384- a = 3
1385- b = 4
1386- self .assertEqual (f'{ a != b = :>10} ' , 'a!=b= 1' )
13871331
13881332 def test_equal_equal (self ):
13891333 # Because an expression ending in = has special meaning,
@@ -1714,14 +1658,6 @@ def __repr__(self):
17141658 self .assertEqual (f'{ " # nooo " = } ' , '" # nooo "=\' # nooo \' ' )
17151659 self .assertEqual (f'{ " \" # nooo \" " = } ' , '" \\ " # nooo \\ " "=\' " # nooo " \' ' )
17161660
1717- result = f'''{ (
1718- 1 , # Force lexer metadata reconstruction.
1719- "\" #" )= } '''
1720- self .assertEqual (
1721- result ,
1722- '(\n 1, \n "\\ "#")=(1, \' "#\' )' ,
1723- )
1724-
17251661 self .assertEqual (f'{ # some comment goes here
17261662 """hello""" = } ' , ' \n """hello"""=\' hello\' ' )
17271663 self .assertEqual (f'{ """# this is not a comment
@@ -1760,9 +1696,6 @@ def test_invalid_syntax_error_message(self):
17601696 with self .assertRaisesRegex (SyntaxError ,
17611697 "f-string: expecting '=', or '!', or ':', or '}'" ):
17621698 compile ("f'{a $ b}'" , "?" , "exec" )
1763- with self .assertRaisesRegex (SyntaxError ,
1764- "f-string: expecting '!', or ':', or '}'" ):
1765- compile ("f'{a=b}'" , "?" , "exec" )
17661699
17671700 def test_with_two_commas_in_format_specifier (self ):
17681701 error_msg = re .escape ("Cannot specify ',' with ','." )
@@ -1811,6 +1744,7 @@ def test_not_closing_quotes(self):
18111744 except SyntaxError as e :
18121745 self .assertEqual (e .text , 'z = f"""' )
18131746 self .assertEqual (e .lineno , 3 )
1747+
18141748 def test_syntax_error_after_debug (self ):
18151749 self .assertAllRaise (SyntaxError , "f-string: expecting a valid expression after '{'" ,
18161750 [
@@ -1838,32 +1772,6 @@ def test_debug_in_file(self):
18381772 self .assertEqual (stdout .decode ('utf-8' ).strip ().replace ('\r \n ' , '\n ' ).replace ('\r ' , '\n ' ),
18391773 "3\n =3" )
18401774
1841- @support .requires_subprocess ()
1842- def test_expression_in_interactive_after_buffer_resize (self ):
1843- expression = "(\n " + (" " * 64 + "\n " ) * 256 + "1\n )"
1844- source = (
1845- f"result = f'''{{{ expression } =}}'''\n "
1846- "print(repr(result))\n "
1847- )
1848- with spawn_python ('-i' , '-q' , stderr = subprocess .PIPE ) as process :
1849- stdout , stderr = process .communicate (
1850- source .encode (), timeout = support .SHORT_TIMEOUT )
1851- self .assertEqual (process .returncode , 0 , stderr )
1852- self .assertEqual (stdout .decode ().strip (), repr (expression + "=1" ))
1853-
1854- def test_debug_in_file_after_buffer_resize (self ):
1855- expression = "(\n " + (" " * 64 + "\n " ) * 256 + "1\n )"
1856- expected = expression + "=1"
1857- with temp_cwd ():
1858- script = 'script.py'
1859- source = (
1860- f"result = f'''{{{ expression } =}}'''\n "
1861- f"assert result == { expected !r} \n "
1862- )
1863- with open (script , 'w' ) as f :
1864- f .write (source )
1865- assert_python_ok (script )
1866-
18671775 def test_syntax_warning_infinite_recursion_in_file (self ):
18681776 with temp_cwd ():
18691777 script = 'script.py'
0 commit comments