summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_io.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-03-08 00:43:48 (GMT)
committerGuido van Rossum <guido@python.org>2007-03-08 00:43:48 (GMT)
commita9e2024b8443959cc906958d161afe9f0d08bc25 (patch)
treee90d1893c99002ba822e9f7e9b4c41ce79923774 /Lib/test/test_io.py
parent4d0f5a4934854207948115b14b4643a6cb600a0d (diff)
downloadcpython-a9e2024b8443959cc906958d161afe9f0d08bc25.zip
cpython-a9e2024b8443959cc906958d161afe9f0d08bc25.tar.gz
cpython-a9e2024b8443959cc906958d161afe9f0d08bc25.tar.bz2
Check in Daniel Stutzbach's _fileio.c and test_fileio.py
(see SF#1671314) with small tweaks. The io module now uses this instead of its own implementation of the FileIO class, if it can import _fileio.
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r--Lib/test/test_io.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 193130e..956a502 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -5,7 +5,9 @@ from test import test_support
import io
+
class MockIO(io.RawIOBase):
+
def __init__(self, readStack=()):
self._readStack = list(readStack)
self._writeStack = []
@@ -38,10 +40,13 @@ class MockIO(io.RawIOBase):
def tell(self):
return 42
+
class MockNonBlockWriterIO(io.RawIOBase):
+
def __init__(self, blockingScript):
self.bs = list(blockingScript)
self._write_stack = []
+
def write(self, b):
self._write_stack.append(b)
n = self.bs.pop(0)
@@ -49,9 +54,11 @@ class MockNonBlockWriterIO(io.RawIOBase):
raise io.BlockingIO(0, "test blocking", -n)
else:
return n
+
def writable(self):
return True
+
class IOTest(unittest.TestCase):
def tearDown(self):
@@ -110,7 +117,38 @@ class IOTest(unittest.TestCase):
f = io.BytesIO(data)
self.read_ops(f)
+ def test_fileio_FileIO(self):
+ import _fileio
+ f = _fileio._FileIO(test_support.TESTFN, "w")
+ self.assertEqual(f.readable(), False)
+ self.assertEqual(f.writable(), True)
+ self.assertEqual(f.seekable(), True)
+ self.write_ops(f)
+ f.close()
+ f = _fileio._FileIO(test_support.TESTFN, "r")
+ self.assertEqual(f.readable(), True)
+ self.assertEqual(f.writable(), False)
+ self.assertEqual(f.seekable(), True)
+ self.read_ops(f)
+ f.close()
+
+ def test_PyFileIO(self):
+ f = io._PyFileIO(test_support.TESTFN, "w")
+ self.assertEqual(f.readable(), False)
+ self.assertEqual(f.writable(), True)
+ self.assertEqual(f.seekable(), True)
+ self.write_ops(f)
+ f.close()
+ f = io._PyFileIO(test_support.TESTFN, "r")
+ self.assertEqual(f.readable(), True)
+ self.assertEqual(f.writable(), False)
+ self.assertEqual(f.seekable(), True)
+ self.read_ops(f)
+ f.close()
+
+
class BytesIOTest(unittest.TestCase):
+
def testInit(self):
buf = b"1234567890"
bytesIo = io.BytesIO(buf)
@@ -152,7 +190,9 @@ class BytesIOTest(unittest.TestCase):
bytesIo.seek(10000)
self.assertEquals(10000, bytesIo.tell())
+
class BufferedReaderTest(unittest.TestCase):
+
def testRead(self):
rawIo = MockIO((b"abc", b"d", b"efg"))
bufIo = io.BufferedReader(rawIo)
@@ -193,7 +233,9 @@ class BufferedReaderTest(unittest.TestCase):
# this test. Else, write it.
pass
+
class BufferedWriterTest(unittest.TestCase):
+
def testWrite(self):
# Write to the buffered IO but don't overflow the buffer.
writer = MockIO()
@@ -246,7 +288,9 @@ class BufferedWriterTest(unittest.TestCase):
self.assertEquals(b"abc", writer._writeStack[0])
+
class BufferedRWPairTest(unittest.TestCase):
+
def testRWPair(self):
r = MockIO(())
w = MockIO()
@@ -254,7 +298,9 @@ class BufferedRWPairTest(unittest.TestCase):
# XXX need implementation
+
class BufferedRandom(unittest.TestCase):
+
def testReadAndWrite(self):
raw = MockIO((b"asdf", b"ghjk"))
rw = io.BufferedRandom(raw, 8, 12)