@@ -662,9 +662,9 @@ def test_syntaxerror_multi_line_fstring(self):
662662 self .assertEqual (
663663 stderr .splitlines ()[- 3 :],
664664 [
665- b' foo"""' ,
666- b' ^' ,
667- b'SyntaxError: f-string: empty expression not allowed ' ,
665+ b' foo = f """{} ' ,
666+ b' ^' ,
667+ b'SyntaxError: f-string: valid expression required before \' } \' ' ,
668668 ],
669669 )
670670
@@ -685,8 +685,31 @@ def test_syntaxerror_invalid_escape_sequence_multi_line(self):
685685 ],
686686 )
687687
688- # TODO: RUSTPYTHON
689- @unittest .expectedFailure
688+ def test_syntaxerror_null_bytes (self ):
689+ script = "x = '\0 ' nothing to see here\n ';import os;os.system('echo pwnd')\n "
690+ with os_helper .temp_dir () as script_dir :
691+ script_name = _make_test_script (script_dir , 'script' , script )
692+ exitcode , stdout , stderr = assert_python_failure (script_name )
693+ self .assertEqual (
694+ stderr .splitlines ()[- 2 :],
695+ [ b" x = '" ,
696+ b'SyntaxError: source code cannot contain null bytes'
697+ ],
698+ )
699+
700+ def test_syntaxerror_null_bytes_in_multiline_string (self ):
701+ scripts = ["\n '''\n multilinestring\0 \n '''" , "\n f'''\n multilinestring\0 \n '''" ] # Both normal and f-strings
702+ with os_helper .temp_dir () as script_dir :
703+ for script in scripts :
704+ script_name = _make_test_script (script_dir , 'script' , script )
705+ _ , _ , stderr = assert_python_failure (script_name )
706+ self .assertEqual (
707+ stderr .splitlines ()[- 2 :],
708+ [ b" multilinestring" ,
709+ b'SyntaxError: source code cannot contain null bytes'
710+ ]
711+ )
712+
690713 def test_consistent_sys_path_for_direct_execution (self ):
691714 # This test case ensures that the following all give the same
692715 # sys.path configuration:
@@ -785,7 +808,7 @@ def test_script_as_dev_fd(self):
785808 with os_helper .temp_dir () as work_dir :
786809 script_name = _make_test_script (work_dir , 'script.py' , script )
787810 with open (script_name , "r" ) as fp :
788- p = spawn_python (f"/dev/fd/{ fp .fileno ()} " , close_fds = False , pass_fds = (0 ,1 ,2 ,fp .fileno ()))
811+ p = spawn_python (f"/dev/fd/{ fp .fileno ()} " , close_fds = True , pass_fds = (0 ,1 ,2 ,fp .fileno ()))
789812 out , err = p .communicate ()
790813 self .assertEqual (out , b"12345678912345678912345\n " )
791814
0 commit comments