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

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

Issue 16510: Using appropriate checks in tests
Patch Set: Created 5 years, 6 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_multiprocessing.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 1976 matching lines...) Expand 10 before | Expand all | Expand 10 after
1987 # normal send 1987 # normal send
1988 total_sent = 0 1988 total_sent = 0
1989 offset = 0 1989 offset = 0
1990 nbytes = 4096 1990 nbytes = 4096
1991 while total_sent < len(self.DATA): 1991 while total_sent < len(self.DATA):
1992 sent = self.sendfile_wrapper(self.sockno, self.fileno, offset, nbyte s) 1992 sent = self.sendfile_wrapper(self.sockno, self.fileno, offset, nbyte s)
1993 if sent == 0: 1993 if sent == 0:
1994 break 1994 break
1995 offset += sent 1995 offset += sent
1996 total_sent += sent 1996 total_sent += sent
1997 self.assertTrue(sent <= nbytes) 1997 self.assertLessEqual(sent, nbytes)
1998 self.assertEqual(offset, total_sent) 1998 self.assertEqual(offset, total_sent)
1999 1999
2000 self.assertEqual(total_sent, len(self.DATA)) 2000 self.assertEqual(total_sent, len(self.DATA))
2001 self.client.shutdown(socket.SHUT_RDWR) 2001 self.client.shutdown(socket.SHUT_RDWR)
2002 self.client.close() 2002 self.client.close()
2003 self.server.wait() 2003 self.server.wait()
2004 data = self.server.handler_instance.get_data() 2004 data = self.server.handler_instance.get_data()
2005 self.assertEqual(len(data), len(self.DATA)) 2005 self.assertEqual(len(data), len(self.DATA))
2006 self.assertEqual(data, self.DATA) 2006 self.assertEqual(data, self.DATA)
2007 2007
2008 def test_send_at_certain_offset(self): 2008 def test_send_at_certain_offset(self):
2009 # start sending a file at a certain offset 2009 # start sending a file at a certain offset
2010 total_sent = 0 2010 total_sent = 0
2011 offset = len(self.DATA) // 2 2011 offset = len(self.DATA) // 2
2012 must_send = len(self.DATA) - offset 2012 must_send = len(self.DATA) - offset
2013 nbytes = 4096 2013 nbytes = 4096
2014 while total_sent < must_send: 2014 while total_sent < must_send:
2015 sent = self.sendfile_wrapper(self.sockno, self.fileno, offset, nbyte s) 2015 sent = self.sendfile_wrapper(self.sockno, self.fileno, offset, nbyte s)
2016 if sent == 0: 2016 if sent == 0:
2017 break 2017 break
2018 offset += sent 2018 offset += sent
2019 total_sent += sent 2019 total_sent += sent
2020 self.assertTrue(sent <= nbytes) 2020 self.assertLessEqual(sent, nbytes)
2021 2021
2022 self.client.shutdown(socket.SHUT_RDWR) 2022 self.client.shutdown(socket.SHUT_RDWR)
2023 self.client.close() 2023 self.client.close()
2024 self.server.wait() 2024 self.server.wait()
2025 data = self.server.handler_instance.get_data() 2025 data = self.server.handler_instance.get_data()
2026 expected = self.DATA[len(self.DATA) // 2:] 2026 expected = self.DATA[len(self.DATA) // 2:]
2027 self.assertEqual(total_sent, len(expected)) 2027 self.assertEqual(total_sent, len(expected))
2028 self.assertEqual(len(data), len(expected)) 2028 self.assertEqual(len(data), len(expected))
2029 self.assertEqual(data, expected) 2029 self.assertEqual(data, expected)
2030 2030
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
2499 Win32DeprecatedBytesAPI, 2499 Win32DeprecatedBytesAPI,
2500 TermsizeTests, 2500 TermsizeTests,
2501 OSErrorTests, 2501 OSErrorTests,
2502 RemoveDirsTests, 2502 RemoveDirsTests,
2503 CPUCountTests, 2503 CPUCountTests,
2504 FDInheritanceTests, 2504 FDInheritanceTests,
2505 ) 2505 )
2506 2506
2507 if __name__ == "__main__": 2507 if __name__ == "__main__":
2508 test_main() 2508 test_main()
OLDNEW
« no previous file with comments | « Lib/test/_test_multiprocessing.py ('k') | Lib/test/test_ossaudiodev.py » ('j') | no next file with comments »

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