summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2010-08-14 18:24:40 (GMT)
committerFlorent Xicluna <florent.xicluna@gmail.com>2010-08-14 18:24:40 (GMT)
commitb4efb3d81e8a22f553d92cfb924258f9c3bca415 (patch)
treec6dfcbdd2d22ac9e31bb9f0326240e1a5bbe1e55 /Lib
parent355447330926fc8e7c8d0163a0739a149d6844a2 (diff)
downloadcpython-b4efb3d81e8a22f553d92cfb924258f9c3bca415.zip
cpython-b4efb3d81e8a22f553d92cfb924258f9c3bca415.tar.gz
cpython-b4efb3d81e8a22f553d92cfb924258f9c3bca415.tar.bz2
Merged revisions 83212,83829,83833,83838-83839,83878,84019,84025,84028,84032,84036 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r83212 | florent.xicluna | 2010-07-28 18:39:41 +0200 (mer., 28 juil. 2010) | 2 lines Syntax cleanup. ........ r83829 | florent.xicluna | 2010-08-08 18:16:07 +0200 (dim., 08 août 2010) | 2 lines Use unittest specific methods for some urllib test cases. And replace urllib2 with urllib.request in comments. ........ r83833 | florent.xicluna | 2010-08-08 18:25:27 +0200 (dim., 08 août 2010) | 2 lines Add test case for the HTTPResponse being an iterable. Follow-up of issue #4608. ........ r83838 | florent.xicluna | 2010-08-08 20:03:44 +0200 (dim., 08 août 2010) | 2 lines Typo. ........ r83839 | florent.xicluna | 2010-08-08 20:06:13 +0200 (dim., 08 août 2010) | 2 lines Issue #7564: Skip test_ioctl if another process is attached to /dev/tty. ........ r83878 | florent.xicluna | 2010-08-09 10:29:08 +0200 (lun., 09 août 2010) | 1 line Merge the 2to3 script from /sandbox/trunk/2to3/2to3, revision 72867 (latest). ........ r84019 | florent.xicluna | 2010-08-14 17:56:42 +0200 (sam., 14 août 2010) | 11 lines Merged manually from 2.7 branch to 3.x trunk. ------------------------------------------------------------------------ r79925 | nick.coghlan | 2010-04-10 16:24:36 +0200 (sam. 10 avril 2010) Try to turn some buildbots green by allowing test_multiprocessing to pass even if it hits the sys.exc_clear code in the threading module, and improve the test coverage by making the ctypes dependencies a bit more granular (two of the cited ctypes objects don't exist on my system) ------------------------------------------------------------------------ ........ r84025 | florent.xicluna | 2010-08-14 18:56:27 +0200 (sam., 14 août 2010) | 1 line List Misc/python-config.in in Misc/README. Fix few typos. ........ r84028 | florent.xicluna | 2010-08-14 19:02:49 +0200 (sam., 14 août 2010) | 1 line Fix order. ........ r84032 | florent.xicluna | 2010-08-14 19:15:31 +0200 (sam., 14 août 2010) | 1 line Convert to spaces. ........ r84036 | florent.xicluna | 2010-08-14 20:03:19 +0200 (sam., 14 août 2010) | 1 line Remove bad merge (from svnmerge r82301) ........
Diffstat (limited to 'Lib')
-rw-r--r--Lib/ctypes/test/test_callbacks.py2
-rw-r--r--Lib/json/encoder.py2
-rw-r--r--Lib/pickletools.py2
-rw-r--r--Lib/test/test_binop.py2
-rw-r--r--Lib/test/test_ioctl.py10
-rw-r--r--Lib/test/test_multiprocessing.py24
-rw-r--r--Lib/test/test_pow.py4
-rw-r--r--Lib/test/test_sys.py4
-rw-r--r--Lib/test/test_urllib.py4
-rw-r--r--Lib/test/test_urllib2.py47
-rw-r--r--Lib/test/test_urllib2_localnet.py46
11 files changed, 90 insertions, 57 deletions
diff --git a/Lib/ctypes/test/test_callbacks.py b/Lib/ctypes/test/test_callbacks.py
index 1466f26..0fa2d9d 100644
--- a/Lib/ctypes/test/test_callbacks.py
+++ b/Lib/ctypes/test/test_callbacks.py
@@ -164,7 +164,7 @@ class SampleCallbacksTestCase(unittest.TestCase):
result = integrate(0.0, 1.0, CALLBACK(func), 10)
diff = abs(result - 1./3.)
- self.assertTrue(diff < 0.01, "%s not less than 0.01" % diff)
+ self.assertLess(diff, 0.01, "%s not less than 0.01" % diff)
################################################################
diff --git a/Lib/json/encoder.py b/Lib/json/encoder.py
index 2beb10e..d068e72 100644
--- a/Lib/json/encoder.py
+++ b/Lib/json/encoder.py
@@ -397,7 +397,7 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
yield 'true'
elif o is False:
yield 'false'
- elif isinstance(o, (int, int)):
+ elif isinstance(o, int):
yield str(o)
elif isinstance(o, float):
yield _floatstr(o)
diff --git a/Lib/pickletools.py b/Lib/pickletools.py
index 4f1c24f..dc40810 100644
--- a/Lib/pickletools.py
+++ b/Lib/pickletools.py
@@ -733,7 +733,7 @@ pylong = StackObject(
pyinteger_or_bool = StackObject(
name='int_or_bool',
- obtype=(int, int, bool),
+ obtype=(int, bool),
doc="A Python integer object (short or long), or "
"a Python bool.")
diff --git a/Lib/test/test_binop.py b/Lib/test/test_binop.py
index 5d77f23..523ecbe 100644
--- a/Lib/test/test_binop.py
+++ b/Lib/test/test_binop.py
@@ -15,7 +15,7 @@ def isint(x):
def isnum(x):
"""Test whether an object is an instance of a built-in numeric type."""
- for T in int, int, float, complex:
+ for T in int, float, complex:
if isinstance(x, T):
return 1
return 0
diff --git a/Lib/test/test_ioctl.py b/Lib/test/test_ioctl.py
index 50597ca..d63fdeb 100644
--- a/Lib/test/test_ioctl.py
+++ b/Lib/test/test_ioctl.py
@@ -7,9 +7,17 @@ get_attribute(termios, 'TIOCGPGRP') #Can't run tests without this feature
try:
tty = open("/dev/tty", "r")
- tty.close()
except IOError:
raise unittest.SkipTest("Unable to open /dev/tty")
+else:
+ # Skip if another process is in foreground
+ r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ")
+ tty.close()
+ rpgrp = struct.unpack("i", r)[0]
+ if rpgrp not in (os.getpgrp(), os.getsid(0)):
+ raise unittest.SkipTest("Neither the process group nor the session "
+ "are attached to /dev/tty")
+ del tty, r, rpgrp
try:
import pty
diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py
index c5aeb14..3f6fc8b 100644
--- a/Lib/test/test_multiprocessing.py
+++ b/Lib/test/test_multiprocessing.py
@@ -14,7 +14,6 @@ import os
import gc
import signal
import array
-import copy
import socket
import random
import logging
@@ -68,11 +67,21 @@ WIN32 = (sys.platform == "win32")
#
try:
- from ctypes import Structure, Value, copy, c_int, c_double
+ from ctypes import Structure, c_int, c_double
except ImportError:
Structure = object
c_int = c_double = None
+try:
+ from ctypes import Value
+except ImportError:
+ Value = None
+
+try:
+ from ctypes import copy as ctypes_copy
+except ImportError:
+ ctypes_copy = None
+
#
# Creates a wrapper for a function which records the time it takes to finish
#
@@ -1103,12 +1112,10 @@ def baz():
yield i*i
class IteratorProxy(BaseProxy):
- _exposed_ = ('next', '__next__')
+ _exposed_ = ('__next__',)
def __iter__(self):
return self
def __next__(self):
- return self._callmethod('next')
- def __next__(self):
return self._callmethod('__next__')
class MyManager(BaseManager):
@@ -1565,7 +1572,7 @@ class _TestSharedCTypes(BaseTestCase):
for i in range(len(arr)):
arr[i] *= 2
- @unittest.skipIf(c_int is None, "requires _ctypes")
+ @unittest.skipIf(Value is None, "requires ctypes.Value")
def test_sharedctypes(self, lock=False):
x = Value('i', 7, lock=lock)
y = Value(ctypes.c_double, 1.0/3.0, lock=lock)
@@ -1586,13 +1593,14 @@ class _TestSharedCTypes(BaseTestCase):
self.assertAlmostEqual(arr[i], i*2)
self.assertEqual(string.value, latin('hellohello'))
+ @unittest.skipIf(Value is None, "requires ctypes.Value")
def test_synchronize(self):
self.test_sharedctypes(lock=True)
- @unittest.skipIf(c_int is None, "requires _ctypes")
+ @unittest.skipIf(ctypes_copy is None, "requires ctypes.copy")
def test_copy(self):
foo = _Foo(2, 5.0)
- bar = copy(foo)
+ bar = ctypes_copy(foo)
foo.x = 0
foo.y = 0
self.assertEqual(bar.x, 2)
diff --git a/Lib/test/test_pow.py b/Lib/test/test_pow.py
index 859c373..60bb533 100644
--- a/Lib/test/test_pow.py
+++ b/Lib/test/test_pow.py
@@ -18,14 +18,14 @@ class PowTest(unittest.TestCase):
self.assertEquals(pow(2, i), pow2)
if i != 30 : pow2 = pow2*2
- for othertype in int, int:
+ for othertype in (int,):
for i in list(range(-10, 0)) + list(range(1, 10)):
ii = type(i)
for j in range(1, 11):
jj = -othertype(j)
pow(ii, jj)
- for othertype in int, int, float:
+ for othertype in int, float:
for i in range(1, 100):
zero = type(0)
exp = -othertype(i/10.0)
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 398243a..ccad44a 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -79,7 +79,6 @@ class SysModuleTest(unittest.TestCase):
# Python/pythonrun.c::PyErr_PrintEx() is tricky.
def test_exit(self):
- import subprocess
self.assertRaises(TypeError, sys.exit, 42, 42)
@@ -458,7 +457,6 @@ class SysModuleTest(unittest.TestCase):
sys._clear_type_cache()
def test_ioencoding(self):
- import subprocess,os
env = dict(os.environ)
# Test character: cent sign, encoded as 0x4A (ASCII J) in CP424,
@@ -480,7 +478,7 @@ class SysModuleTest(unittest.TestCase):
# Issue #7774: Ensure that sys.executable is an empty string if argv[0]
# has been set to an non existent program name and Python is unable to
# retrieve the real program name
- import subprocess
+
# For a normal installation, it should work without 'cwd'
# argument. For test runs in the build directory, see #7774.
python_dir = os.path.dirname(os.path.realpath(sys.executable))
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index c573f14..80cd8ef 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -103,7 +103,7 @@ class urlopen_FileTests(unittest.TestCase):
self.assertEqual(self.returned_obj.geturl(), self.pathname)
def test_getcode(self):
- self.assertEqual(self.returned_obj.getcode(), None)
+ self.assertIsNone(self.returned_obj.getcode())
def test_iter(self):
# Test iterator
@@ -132,7 +132,7 @@ class ProxyTests(unittest.TestCase):
self.env.set('NO_PROXY', 'localhost')
proxies = urllib.request.getproxies_environment()
# getproxies_environment use lowered case truncated (no '_proxy') keys
- self.assertEquals('localhost', proxies['no'])
+ self.assertEqual('localhost', proxies['no'])
class urlopen_HttpTests(unittest.TestCase):
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index 83bd467..0f8395e 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -46,7 +46,7 @@ class TrivialTests(unittest.TestCase):
('a="b\\"c", d="e\\,f", g="h\\\\i"',
['a="b"c"', 'd="e,f"', 'g="h\\i"'])]
for string, list in tests:
- self.assertEquals(urllib.request.parse_http_list(string), list)
+ self.assertEqual(urllib.request.parse_http_list(string), list)
def test_request_headers_dict():
@@ -744,9 +744,9 @@ class HandlerTests(unittest.TestCase):
h.file_open(req)
# XXXX remove OSError when bug fixed
except (urllib.error.URLError, OSError):
- self.assertTrue(not ftp)
+ self.assertFalse(ftp)
else:
- self.assertTrue(o.req is req)
+ self.assertIs(o.req, req)
self.assertEqual(req.type, "ftp")
self.assertEqual(req.type is "ftp", ftp)
@@ -849,19 +849,19 @@ class HandlerTests(unittest.TestCase):
# all 2xx are passed through
r = MockResponse(200, "OK", {}, "", url)
newr = h.http_response(req, r)
- self.assertTrue(r is newr)
- self.assertTrue(not hasattr(o, "proto")) # o.error not called
+ self.assertIs(r, newr)
+ self.assertFalse(hasattr(o, "proto")) # o.error not called
r = MockResponse(202, "Accepted", {}, "", url)
newr = h.http_response(req, r)
- self.assertTrue(r is newr)
- self.assertTrue(not hasattr(o, "proto")) # o.error not called
+ self.assertIs(r, newr)
+ self.assertFalse(hasattr(o, "proto")) # o.error not called
r = MockResponse(206, "Partial content", {}, "", url)
newr = h.http_response(req, r)
- self.assertTrue(r is newr)
- self.assertTrue(not hasattr(o, "proto")) # o.error not called
+ self.assertIs(r, newr)
+ self.assertFalse(hasattr(o, "proto")) # o.error not called
# anything else calls o.error (and MockOpener returns None, here)
r = MockResponse(502, "Bad gateway", {}, "", url)
- self.assertTrue(h.http_response(req, r) is None)
+ self.assertIsNone(h.http_response(req, r))
self.assertEqual(o.proto, "http") # o.error called
self.assertEqual(o.args, (req, r, 502, "Bad gateway", {}))
@@ -873,12 +873,14 @@ class HandlerTests(unittest.TestCase):
req = Request("http://example.com/")
r = MockResponse(200, "OK", {}, "")
newreq = h.http_request(req)
- self.assertTrue(cj.ach_req is req is newreq)
- self.assertEquals(req.get_origin_req_host(), "example.com")
- self.assertTrue(not req.is_unverifiable())
+ self.assertIs(cj.ach_req, req)
+ self.assertIs(cj.ach_req, newreq)
+ self.assertEqual(req.get_origin_req_host(), "example.com")
+ self.assertFalse(req.is_unverifiable())
newr = h.http_response(req, r)
- self.assertTrue(cj.ec_req is req)
- self.assertTrue(cj.ec_r is r is newr)
+ self.assertIs(cj.ec_req, req)
+ self.assertIs(cj.ec_r, r)
+ self.assertIs(r, newr)
def test_redirect(self):
from_url = "http://example.com/a.html"
@@ -906,7 +908,7 @@ class HandlerTests(unittest.TestCase):
try:
self.assertEqual(o.req.get_method(), "GET")
except AttributeError:
- self.assertTrue(not o.req.has_data())
+ self.assertFalse(o.req.has_data())
# now it's a GET, there should not be headers regarding content
# (possibly dragged from before being a POST)
@@ -965,7 +967,7 @@ class HandlerTests(unittest.TestCase):
cp = urllib.request.HTTPCookieProcessor(cj)
o = build_test_opener(hh, hdeh, hrh, cp)
o.open("http://www.example.com/")
- self.assertTrue(not hh.req.has_header("Cookie"))
+ self.assertFalse(hh.req.has_header("Cookie"))
def test_proxy(self):
o = OpenerDirector()
@@ -1199,11 +1201,8 @@ class MiscTests(unittest.TestCase):
self.opener_has_handler(o, MyOtherHTTPHandler)
def opener_has_handler(self, opener, handler_class):
- for h in opener.handlers:
- if h.__class__ == handler_class:
- break
- else:
- self.assertTrue(False)
+ self.assertTrue(any(h.__class__ == handler_class
+ for h in opener.handlers))
class RequestTests(unittest.TestCase):
@@ -1218,7 +1217,7 @@ class RequestTests(unittest.TestCase):
self.assertEqual("GET", self.get.get_method())
def test_add_data(self):
- self.assertTrue(not self.get.has_data())
+ self.assertFalse(self.get.has_data())
self.assertEqual("GET", self.get.get_method())
self.get.add_data("spam")
self.assertTrue(self.get.has_data())
@@ -1244,7 +1243,7 @@ class RequestTests(unittest.TestCase):
self.assertEqual("www.python.org", req.get_host())
def test_proxy(self):
- self.assertTrue(not self.get.has_proxy())
+ self.assertFalse(self.get.has_proxy())
self.get.set_proxy("www.perl.org", "http")
self.assertTrue(self.get.has_proxy())
self.assertEqual("www.python.org", self.get.get_origin_req_host())
diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py
index 365742c..fbd21d2 100644
--- a/Lib/test/test_urllib2_localnet.py
+++ b/Lib/test/test_urllib2_localnet.py
@@ -172,7 +172,7 @@ class DigestAuthHandler:
auth_validated = False
# MSIE uses short_path in its validation, but Python's
- # urllib2 uses the full path, so we're going to see if
+ # urllib.request uses the full path, so we're going to see if
# either of them works here.
for path in [request_handler.path, request_handler.short_path]:
@@ -298,8 +298,9 @@ def GetRequestHandler(responses):
def do_GET(self):
body = self.send_head()
- if body:
- self.wfile.write(body)
+ while body:
+ done = self.wfile.write(body)
+ body = body[done:]
def do_POST(self):
content_length = self.headers["Content-Length"]
@@ -330,7 +331,7 @@ def GetRequestHandler(responses):
class TestUrlopen(unittest.TestCase):
- """Tests urllib2.urlopen using the network.
+ """Tests urllib.request.urlopen using the network.
These tests are not exhaustive. Assuming that testing using files does a
good job overall of some of the basic interface features. There are no
@@ -380,8 +381,8 @@ class TestUrlopen(unittest.TestCase):
handler = self.start_server(responses)
data = self.urlopen("http://localhost:%s/" % handler.port)
- self.assertEquals(data, expected_response)
- self.assertEquals(handler.requests, ["/", "/somewhere_else"])
+ self.assertEqual(data, expected_response)
+ self.assertEqual(handler.requests, ["/", "/somewhere_else"])
def test_chunked(self):
expected_response = b"hello world"
@@ -395,7 +396,7 @@ class TestUrlopen(unittest.TestCase):
response = [(200, [("Transfer-Encoding", "chunked")], chunked_start)]
handler = self.start_server(response)
data = self.urlopen("http://localhost:%s/" % handler.port)
- self.assertEquals(data, expected_response)
+ self.assertEqual(data, expected_response)
def test_404(self):
expected_response = b"Bad bad bad..."
@@ -409,23 +410,23 @@ class TestUrlopen(unittest.TestCase):
else:
self.fail("404 should raise URLError")
- self.assertEquals(data, expected_response)
- self.assertEquals(handler.requests, ["/weeble"])
+ self.assertEqual(data, expected_response)
+ self.assertEqual(handler.requests, ["/weeble"])
def test_200(self):
expected_response = b"pycon 2008..."
handler = self.start_server([(200, [], expected_response)])
data = self.urlopen("http://localhost:%s/bizarre" % handler.port)
- self.assertEquals(data, expected_response)
- self.assertEquals(handler.requests, ["/bizarre"])
+ self.assertEqual(data, expected_response)
+ self.assertEqual(handler.requests, ["/bizarre"])
def test_200_with_parameters(self):
expected_response = b"pycon 2008..."
handler = self.start_server([(200, [], expected_response)])
data = self.urlopen("http://localhost:%s/bizarre" % handler.port,
b"get=with_feeling")
- self.assertEquals(data, expected_response)
- self.assertEquals(handler.requests, ["/bizarre", b"get=with_feeling"])
+ self.assertEqual(data, expected_response)
+ self.assertEqual(handler.requests, ["/bizarre", b"get=with_feeling"])
def test_sending_headers(self):
handler = self.start_server()
@@ -489,6 +490,25 @@ class TestUrlopen(unittest.TestCase):
urllib.request.urlopen,
"http://sadflkjsasf.i.nvali.d./")
+ def test_iteration(self):
+ expected_response = b"pycon 2008..."
+ handler = self.start_server([(200, [], expected_response)])
+ data = urllib.request.urlopen("http://localhost:%s" % handler.port)
+ for line in data:
+ self.assertEqual(line, expected_response)
+
+ def test_line_iteration(self):
+ lines = [b"We\n", b"got\n", b"here\n", b"verylong " * 8192 + b"\n"]
+ expected_response = b"".join(lines)
+ handler = self.start_server([(200, [], expected_response)])
+ data = urllib.request.urlopen("http://localhost:%s" % handler.port)
+ for index, line in enumerate(data):
+ self.assertEqual(line, lines[index],
+ "Fetched line number %s doesn't match expected:\n"
+ " Expected length was %s, got %s" %
+ (index, len(lines[index]), len(line)))
+ self.assertEqual(index + 1, len(lines))
+
def test_main():
support.run_unittest(ProxyAuthTests, TestUrlopen)