[pypy-svn] r49406 - pypy/branch/pypy-interp-file/module/_file/test

arigo at codespeak.net arigo at codespeak.net
Wed Dec 5 19:47:44 CET 2007


Author: arigo
Date: Wed Dec  5 19:47:42 2007
New Revision: 49406

Modified:
   pypy/branch/pypy-interp-file/module/_file/test/test_file_extra.py
Log:
In the process of resurrecting this test 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:47:42 2007
@@ -1,8 +1,6 @@
 import os, random, sys
 import pypy.tool.udir
 import py
-py.test.skip("XXX convert this to a normal applevel test!")
-from pypy.interpreter.mixedmodule import testmodule
 
 udir = pypy.tool.udir.udir.ensure('test_file_extra', dir=1)
 
@@ -15,11 +13,7 @@
 
 
 def setup_module(mod):
-    mod._file = testmodule("_file")
     udir.join('sample').write(SAMPLE)
-    # workaround for testing _file on top of CPython
-    if not hasattr(sys, 'pypy_objspaceclass'):
-        sys.pypy__exithandlers__ = {}
 
 
 class BaseROTests:
@@ -74,13 +68,6 @@
 
     def test_isatty(self):
         assert not self.file.isatty()
-        try:
-            f = _file.file('/dev/tty')
-        except IOError:
-            pass
-        else:
-            assert f.isatty()
-            f.close()
 
     def test_next(self):
         lines = self.expected_lines()
@@ -213,23 +200,28 @@
     extra_args = ()
 
     def setup_method(self, method):
-        self.file = _file.file(self.expected_filename,
-                               self.expected_mode,
-                               *self.extra_args)
+        from pypy.module._file.interp_file import W_File
+        space = self.space
+        w_filetype = space.gettypeobject(W_File.typedef)
+        self.w_file = space.call_function(
+            w_filetype,
+            space.wrap(self.expected_filename),
+            space.wrap(self.expected_mode),
+            *[space.wrap(a) for a in self.extra_args])
 
     def teardown_method(self, method):
-        self.file.close()
+        self.space.call_method(self.w_file, 'close')
 
 
-class TestUnbufferedFile(TestFile):
+class AppTestUnbufferedFile(AppTestFile):
     extra_args = (0,)
 
 
-class TestLineBufferedFile(TestFile):
+class AppTestLineBufferedFile(AppTestFile):
     extra_args = (1,)
 
 
-class TestLargeBufferFile(TestFile):
+class AppTestLargeBufferFile(AppTestFile):
     extra_args = (len(SAMPLE),)
 
 
@@ -238,18 +230,21 @@
 #  Check on top of CPython
 
 
-class TestWithCPython(TestFile):
+class TestWithCPython(BaseROTests):
+    expected_filename = str(udir.join('sample'))
+    expected_mode     = 'rb'
+
     def setup_method(self, method):
-        self.file = open(self.expected_filename,
-                         self.expected_mode,
-                         *self.extra_args)
+        self.file = open(self.expected_filename, self.expected_mode)
 
+    def teardown_method(self, method):
+        self.file.close()
 
 # ____________________________________________________________
 #
 #  Files built with fdopen()
 
-class TestFdOpen(BaseROTests):
+class AppTestFdOpen(BaseROTests):
     expected_filename  = None
     expected_mode      = 'rb'
     extra_args = ()
@@ -265,15 +260,15 @@
         self.file.close()
 
 
-class TestUnbufferedFdOpen(TestFdOpen):
+class AppTestUnbufferedFdOpen(AppTestFdOpen):
     extra_args = (0,)
 
 
-class TestLineBufferedFdOpen(TestFdOpen):
+class AppTestLineBufferedFdOpen(AppTestFdOpen):
     extra_args = (1,)
 
 
-class TestLargeBufferFdOpen(TestFdOpen):
+class AppTestLargeBufferFdOpen(AppTestFdOpen):
     extra_args = (len(SAMPLE),)
 
 
@@ -281,7 +276,7 @@
 #
 #  Universal newlines
 
-class TestUniversalNewlines(TestFile):
+class AppTestUniversalNewlines(AppTestFile):
     expected_mode = 'rU'
     sample = '\n'.join(SAMPLE.splitlines(False))
 
@@ -291,15 +286,15 @@
     test_tell = test_seek
 
 
-class TestUnbufferedUniversal(TestUniversalNewlines):
+class AppTestUnbufferedUniversal(AppTestUniversalNewlines):
     extra_args = (0,)
 
 
-class TestLineBufferedUniversal(TestUniversalNewlines):
+class AppTestLineBufferedUniversal(AppTestUniversalNewlines):
     extra_args = (1,)
 
 
-class TestLargeBufferUniversal(TestUniversalNewlines):
+class AppTestLargeBufferUniversal(AppTestUniversalNewlines):
     extra_args = (len(SAMPLE),)
 
 
@@ -307,7 +302,7 @@
 #
 #  A few extra tests
 
-def test_case_readonly():
+def app_test_case_readonly():
     fn = str(udir.join('temptestfile'))
     f = _file.file(fn, 'w')
     assert f.name == fn
@@ -316,7 +311,7 @@
     assert f.encoding == None # Fix when we find out what this is
     py.test.raises((TypeError, AttributeError), setattr, f, 'name', 42)
 
-def test_readlines():
+def app_test_readlines():
     fn = str(udir.join('temptestfile'))
     lines = ['line%d\n' % i for i in range(1000)]
     f=_file.file(fn, 'w')
@@ -328,7 +323,11 @@
     assert len(somelines) > 200
     assert somelines == lines[:len(somelines)]
 
-def stresstest(flags, checkflags, eolstyles):
+def app_test_rw_bin():
+    flags = 'w+b'
+    checkflags = 'rb'
+    eolstyles = [('', ''),     ('\n', '\n'),
+                 ('\r', '\r'), ('\r\n', '\r\n')]
     fn = str(udir.join('temptestfile'))
     f = _file.file(fn, flags)
     expected = ''
@@ -372,11 +371,7 @@
     g.close()
     assert buf == expected
 
-def test_rw_bin():
-    stresstest('w+b', 'rb', [('', ''),     ('\n', '\n'),
-                                  ('\r', '\r'), ('\r\n', '\r\n')])
-
-def test_rw():
+def app_test_rw():
     fn = str(udir.join('temptestfile'))
     f = _file.file(fn, 'w+')
     f.write('hello\nworld\n')
@@ -384,7 +379,7 @@
     assert f.read() == 'hello\nworld\n'
     f.close()
 
-def test_r_universal():
+def app_test_r_universal():
     fn = str(udir.join('temptestfile'))
     f = open(fn, 'wb')
     f.write('hello\r\nworld\r\n')
@@ -393,7 +388,7 @@
     assert f.read() == 'hello\nworld\n'
     f.close()
 
-def test_flush():
+def app_test_flush():
     fn = str(udir.join('temptestfile'))
     f = _file.file(fn, 'w', 0)
     f.write('x')
@@ -423,3 +418,12 @@
     assert os.stat(fn).st_size == 3
     f.close()
     assert os.stat(fn).st_size == 3
+
+def app_test_isatty():
+    try:
+        f = file('/dev/tty')
+    except IOError:
+        pass
+    else:
+        assert f.isatty()
+        f.close()



More information about the Pypy-commit mailing list