summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_os.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-02-26 14:29:24 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-02-26 14:29:24 (GMT)
commit18dd0df5af140f2640953cd094e0453798e1fa22 (patch)
tree3e2698c87e5c7f07bf9f6168f67cf51636d80dad /Lib/test/test_os.py
parentf368895780625ea5b7aa6d4707c3a1c56480b70a (diff)
downloadcpython-18dd0df5af140f2640953cd094e0453798e1fa22.zip
cpython-18dd0df5af140f2640953cd094e0453798e1fa22.tar.gz
cpython-18dd0df5af140f2640953cd094e0453798e1fa22.tar.bz2
Issue #11323: fix sendfile tests under 64-bit Solaris.
Diffstat (limited to 'Lib/test/test_os.py')
-rw-r--r--Lib/test/test_os.py25
1 files changed, 16 insertions, 9 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 0b65bbd..a2e2ee8 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -1374,7 +1374,7 @@ class SendfileTestServer(asyncore.dispatcher, threading.Thread):
@unittest.skipUnless(hasattr(os, 'sendfile'), "test needs os.sendfile()")
class TestSendfile(unittest.TestCase):
- DATA = b"12345abcde" * 1024 * 1024 # 10 Mb
+ DATA = b"12345abcde" * 16 * 1024 # 160 KB
SUPPORT_HEADERS_TRAILERS = not sys.platform.startswith("linux") and \
not sys.platform.startswith("solaris") and \
not sys.platform.startswith("sunos")
@@ -1432,7 +1432,7 @@ class TestSendfile(unittest.TestCase):
total_sent = 0
offset = 0
nbytes = 4096
- while 1:
+ while total_sent < len(self.DATA):
sent = self.sendfile_wrapper(self.sockno, self.fileno, offset, nbytes)
if sent == 0:
break
@@ -1445,14 +1445,15 @@ class TestSendfile(unittest.TestCase):
self.client.close()
self.server.wait()
data = self.server.handler_instance.get_data()
- self.assertEqual(hash(data), hash(self.DATA))
+ self.assertEqual(data, self.DATA)
def test_send_at_certain_offset(self):
# start sending a file at a certain offset
total_sent = 0
- offset = len(self.DATA) / 2
+ offset = len(self.DATA) // 2
+ must_send = len(self.DATA) - offset
nbytes = 4096
- while 1:
+ while total_sent < must_send:
sent = self.sendfile_wrapper(self.sockno, self.fileno, offset, nbytes)
if sent == 0:
break
@@ -1463,15 +1464,21 @@ class TestSendfile(unittest.TestCase):
self.client.close()
self.server.wait()
data = self.server.handler_instance.get_data()
- expected = self.DATA[int(len(self.DATA) / 2):]
+ expected = self.DATA[len(self.DATA) // 2:]
self.assertEqual(total_sent, len(expected))
- self.assertEqual(hash(data), hash(expected))
+ self.assertEqual(data, expected)
def test_offset_overflow(self):
# specify an offset > file size
offset = len(self.DATA) + 4096
- sent = os.sendfile(self.sockno, self.fileno, offset, 4096)
- self.assertEqual(sent, 0)
+ try:
+ sent = os.sendfile(self.sockno, self.fileno, offset, 4096)
+ except OSError as e:
+ # Solaris can raise EINVAL if offset >= file length, ignore.
+ if e.errno != errno.EINVAL:
+ raise
+ else:
+ self.assertEqual(sent, 0)
self.client.close()
self.server.wait()
data = self.server.handler_instance.get_data()