Changeset 391 for python/trunk/Lib/test/test_bufio.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/test/test_bufio.py
r2 r391 1 1 import unittest 2 from test import test_support 2 from test import test_support as support 3 3 4 # Simple test to ensure that optimizations in fileobject.c deliver 5 # the expected results. For best testing, run this under a debug-build 6 # Python too (to exercise asserts in the C code). 4 import io # C implementation. 5 import _pyio as pyio # Python implementation. 7 6 8 lengths = range(1, 257) + [512, 1000, 1024, 2048, 4096, 8192, 10000, 9 16384, 32768, 65536, 1000000] 7 # Simple test to ensure that optimizations in the IO library deliver the 8 # expected results. For best testing, run this under a debug-build Python too 9 # (to exercise asserts in the C code). 10 11 lengths = list(range(1, 257)) + [512, 1000, 1024, 2048, 4096, 8192, 10000, 12 16384, 32768, 65536, 1000000] 10 13 11 14 class BufferSizeTest(unittest.TestCase): … … 15 18 16 19 # Ensure we can open TESTFN for writing. 17 test_support.unlink(test_support.TESTFN)20 support.unlink(support.TESTFN) 18 21 19 22 # Since C doesn't guarantee we can write/read arbitrary bytes in text 20 23 # files, use binary mode. 21 f = open(test_support.TESTFN, "wb")24 f = self.open(support.TESTFN, "wb") 22 25 try: 23 26 # write once with \n and once without 24 27 f.write(s) 25 f.write( "\n")28 f.write(b"\n") 26 29 f.write(s) 27 30 f.close() 28 f = open( test_support.TESTFN, "rb")31 f = open(support.TESTFN, "rb") 29 32 line = f.readline() 30 self.assertEqual(line, s + "\n")33 self.assertEqual(line, s + b"\n") 31 34 line = f.readline() 32 35 self.assertEqual(line, s) 33 36 line = f.readline() 34 self.assert _(not line) # Must be at EOF37 self.assertTrue(not line) # Must be at EOF 35 38 f.close() 36 39 finally: 37 test_support.unlink(test_support.TESTFN)40 support.unlink(support.TESTFN) 38 41 39 42 def drive_one(self, pattern): … … 48 51 self.assertEqual(len(teststring), length) 49 52 self.try_one(teststring) 50 self.try_one(teststring + "x")53 self.try_one(teststring + b"x") 51 54 self.try_one(teststring[:-1]) 52 55 … … 54 57 # A pattern with prime length, to avoid simple relationships with 55 58 # stdio buffer sizes. 56 self.drive_one( "1234567890\00\01\02\03\04\05\06")59 self.drive_one(b"1234567890\00\01\02\03\04\05\06") 57 60 58 61 def test_nullpat(self): 59 self.drive_one("\0" * 1000) 62 self.drive_one(bytes(1000)) 63 64 65 class CBufferSizeTest(BufferSizeTest): 66 open = io.open 67 68 class PyBufferSizeTest(BufferSizeTest): 69 open = staticmethod(pyio.open) 70 71 class BuiltinBufferSizeTest(BufferSizeTest): 72 open = open 73 60 74 61 75 def test_main(): 62 test_support.run_unittest(BufferSizeTest)76 support.run_unittest(CBufferSizeTest, PyBufferSizeTest, BuiltinBufferSizeTest) 63 77 64 78 if __name__ == "__main__":
Note:
See TracChangeset
for help on using the changeset viewer.