def test_run_file(self, space): filepath = udir / "cpyext_test_runfile.py" filepath.write("raise ZeroDivisionError") fp = c_fopen(str(filepath), "rb") filename = rffi.str2charp(str(filepath)) w_globals = w_locals = space.newdict() with raises_w(space, ZeroDivisionError): PyRun_File(space, fp, filename, Py_file_input, w_globals, w_locals) c_fclose(fp) # try again, but with a closed file fp = c_fopen(str(filepath), "rb") os.close(c_fileno(fp)) with raises_w(space, IOError): PyRun_File(space, fp, filename, Py_file_input, w_globals, w_locals) c_fclose(fp) rffi.free_charp(filename)
def test_run_file(self, space): filepath = udir / "cpyext_test_runfile.py" filepath.write("raise ZeroDivisionError") fp = c_fopen(str(filepath), "rb") filename = rffi.str2charp(str(filepath)) w_globals = w_locals = space.newdict() with raises_w(space, ZeroDivisionError): PyRun_File(space, fp, filename, Py_file_input, w_globals, w_locals) c_fclose(fp) # try again, but with a closed file if self.runappdirect: # according to man 2 fclose, any access of fp is undefined # behaviour. This crashes on some linux systems untranslated fp = c_fopen(str(filepath), "rb") c_fclose(fp) with raises_w(space, IOError): PyRun_File(space, fp, filename, Py_file_input, w_globals, w_locals) rffi.free_charp(filename)