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

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

Issue 22671: Typo in class io.BufferedIOBase docs
Patch Set: Created 4 years, 11 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 | « Doc/library/io.rst ('k') | no next file » | 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 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 self.assertTrue(f.closed) 598 self.assertTrue(f.closed)
599 599
600 def test_multi_close(self): 600 def test_multi_close(self):
601 f = self.open(support.TESTFN, "wb", buffering=0) 601 f = self.open(support.TESTFN, "wb", buffering=0)
602 f.close() 602 f.close()
603 f.close() 603 f.close()
604 f.close() 604 f.close()
605 self.assertRaises(ValueError, f.flush) 605 self.assertRaises(ValueError, f.flush)
606 606
607 def test_RawIOBase_read(self): 607 def test_RawIOBase_read(self):
608 # Exercise the default RawIOBase.read() implementation (which calls 608 # Exercise the default RawIOBase.read() and readall() implementations
storchaka 2015/03/21 19:22:00 May be create separate test for readall?
Martin Panter 2015/03/22 00:09:01 Okay
609 # readinto() internally). 609 # (which call readinto() internally).
610 rawio = self.MockRawIOWithoutRead((b"abc", b"d", None, b"efg", None)) 610 rawio = self.MockRawIOWithoutRead((b"abc", b"d", None, b"efg", None))
611 self.assertEqual(rawio.read(2), b"ab") 611 self.assertEqual(rawio.read(2), b"ab")
612 self.assertEqual(rawio.read(2), b"c") 612 self.assertEqual(rawio.read(2), b"c")
613 self.assertEqual(rawio.read(2), b"d") 613 self.assertEqual(rawio.read(2), b"d")
614 self.assertEqual(rawio.read(2), None) 614 self.assertEqual(rawio.read(2), None)
615 self.assertEqual(rawio.read(2), b"ef") 615 self.assertEqual(rawio.read(2), b"ef")
616 self.assertEqual(rawio.read(2), b"g") 616 self.assertEqual(rawio.read(2), b"g")
617 self.assertEqual(rawio.read(2), None) 617 self.assertEqual(rawio.read(2), None)
618 self.assertEqual(rawio.read(2), b"") 618 self.assertEqual(rawio.read(2), b"")
619
620 rawio = self.MockRawIOWithoutRead((b"abc", b"d", b"efg"))
621 self.assertEqual(rawio.read(), b"abcdefg")
622 rawio = self.MockRawIOWithoutRead((b"abc", b"d", b"efg"))
623 self.assertEqual(rawio.readall(), b"abcdefg")
624
625 def test_BufferedIOBase_readinto(self):
626 # Exercise the default BufferedIOBase.readinto() and readinto1()
627 # implementations (which call read() or read1() internally).
628 class Reader(self.BufferedIOBase):
629 def read(self, size):
630 result = self.avail[:size]
631 self.avail = self.avail[size:]
632 return result
633 def read1(self, size):
634 return self.read(min(size, 5))
635 tests = (
636 dict(method="readinto", avail=10, request=5, result=5),
storchaka 2015/03/21 19:22:00 This is too verbose. Tuples would look cleaner. An
Martin Panter 2015/03/22 00:09:01 Perhaps a matrix of tuples with a comment at the t
637 dict(method="readinto", avail=10, request=6, result=6),
638 dict(method="readinto", avail=5, request=6, result=5),
639 dict(method="readinto", avail=6, request=7, result=6),
640 dict(method="readinto1", avail=10, request=5, result=5),
641 dict(method="readinto1", avail=10, request=6, result=5),
642 dict(method="readinto1", avail=5, request=6, result=5),
643 dict(method="readinto1", avail=6, request=7, result=5),
644 )
storchaka 2015/03/21 19:22:00 Does it make sense to add tests for request=0 or -
Martin Panter 2015/03/22 00:09:01 request=0: yes; request=-1: no, because you can’t
645 for test in tests:
646 with self.subTest(**test):
647 reader = Reader()
648 reader.avail = bytes(range(test["avail"]))
649 buffer = bytearray(test["request"])
650 call = getattr(reader, test["method"])
651 size = test["result"]
652 self.assertEqual(call(buffer), size)
653 self.assertEqual(len(buffer), test["request"])
654 self.assertSequenceEqual(buffer[:size], range(size))
storchaka 2015/03/21 19:22:00 Fill buffer before reading and test that buffer[si
655 self.assertEqual(len(reader.avail), test["avail"] - size)
619 656
620 def test_types_have_dict(self): 657 def test_types_have_dict(self):
621 test = ( 658 test = (
622 self.IOBase(), 659 self.IOBase(),
623 self.RawIOBase(), 660 self.RawIOBase(),
624 self.TextIOBase(), 661 self.TextIOBase(),
625 self.StringIO(), 662 self.StringIO(),
626 self.BytesIO() 663 self.BytesIO()
627 ) 664 )
628 for obj in test: 665 for obj in test:
(...skipping 2951 matching lines...) Expand 10 before | Expand all | Expand 10 after
3580 setattr(test, name, obj) 3617 setattr(test, name, obj)
3581 elif test.__name__.startswith("Py"): 3618 elif test.__name__.startswith("Py"):
3582 for name, obj in py_io_ns.items(): 3619 for name, obj in py_io_ns.items():
3583 setattr(test, name, obj) 3620 setattr(test, name, obj)
3584 3621
3585 suite = unittest.TestSuite([unittest.makeSuite(test) for test in tests]) 3622 suite = unittest.TestSuite([unittest.makeSuite(test) for test in tests])
3586 return suite 3623 return suite
3587 3624
3588 if __name__ == "__main__": 3625 if __name__ == "__main__":
3589 unittest.main() 3626 unittest.main()
OLDNEW
« no previous file with comments | « Doc/library/io.rst ('k') | no next file » | no next file with comments »

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