Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(53)

Side by Side Diff: Lib/test/test_io.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_ioctl.py ('k') | Lib/test/test_itertools.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Unit tests for the io module.""" 1 """Unit tests for the io module."""
2 2
3 # Tests of io are scattered over the test suite: 3 # Tests of io are scattered over the test suite:
4 # * test_bufio - tests file buffering 4 # * test_bufio - tests file buffering
5 # * test_memoryio - tests BytesIO and StringIO 5 # * test_memoryio - tests BytesIO and StringIO
6 # * test_fileio - tests FileIO 6 # * test_fileio - tests FileIO
7 # * test_file - tests the file interface 7 # * test_file - tests the file interface
8 # * test_io - tests everything else in the io module 8 # * test_io - tests everything else in the io module
9 # * test_univnewlines - tests universal newline support 9 # * test_univnewlines - tests universal newline support
10 # * test_largefile - tests operations on a file greater than 2**32 bytes 10 # * test_largefile - tests operations on a file greater than 2**32 bytes
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 self.assertEqual(rawio.read(2), b"ab") 604 self.assertEqual(rawio.read(2), b"ab")
605 self.assertEqual(rawio.read(2), b"c") 605 self.assertEqual(rawio.read(2), b"c")
606 self.assertEqual(rawio.read(2), b"d") 606 self.assertEqual(rawio.read(2), b"d")
607 self.assertEqual(rawio.read(2), None) 607 self.assertEqual(rawio.read(2), None)
608 self.assertEqual(rawio.read(2), b"ef") 608 self.assertEqual(rawio.read(2), b"ef")
609 self.assertEqual(rawio.read(2), b"g") 609 self.assertEqual(rawio.read(2), b"g")
610 self.assertEqual(rawio.read(2), None) 610 self.assertEqual(rawio.read(2), None)
611 self.assertEqual(rawio.read(2), b"") 611 self.assertEqual(rawio.read(2), b"")
612 612
613 class CIOTest(IOTest): 613 class CIOTest(IOTest):
614 614 pass
615 def test_IOBase_finalize(self):
616 # Issue #12149: segmentation fault on _PyIOBase_finalize when both a
617 # class which inherits IOBase and an object of this class are caught
618 # in a reference cycle and close() is already in the method cache.
619 class MyIO(self.IOBase):
620 def close(self):
621 pass
622
623 # create an instance to populate the method cache
624 MyIO()
625 obj = MyIO()
626 obj.obj = obj
627 wr = weakref.ref(obj)
628 del MyIO
629 del obj
630 support.gc_collect()
631 self.assertTrue(wr() is None, wr)
632 615
633 class PyIOTest(IOTest): 616 class PyIOTest(IOTest):
634 pass 617 pass
635 618
636 619
637 class CommonBufferedTests: 620 class CommonBufferedTests:
638 # Tests common to BufferedReader, BufferedWriter and BufferedRandom 621 # Tests common to BufferedReader, BufferedWriter and BufferedRandom
639 622
640 def test_detach(self): 623 def test_detach(self):
641 raw = self.MockRawIO() 624 raw = self.MockRawIO()
(...skipping 1664 matching lines...) Expand 10 before | Expand all | Expand 10 after
2306 def test_unseekable(self): 2289 def test_unseekable(self):
2307 txt = self.TextIOWrapper(self.MockUnseekableIO(self.testdata)) 2290 txt = self.TextIOWrapper(self.MockUnseekableIO(self.testdata))
2308 self.assertRaises(self.UnsupportedOperation, txt.tell) 2291 self.assertRaises(self.UnsupportedOperation, txt.tell)
2309 self.assertRaises(self.UnsupportedOperation, txt.seek, 0) 2292 self.assertRaises(self.UnsupportedOperation, txt.seek, 0)
2310 2293
2311 def test_readonly_attributes(self): 2294 def test_readonly_attributes(self):
2312 txt = self.TextIOWrapper(self.BytesIO(self.testdata), encoding="ascii") 2295 txt = self.TextIOWrapper(self.BytesIO(self.testdata), encoding="ascii")
2313 buf = self.BytesIO(self.testdata) 2296 buf = self.BytesIO(self.testdata)
2314 with self.assertRaises(AttributeError): 2297 with self.assertRaises(AttributeError):
2315 txt.buffer = buf 2298 txt.buffer = buf
2316
2317 def test_rawio(self):
2318 # Issue #12591: TextIOWrapper must work with raw I/O objects, so
2319 # that subprocess.Popen() can have the required unbuffered
2320 # semantics with universal_newlines=True.
2321 raw = self.MockRawIO([b'abc', b'def', b'ghi\njkl\nopq\n'])
2322 txt = self.TextIOWrapper(raw, encoding='ascii', newline='\n')
2323 # Reads
2324 self.assertEqual(txt.read(4), 'abcd')
2325 self.assertEqual(txt.readline(), 'efghi\n')
2326 self.assertEqual(list(txt), ['jkl\n', 'opq\n'])
2327
2328 def test_rawio_write_through(self):
2329 # Issue #12591: with write_through=True, writes don't need a flush
2330 raw = self.MockRawIO([b'abc', b'def', b'ghi\njkl\nopq\n'])
2331 txt = self.TextIOWrapper(raw, encoding='ascii', newline='\n',
2332 write_through=True)
2333 txt.write('1')
2334 txt.write('23\n4')
2335 txt.write('5')
2336 self.assertEqual(b''.join(raw._write_stack), b'123\n45')
2337 2299
2338 class CTextIOWrapperTest(TextIOWrapperTest): 2300 class CTextIOWrapperTest(TextIOWrapperTest):
2339 2301
2340 def test_initialization(self): 2302 def test_initialization(self):
2341 r = self.BytesIO(b"\xc3\xa9\n\n") 2303 r = self.BytesIO(b"\xc3\xa9\n\n")
2342 b = self.BufferedReader(r, 1000) 2304 b = self.BufferedReader(r, 1000)
2343 t = self.TextIOWrapper(b) 2305 t = self.TextIOWrapper(b)
2344 self.assertRaises(TypeError, t.__init__, b, newline=42) 2306 self.assertRaises(TypeError, t.__init__, b, newline=42)
2345 self.assertRaises(ValueError, t.read) 2307 self.assertRaises(ValueError, t.read)
2346 self.assertRaises(ValueError, t.__init__, b, newline='xyzzy') 2308 self.assertRaises(ValueError, t.__init__, b, newline='xyzzy')
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
2916 for name, obj in c_io_ns.items(): 2878 for name, obj in c_io_ns.items():
2917 setattr(test, name, obj) 2879 setattr(test, name, obj)
2918 elif test.__name__.startswith("Py"): 2880 elif test.__name__.startswith("Py"):
2919 for name, obj in py_io_ns.items(): 2881 for name, obj in py_io_ns.items():
2920 setattr(test, name, obj) 2882 setattr(test, name, obj)
2921 2883
2922 support.run_unittest(*tests) 2884 support.run_unittest(*tests)
2923 2885
2924 if __name__ == "__main__": 2886 if __name__ == "__main__":
2925 test_main() 2887 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_ioctl.py ('k') | Lib/test/test_itertools.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+