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

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

Issue 16510: Using appropriate checks in tests
Patch Set: Created 6 years 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_optparse.py ('k') | Lib/test/test_ossaudiodev.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 # As a test suite for the os module, this is woefully inadequate, but this 1 # As a test suite for the os module, this is woefully inadequate, but this
2 # does add tests for a few functions which have been determined to be more 2 # does add tests for a few functions which have been determined to be more
3 # portable than they had been thought to be. 3 # portable than they had been thought to be.
4 4
5 import os 5 import os
6 import errno 6 import errno
7 import unittest 7 import unittest
8 import warnings 8 import warnings
9 import sys 9 import sys
10 import signal 10 import signal
(...skipping 1806 matching lines...) Expand 10 before | Expand all | Expand 10 after
1817 # normal send 1817 # normal send
1818 total_sent = 0 1818 total_sent = 0
1819 offset = 0 1819 offset = 0
1820 nbytes = 4096 1820 nbytes = 4096
1821 while total_sent < len(self.DATA): 1821 while total_sent < len(self.DATA):
1822 sent = self.sendfile_wrapper(self.sockno, self.fileno, offset, nbyte s) 1822 sent = self.sendfile_wrapper(self.sockno, self.fileno, offset, nbyte s)
1823 if sent == 0: 1823 if sent == 0:
1824 break 1824 break
1825 offset += sent 1825 offset += sent
1826 total_sent += sent 1826 total_sent += sent
1827 self.assertTrue(sent <= nbytes) 1827 self.assertLessEqual(sent, nbytes)
1828 self.assertEqual(offset, total_sent) 1828 self.assertEqual(offset, total_sent)
1829 1829
1830 self.assertEqual(total_sent, len(self.DATA)) 1830 self.assertEqual(total_sent, len(self.DATA))
1831 self.client.shutdown(socket.SHUT_RDWR) 1831 self.client.shutdown(socket.SHUT_RDWR)
1832 self.client.close() 1832 self.client.close()
1833 self.server.wait() 1833 self.server.wait()
1834 data = self.server.handler_instance.get_data() 1834 data = self.server.handler_instance.get_data()
1835 self.assertEqual(len(data), len(self.DATA)) 1835 self.assertEqual(len(data), len(self.DATA))
1836 self.assertEqual(data, self.DATA) 1836 self.assertEqual(data, self.DATA)
1837 1837
1838 def test_send_at_certain_offset(self): 1838 def test_send_at_certain_offset(self):
1839 # start sending a file at a certain offset 1839 # start sending a file at a certain offset
1840 total_sent = 0 1840 total_sent = 0
1841 offset = len(self.DATA) // 2 1841 offset = len(self.DATA) // 2
1842 must_send = len(self.DATA) - offset 1842 must_send = len(self.DATA) - offset
1843 nbytes = 4096 1843 nbytes = 4096
1844 while total_sent < must_send: 1844 while total_sent < must_send:
1845 sent = self.sendfile_wrapper(self.sockno, self.fileno, offset, nbyte s) 1845 sent = self.sendfile_wrapper(self.sockno, self.fileno, offset, nbyte s)
1846 if sent == 0: 1846 if sent == 0:
1847 break 1847 break
1848 offset += sent 1848 offset += sent
1849 total_sent += sent 1849 total_sent += sent
1850 self.assertTrue(sent <= nbytes) 1850 self.assertLessEqual(sent, nbytes)
1851 1851
1852 self.client.shutdown(socket.SHUT_RDWR) 1852 self.client.shutdown(socket.SHUT_RDWR)
1853 self.client.close() 1853 self.client.close()
1854 self.server.wait() 1854 self.server.wait()
1855 data = self.server.handler_instance.get_data() 1855 data = self.server.handler_instance.get_data()
1856 expected = self.DATA[len(self.DATA) // 2:] 1856 expected = self.DATA[len(self.DATA) // 2:]
1857 self.assertEqual(total_sent, len(expected)) 1857 self.assertEqual(total_sent, len(expected))
1858 self.assertEqual(len(data), len(expected)) 1858 self.assertEqual(len(data), len(expected))
1859 self.assertEqual(data, expected) 1859 self.assertEqual(data, expected)
1860 1860
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
2228 ProgramPriorityTests, 2228 ProgramPriorityTests,
2229 ExtendedAttributeTests, 2229 ExtendedAttributeTests,
2230 Win32DeprecatedBytesAPI, 2230 Win32DeprecatedBytesAPI,
2231 TermsizeTests, 2231 TermsizeTests,
2232 OSErrorTests, 2232 OSErrorTests,
2233 RemoveDirsTests, 2233 RemoveDirsTests,
2234 ) 2234 )
2235 2235
2236 if __name__ == "__main__": 2236 if __name__ == "__main__":
2237 test_main() 2237 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_optparse.py ('k') | Lib/test/test_ossaudiodev.py » ('j') | no next file with comments »

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