summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_io.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-02-27 05:47:44 (GMT)
committerGuido van Rossum <guido@python.org>2007-02-27 05:47:44 (GMT)
commit28524c7f10beb2821cae57a165ef920abbf76b77 (patch)
treecdfa308617e0a0b2ce2ee983859aa8d1144e1a32 /Lib/test/test_io.py
parenteff072c66c23b287d2fa77e2ef9114cb97d988dd (diff)
downloadcpython-28524c7f10beb2821cae57a165ef920abbf76b77.zip
cpython-28524c7f10beb2821cae57a165ef920abbf76b77.tar.gz
cpython-28524c7f10beb2821cae57a165ef920abbf76b77.tar.bz2
Checkpoint for new I/O library.
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r--Lib/test/test_io.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
new file mode 100644
index 0000000..0e3b03d
--- /dev/null
+++ b/Lib/test/test_io.py
@@ -0,0 +1,62 @@
+import unittest
+from test import test_support
+
+import io
+
+class IOTest(unittest.TestCase):
+
+ def write_ops(self, f):
+ f.write(b"blah.")
+ f.seek(0)
+ f.write(b"Hello.")
+ self.assertEqual(f.tell(), 6)
+ f.seek(-1, 1)
+ self.assertEqual(f.tell(), 5)
+ f.write(" world\n\n\n")
+ f.seek(0)
+ f.write("h")
+ f.seek(-2, 2)
+ f.truncate()
+
+ def read_ops(self, f):
+ data = f.read(5)
+ self.assertEqual(data, b"hello")
+ f.readinto(data)
+ self.assertEqual(data, b" worl")
+ f.readinto(data)
+ self.assertEqual(data, b"d\n")
+ f.seek(0)
+ self.assertEqual(f.read(20), b"hello world\n")
+ f.seek(-6, 2)
+ self.assertEqual(f.read(5), b"world")
+ f.seek(-6, 1)
+ self.assertEqual(f.read(5), b" worl")
+ self.assertEqual(f.tell(), 10)
+
+ def test_raw_file_io(self):
+ f = io.open(test_support.TESTFN, "wb", buffering=0)
+ self.assertEqual(f.readable(), False)
+ self.assertEqual(f.writable(), True)
+ self.assertEqual(f.seekable(), True)
+ self.write_ops(f)
+ f.close()
+ f = io.open(test_support.TESTFN, "rb", buffering=0)
+ self.assertEqual(f.readable(), True)
+ self.assertEqual(f.writable(), False)
+ self.assertEqual(f.seekable(), True)
+ self.read_ops(f)
+ f.close()
+
+ def test_raw_bytes_io(self):
+ f = io.BytesIO()
+ self.write_ops(f)
+ data = f.getvalue()
+ self.assertEqual(data, b"hello world\n")
+ f = io.BytesIO(data)
+ self.read_ops(f)
+
+def test_main():
+ test_support.run_unittest(IOTest)
+
+if __name__ == "__main__":
+ test_main()