Changeset 2458
- Timestamp:
- 06/16/09 11:02:43
- Files:
-
- branches/python3/cherrypy/test/test_static.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/python3/cherrypy/test/test_static.py
r2438 r2458 2 2 test.prefer_parent_path() 3 3 4 import http.client 4 5 from io import BytesIO 5 6 … … 30 31 31 32 def tell(self): 33 if self.f.input.closed: 34 return '' 32 35 return repr(self.f.input.tell()) 33 36 tell.exposed = True … … 225 228 self.assertEqual(response.status, 200) 226 229 227 body = ''230 body = b'' 228 231 remaining = BIGFILE_SIZE 229 # By this point, the webserver has already written one chunk to230 # the socket and queued another. So we start with i=1.231 i = 1232 232 while remaining > 0: 233 i += 1234 s, h, b = helper.webtest.openURL(235 b"/tell", headers=[], host=self.HOST, port=self.PORT)236 if remaining != 65536:237 self.assertEqual(int(b), 65536 * i)238 233 data = response.fp.read(65536) 239 234 if not data: … … 241 236 body += data 242 237 remaining -= len(data) 243 244 if body != "x" * BIGFILE_SIZE: 238 239 if self.scheme == "https": 240 newconn = http.client.HTTPSConnection 241 else: 242 newconn = http.client.HTTPConnection 243 s, h, b = helper.webtest.openURL( 244 b"/tell", headers=[], host=self.HOST, port=self.PORT, 245 http_conn=newconn) 246 if not b: 247 # The file was closed on the server. 248 tell_position = BIGFILE_SIZE 249 else: 250 tell_position = int(b) 251 252 expected = len(body) 253 if tell_position >= BIGFILE_SIZE: 254 # We can't exactly control how much content the server asks for. 255 # Fudge it by only checking the first half of the reads. 256 if expected < (BIGFILE_SIZE / 2): 257 self.fail( 258 "The file should have advanced to position %r, but has " 259 "already advanced to the end of the file. It may not be " 260 "streamed as intended, or at the wrong chunk size (64k)" % 261 expected) 262 elif tell_position < expected: 263 self.fail( 264 "The file should have advanced to position %r, but has " 265 "only advanced to position %r. It may not be streamed " 266 "as intended, or at the wrong chunk size (65536)" % 267 (expected, tell_position)) 268 269 if body != b"x" * BIGFILE_SIZE: 245 270 self.fail("Body != 'x' * %d. Got %r instead (%d bytes)." % 246 271 (BIGFILE_SIZE, body[:50], len(body))) … … 263 288 self.assertEqual(response.status, 200) 264 289 body = response.fp.read(65536) 265 if body != b"x" * 65536:290 if body != b"x" * len(body): 266 291 self.fail("Body != b'x' * %d. Got %r instead (%d bytes)." % 267 292 (65536, body[:50], len(body)))

