[pypy-svn] r31008 - in pypy/dist/pypy/module/bz2: . test
rhymes at codespeak.net
rhymes at codespeak.net
Fri Aug 4 17:11:57 CEST 2006
Author: rhymes
Date: Fri Aug 4 17:11:54 2006
New Revision: 31008
Modified:
pypy/dist/pypy/module/bz2/interp_bz2.py
pypy/dist/pypy/module/bz2/test/test_bz2.py
Log:
tell() implemented
Modified: pypy/dist/pypy/module/bz2/interp_bz2.py
==============================================================================
--- pypy/dist/pypy/module/bz2/interp_bz2.py (original)
+++ pypy/dist/pypy/module/bz2/interp_bz2.py Fri Aug 4 17:11:54 2006
@@ -239,10 +239,24 @@
return ret
close.unwrap_spec = ['self']
+
+ def tell(self):
+ """tell() -> int
+
+ Return the current file position, an integer (may be a long integer)."""
+
+ if self.mode == MODE_CLOSED:
+ raise OperationError(self.space.w_ValueError,
+ self.space.wrap("I/O operation on closed file"))
+
+ return self.space.wrap(self.pos)
+ tell.unwrap_spec = ['self']
_BZ2File.typedef = TypeDef("_BZ2File",
close = interp2app(_BZ2File.close,
unwrap_spec=_BZ2File.close.unwrap_spec),
+ tell = interp2app(_BZ2File.tell,
+ unwrap_spec=_BZ2File.tell.unwrap_spec),
)
def BZ2File(space, filename, mode='r', buffering=-1, compresslevel=9):
Modified: pypy/dist/pypy/module/bz2/test/test_bz2.py
==============================================================================
--- pypy/dist/pypy/module/bz2/test/test_bz2.py (original)
+++ pypy/dist/pypy/module/bz2/test/test_bz2.py Fri Aug 4 17:11:54 2006
@@ -26,16 +26,28 @@
def test_close(self):
from bz2 import BZ2File
- # readonly
+ # writeonly
bz2f = BZ2File("foo", mode='w')
bz2f.close()
# since we use fclose() internally you can't close it twice
# bz2f.close()
- # writeonly
+ # readonly
bz2f = BZ2File("foo", mode='r')
bz2f.close()
+ def test_tell(self):
+ from bz2 import BZ2File
+
+ bz2f = BZ2File("foo", mode='w')
+ bz2f.close()
+ raises(ValueError, bz2f.tell)
+
+ bz2f = BZ2File("foo", mode='w')
+ pos = bz2f.tell()
+ assert pos == 0
+
+
# #!/usr/bin/python
# from test import test_support
# from test.test_support import TESTFN
More information about the Pypy-commit
mailing list