summaryrefslogtreecommitdiff
path: root/test/test_keepalive.py
diff options
context:
space:
mode:
authormstenner <mstenner>2005-02-14 21:55:06 +0000
committermstenner <mstenner>2005-02-14 21:55:06 +0000
commitc3b8f50636637fb6ede6187d2428202ba123e2d4 (patch)
tree7243eef9195dd55e76e7f82f6f4b599d6457500e /test/test_keepalive.py
parent844d48d85e54ac6352f1eb17c5b523f0d0fc7187 (diff)
downloadurlgrabber-c3b8f50636637fb6ede6187d2428202ba123e2d4.tar.gz
Fixed python 2.4 bug - added .code attribute to returned file objects.
Changed keepalive.HANDLE_ERRORS behavior for the way 2.4 does things.
Diffstat (limited to 'test/test_keepalive.py')
-rw-r--r--test/test_keepalive.py32
1 files changed, 22 insertions, 10 deletions
diff --git a/test/test_keepalive.py b/test/test_keepalive.py
index 9d4cfb9..f0d18d2 100644
--- a/test/test_keepalive.py
+++ b/test/test_keepalive.py
@@ -21,7 +21,7 @@
"""keepalive.py tests"""
-# $Id: test_keepalive.py,v 1.8 2004/03/31 17:02:00 mstenner Exp $
+# $Id: test_keepalive.py,v 1.9 2005/02/14 21:55:06 mstenner Exp $
import sys
import os
@@ -30,7 +30,7 @@ import urllib2
import threading
import re
-from urllib2 import URLError
+from urllib2 import URLError, HTTPError
from base_test_code import *
@@ -92,6 +92,8 @@ class HTTPErrorTests(TestCase):
def setUp(self):
self.kh = keepalive.HTTPHandler()
self.opener = urllib2.build_opener(self.kh)
+ import sys
+ self.python_version = map(int, sys.version.split()[0].split('.'))
def tearDown(self):
self.kh.close_all()
@@ -121,10 +123,15 @@ class HTTPErrorTests(TestCase):
def test_404_handler_off(self):
"test that 404 works without fancy handler"
keepalive.HANDLE_ERRORS = 0
- fo = self.opener.open(ref_404)
- data = fo.read()
- fo.close()
- self.assertEqual((fo.status, fo.reason), (404, 'Not Found'))
+ ## see the HANDLE_ERRORS note in keepalive.py for discussion of
+ ## the changes in python 2.4
+ if self.python_version >= [2, 4]:
+ self.assertRaises(URLError, self.opener.open, ref_404)
+ else:
+ fo = self.opener.open(ref_404)
+ data = fo.read()
+ fo.close()
+ self.assertEqual((fo.status, fo.reason), (404, 'Not Found'))
def test_403_handler_on(self):
"test that 403 works with fancy handler"
@@ -134,10 +141,15 @@ class HTTPErrorTests(TestCase):
def test_403_handler_off(self):
"test that 403 works without fancy handler"
keepalive.HANDLE_ERRORS = 0
- fo = self.opener.open(ref_403)
- data = fo.read()
- fo.close()
- self.assertEqual((fo.status, fo.reason), (403, 'Forbidden'))
+ ## see the HANDLE_ERRORS note in keepalive.py for discussion of
+ ## the changes in python 2.4
+ if self.python_version >= [2, 4]:
+ self.assertRaises(URLError, self.opener.open, ref_403)
+ else:
+ fo = self.opener.open(ref_403)
+ data = fo.read()
+ fo.close()
+ self.assertEqual((fo.status, fo.reason), (403, 'Forbidden'))
class DroppedConnectionTests(TestCase):
def setUp(self):