[pypy-svn] r49407 - in pypy/branch/pypy-interp-file/module/_file: . test

arigo at codespeak.net arigo at codespeak.net
Wed Dec 5 19:51:23 CET 2007


Author: arigo
Date: Wed Dec  5 19:51:22 2007
New Revision: 49407

Modified:
   pypy/branch/pypy-interp-file/module/_file/app_file.py
   pypy/branch/pypy-interp-file/module/_file/interp_file.py
   pypy/branch/pypy-interp-file/module/_file/test/test_file_extra.py
Log:
file.tell().  More test fixing.


Modified: pypy/branch/pypy-interp-file/module/_file/app_file.py
==============================================================================
--- pypy/branch/pypy-interp-file/module/_file/app_file.py	(original)
+++ pypy/branch/pypy-interp-file/module/_file/app_file.py	Wed Dec  5 19:51:22 2007
@@ -38,7 +38,7 @@
         return f
     fdopen = classmethod(fdopen)
 
-    def tmpfile(cls, stream):
+    #def tmpfile(cls, stream):
         f = cls.__new__(cls)
         fd = stream.try_to_find_file_descriptor()
         assert fd != -1
@@ -46,7 +46,7 @@
         return f
     tmpfile = classmethod(tmpfile)
 
-    def _fdopenstream(self, fd, mode, buffering, name, stream):
+    #def _fdopenstream(self, fd, mode, buffering, name, stream):
         self.fd = fd
         self._name = name
         self.softspace = 0    # Required according to file object docs
@@ -57,7 +57,7 @@
         if stream.flushable():
             sys.pypy__exithandlers__[stream] = stream.flush
 
-    def getnewlines(self):
+    #def getnewlines(self):
         "end-of-line convention used in this file"
 
         newlines = self.stream.getnewlines()
@@ -85,8 +85,8 @@
     name     = property(lambda self: self._name, doc = "file name")
     closed   = property(lambda self: self._closed,
                         doc = "True if the file is closed")
-    newlines = property(lambda self: self.getnewlines(),
-                        doc = "end-of-line convention used in this file")
+    #newlines = property(lambda self: self.getnewlines(),
+    #                    doc = "end-of-line convention used in this file")
 
     #def read(self, n=-1):
         """read([size]) -> read at most size bytes, returned as a string.
@@ -196,7 +196,7 @@
         for line in sequence_of_strings:
             self.stream.write(line)
 
-    def tell(self):
+    #def tell(self):
         """tell() -> current file position, an integer (may be a long integer)."""
         if self._closed:
             raise ValueError('I/O operation on closed file')

Modified: pypy/branch/pypy-interp-file/module/_file/interp_file.py
==============================================================================
--- pypy/branch/pypy-interp-file/module/_file/interp_file.py	(original)
+++ pypy/branch/pypy-interp-file/module/_file/interp_file.py	Wed Dec  5 19:51:22 2007
@@ -152,6 +152,9 @@
     def direct_seek(self, offset, whence=0):
         self.getstream().seek(offset, whence)
 
+    def direct_tell(self):
+        return self.getstream().tell()
+
     def direct_write(self, data):
         self.getstream().write(data)
 
@@ -261,6 +264,9 @@
 undefined behavior.
 Note that not all file objects are seekable.""")
 
+    _decl(locals(), "tell", ['self'],
+        "tell() -> current file position, an integer (may be a long integer).")
+
     _decl(locals(), "write", ['self', str],
         """write(str) -> None.  Write string str to file.
 

Modified: pypy/branch/pypy-interp-file/module/_file/test/test_file_extra.py
==============================================================================
--- pypy/branch/pypy-interp-file/module/_file/test/test_file_extra.py	(original)
+++ pypy/branch/pypy-interp-file/module/_file/test/test_file_extra.py	Wed Dec  5 19:51:22 2007
@@ -19,7 +19,7 @@
 class BaseROTests:
     sample = SAMPLE
 
-    def expected_lines(self):
+    def get_expected_lines(self):
         lines = self.sample.split('\n')
         for i in range(len(lines)-1):
             lines[i] += '\n'
@@ -33,7 +33,7 @@
         assert data1 == self.sample
 
     def test_readline(self):
-        lines = self.expected_lines()
+        lines = self.expected_lines
         for sampleline in lines:
             inputline = self.file.readline()
             assert inputline == sampleline
@@ -42,6 +42,7 @@
             assert inputline == ""
 
     def test_readline_max(self):
+        import random
         i = 0
         stop = 0
         while stop < 5:
@@ -58,7 +59,7 @@
 
     def test_iter(self):
         inputlines = list(self.file)
-        assert inputlines == self.expected_lines()
+        assert inputlines == self.expected_lines
 
     def test_repr(self):
         r = repr(self.file)
@@ -70,7 +71,7 @@
         assert not self.file.isatty()
 
     def test_next(self):
-        lines = self.expected_lines()
+        lines = self.expected_lines
         for sampleline in lines:
             inputline = self.file.next()
             assert inputline == sampleline
@@ -78,6 +79,7 @@
             py.test.raises(StopIteration, self.file.next)
 
     def test_read(self):
+        import random
         i = 0
         stop = 0
         while stop < 5:
@@ -91,12 +93,13 @@
 
     def test_readlines(self):
         lines = self.file.readlines()
-        assert lines == self.expected_lines()
+        assert lines == self.expected_lines
 
     def test_readlines_max(self):
+        import random
         i = 0
         stop = 0
-        samplelines = self.expected_lines()
+        samplelines = self.expected_lines
         while stop < 5:
             morelines = self.file.readlines(random.randrange(1, 300))
             for inputline in morelines:
@@ -110,6 +113,7 @@
                                               # to endless loops
 
     def test_seek(self):
+        import random
         for i in range(100):
             position = random.randrange(0, len(self.sample))
             self.file.seek(position)
@@ -129,6 +133,7 @@
             prevpos = position + 1
 
     def test_tell(self):
+        import random
         for i in range(100):
             position = random.randrange(0, len(self.sample)+1)
             self.file.seek(position)
@@ -148,6 +153,7 @@
             prevpos = position
 
     def test_tell_and_seek_back(self):
+        import random
         i = 0
         stop = 0
         secondpass = []
@@ -208,6 +214,8 @@
             space.wrap(self.expected_filename),
             space.wrap(self.expected_mode),
             *[space.wrap(a) for a in self.extra_args])
+        self.w_sample = space.wrap(SAMPLE)
+        self.w_expected_lines = space.wrap(self.get_expected_lines())
 
     def teardown_method(self, method):
         self.space.call_method(self.w_file, 'close')



More information about the Pypy-commit mailing list