コード例 #1
0
ファイル: test_eval.py プロジェクト: yuanleilei/pypy
    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)
        if is_valid_fd(c_fileno(fp)):
            c_fclose(fp)
        rffi.free_charp(filename)
コード例 #2
0
ファイル: test_eval.py プロジェクト: mozillazg/pypy
    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)