Beispiel #1
0
    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)
Beispiel #2
0
    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)
Beispiel #3
0
    def test_run_file(self, space, api):
        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()
        api.PyRun_File(fp, filename, Py_file_input, w_globals, w_locals)
        c_fclose(fp)
        assert api.PyErr_Occurred() is space.w_ZeroDivisionError
        api.PyErr_Clear()

        # try again, but with a closed file
        fp = c_fopen(str(filepath), "rb")
        os.close(c_fileno(fp))
        api.PyRun_File(fp, filename, Py_file_input, w_globals, w_locals)
        if is_valid_fd(c_fileno(fp)):
            c_fclose(fp)
        assert api.PyErr_Occurred() is space.w_IOError
        api.PyErr_Clear()

        rffi.free_charp(filename)