[pypy-commit] pypy pyfile-tell: add failing test for syncing ftell(fp) and fid.tell()
mattip
pypy.commits at gmail.com
Thu Jun 16 16:37:05 EDT 2016
Author: Matti Picus <matti.picus at gmail.com>
Branch: pyfile-tell
Changeset: r85197:4941e3ed2258
Date: 2016-06-16 22:51 +0300
http://bitbucket.org/pypy/pypy/changeset/4941e3ed2258/
Log: add failing test for syncing ftell(fp) and fid.tell()
diff --git a/pypy/module/cpyext/test/test_pyfile.py b/pypy/module/cpyext/test/test_pyfile.py
--- a/pypy/module/cpyext/test/test_pyfile.py
+++ b/pypy/module/cpyext/test/test_pyfile.py
@@ -1,5 +1,7 @@
+from pypy.conftest import option
from pypy.module.cpyext.api import fopen, fclose, fwrite
from pypy.module.cpyext.test.test_api import BaseApiTest
+from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
from pypy.module.cpyext.object import Py_PRINT_RAW
from rpython.rtyper.lltypesystem import rffi, lltype
from rpython.tool.udir import udir
@@ -111,3 +113,34 @@
out, err = capfd.readouterr()
out = out.replace('\r\n', '\n')
assert out == " 1 23\n"
+
+
+class AppTestPyFile(AppTestCpythonExtensionBase):
+
+ def setup_class(cls):
+ from rpython.tool.udir import udir
+ if option.runappdirect:
+ cls.w_udir = str(udir)
+ else:
+ cls.w_udir = cls.space.wrap(str(udir))
+
+ def test_file_tell(self):
+ module = self.import_extension('foo', [
+ ("get_c_tell", "METH_O",
+ """
+ FILE * fp = PyFile_AsFile(args);
+ if (fp == NULL)
+ return PyLong_FromLong(0);
+ return PyLong_FromLong(ftell(fp));
+ """),
+ ])
+ filename = self.udir + "/_test_file"
+ with open(filename, 'w') as fid:
+ fid.write('3' * 122)
+ with open(filename, 'r') as fid:
+ s = fid.read(80)
+ t_py = fid.tell()
+ assert t_py == 80
+ t_c = module.get_c_tell(fid)
+ assert t_c == t_py
+
More information about the pypy-commit
mailing list