[pypy-svn] r36398 - in pypy/dist/pypy/lib: . test2

exarkun at codespeak.net exarkun at codespeak.net
Wed Jan 10 02:57:34 CET 2007


Author: exarkun
Date: Wed Jan 10 02:57:32 2007
New Revision: 36398

Added:
   pypy/dist/pypy/lib/test2/test_cstringio.py
Modified:
   pypy/dist/pypy/lib/cStringIO.py
Log:
Add cStringIO.StringIO.reset - an alternate spelling of seek(0, 0) only available on cStringIO objects

Modified: pypy/dist/pypy/lib/cStringIO.py
==============================================================================
--- pypy/dist/pypy/lib/cStringIO.py	(original)
+++ pypy/dist/pypy/lib/cStringIO.py	Wed Jan 10 02:57:32 2007
@@ -1,6 +1,13 @@
 #
-# One-liner implementation of cStringIO
+# StringIO-based cStringIO implementation.
 #
 
 from StringIO import *
 from StringIO import __doc__
+
+class StringIO(StringIO):
+    def reset(self):
+        """
+        reset() -- Reset the file position to the beginning
+        """
+        self.seek(0, 0)

Added: pypy/dist/pypy/lib/test2/test_cstringio.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lib/test2/test_cstringio.py	Wed Jan 10 02:57:32 2007
@@ -0,0 +1,30 @@
+
+"""
+Tests for the PyPy cStringIO implementation.
+"""
+
+from pypy.conftest import gettestobjspace
+
+class AppTestcStringIO:
+    def setup_class(cls):
+        cls.space = gettestobjspace()
+        cls.w_io = cls.space.appexec([], "(): import cStringIO; return cStringIO")
+        cls.w_bytes = cls.space.wrap('some bytes')
+
+
+    def test_reset(self):
+        """
+        Test that the reset method of cStringIO objects sets the position
+        marker to the beginning of the stream.
+        """
+        io = self.io.StringIO()
+        io.write(self.bytes)
+        assert io.read() == ''
+        io.reset()
+        assert io.read() == self.bytes
+
+        io = self.io.StringIO(self.bytes)
+        assert io.read() == self.bytes
+        assert io.read() == ''
+        io.reset()
+        assert io.read() == self.bytes



More information about the Pypy-commit mailing list