diff options
author | Christian Heimes <christian@cheimes.de> | 2008-01-27 15:18:18 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2008-01-27 15:18:18 (GMT) |
commit | af98da18c0af924d7b03884a14ecd8e72a4832d0 (patch) | |
tree | 22aaecf7da5a5102d9c43cae707212a5a9b7c97f /Lib/test | |
parent | 4f110d880502f87995ea7d04726deeeb0640a4db (diff) | |
download | cpython-af98da18c0af924d7b03884a14ecd8e72a4832d0.zip cpython-af98da18c0af924d7b03884a14ecd8e72a4832d0.tar.gz cpython-af98da18c0af924d7b03884a14ecd8e72a4832d0.tar.bz2 |
Merged revisions 60284-60349 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60286 | christian.heimes | 2008-01-25 15:54:23 +0100 (Fri, 25 Jan 2008) | 1 line
setup.py doesn't pick up changes to a header file
........
r60287 | christian.heimes | 2008-01-25 16:52:11 +0100 (Fri, 25 Jan 2008) | 2 lines
Added the Python core headers Include/*.h and pyconfig.h as dependencies for the extensions in Modules/
It forces a rebuild of all extensions when a header files has been modified
........
r60291 | raymond.hettinger | 2008-01-25 20:24:46 +0100 (Fri, 25 Jan 2008) | 4 lines
Changes 54857 and 54840 broke code and were reverted in Py2.5 just before
it was released, but that reversion never made it to the Py2.6 head.
........
r60296 | guido.van.rossum | 2008-01-25 20:50:26 +0100 (Fri, 25 Jan 2008) | 2 lines
Rewrite the list_inline_repeat overflow check slightly differently.
........
r60301 | thomas.wouters | 2008-01-25 22:09:34 +0100 (Fri, 25 Jan 2008) | 4 lines
Use the right (portable) definition of the max of a Py_ssize_t.
........
r60303 | thomas.wouters | 2008-01-26 02:47:05 +0100 (Sat, 26 Jan 2008) | 5 lines
Make 'testall' work again when building in a separate directory.
test_distutils still fails when doing that.
........
r60305 | neal.norwitz | 2008-01-26 06:54:48 +0100 (Sat, 26 Jan 2008) | 3 lines
Prevent this test from failing if there are transient network problems
by retrying the host for up to 3 times.
........
r60306 | neal.norwitz | 2008-01-26 08:26:12 +0100 (Sat, 26 Jan 2008) | 12 lines
Use a condition variable (threading.Event) rather than sleeps and checking a
global to determine when the server is ready to be used. This slows the test
down, but should make it correct. There was a race condition before where the
server could have assigned a port, yet it wasn't ready to serve requests. If
the client sent a request before the server was completely ready, it would get
an exception. There was machinery to try to handle this condition. All of
that should be unnecessary and removed if this change works. A NOTE was
added as a comment about what needs to be fixed.
The buildbots will tell us if there are more errors or
if this test is now stable.
........
r60307 | neal.norwitz | 2008-01-26 08:38:03 +0100 (Sat, 26 Jan 2008) | 3 lines
Fix exception in tearDown on ppc buildbot. If there's no directory,
that shouldn't cause the test to fail. Just like it setUp.
........
r60308 | raymond.hettinger | 2008-01-26 09:19:06 +0100 (Sat, 26 Jan 2008) | 3 lines
Make PySet_Add() work with frozensets. Works like PyTuple_SetItem() to build-up values in a brand new frozenset.
........
r60309 | neal.norwitz | 2008-01-26 09:26:00 +0100 (Sat, 26 Jan 2008) | 1 line
The OS X buildbot had errors with the unavailable exceptions disabled. Restore it.
........
r60310 | raymond.hettinger | 2008-01-26 09:37:28 +0100 (Sat, 26 Jan 2008) | 4 lines
Let marshal build-up sets and frozensets one element at a time.
Saves the unnecessary creation of a tuple as intermediate container.
........
r60311 | raymond.hettinger | 2008-01-26 09:41:13 +0100 (Sat, 26 Jan 2008) | 1 line
Update test code for change to PySet_Add().
........
r60312 | raymond.hettinger | 2008-01-26 10:31:11 +0100 (Sat, 26 Jan 2008) | 1 line
Revert PySet_Add() changes.
........
r60314 | georg.brandl | 2008-01-26 10:43:35 +0100 (Sat, 26 Jan 2008) | 2 lines
#1934: fix os.path.isabs docs.
........
r60316 | georg.brandl | 2008-01-26 12:00:18 +0100 (Sat, 26 Jan 2008) | 2 lines
Add missing things in re docstring.
........
r60317 | georg.brandl | 2008-01-26 12:02:22 +0100 (Sat, 26 Jan 2008) | 2 lines
Slashes allowed on Windows.
........
r60319 | georg.brandl | 2008-01-26 14:41:21 +0100 (Sat, 26 Jan 2008) | 2 lines
Fix markup again.
........
r60320 | andrew.kuchling | 2008-01-26 14:50:51 +0100 (Sat, 26 Jan 2008) | 1 line
Add some items
........
r60321 | georg.brandl | 2008-01-26 15:02:38 +0100 (Sat, 26 Jan 2008) | 2 lines
Clarify "b" mode under Unix.
........
r60322 | georg.brandl | 2008-01-26 15:03:47 +0100 (Sat, 26 Jan 2008) | 3 lines
#1940: make it possible to use curses.filter() before curses.initscr()
as the documentation says.
........
r60324 | georg.brandl | 2008-01-26 15:14:20 +0100 (Sat, 26 Jan 2008) | 3 lines
#1473257: add generator.gi_code attribute that refers to
the original code object backing the generator. Patch by Collin Winter.
........
r60325 | georg.brandl | 2008-01-26 15:19:22 +0100 (Sat, 26 Jan 2008) | 2 lines
Move C API entries to the corresponding section.
........
r60326 | christian.heimes | 2008-01-26 17:43:35 +0100 (Sat, 26 Jan 2008) | 1 line
Unit test fix from Giampaolo Rodola, #1938
........
r60327 | gregory.p.smith | 2008-01-26 19:51:05 +0100 (Sat, 26 Jan 2008) | 2 lines
Update docs for new callpack params added in r60188
........
r60329 | neal.norwitz | 2008-01-26 21:24:36 +0100 (Sat, 26 Jan 2008) | 3 lines
Cleanup the code a bit. test_rfind is failing on PPC and PPC64 buildbots,
this might fix the problem.
........
r60330 | neal.norwitz | 2008-01-26 22:02:45 +0100 (Sat, 26 Jan 2008) | 1 line
Always try to remove the test file even if close raises an exception
........
r60331 | neal.norwitz | 2008-01-26 22:21:59 +0100 (Sat, 26 Jan 2008) | 3 lines
Reduce the race condition by signalling when the server is ready
and not trying to connect before.
........
r60334 | neal.norwitz | 2008-01-27 00:13:46 +0100 (Sun, 27 Jan 2008) | 5 lines
On some systems (e.g., Ubuntu on hppa) the flush()
doesn't cause the exception, but the close() does.
Will backport.
........
r60335 | neal.norwitz | 2008-01-27 00:14:17 +0100 (Sun, 27 Jan 2008) | 2 lines
Consistently use tempfile.tempdir for the db_home directory.
........
r60338 | neal.norwitz | 2008-01-27 02:44:05 +0100 (Sun, 27 Jan 2008) | 4 lines
Eliminate the sleeps that assume the server will start in .5 seconds.
This should make the test less flaky. It also speeds up the test
by about 75% on my box (20+ seconds -> ~4 seconds).
........
r60342 | neal.norwitz | 2008-01-27 06:02:34 +0100 (Sun, 27 Jan 2008) | 6 lines
Try to prevent this test from being flaky. We might need a sleep in here
which isn't as bad as it sounds. The close() *should* raise an exception,
so if it didn't we should give more time to sync and really raise it.
Will backport.
........
r60344 | jeffrey.yasskin | 2008-01-27 06:40:35 +0100 (Sun, 27 Jan 2008) | 3 lines
Make rational.gcd() public and allow Rational to take decimal strings, per
Raymond's advice.
........
r60345 | neal.norwitz | 2008-01-27 08:36:03 +0100 (Sun, 27 Jan 2008) | 3 lines
Mostly reformat. Also set an error and return NULL if neither MS_WINDOWS
nor UNIX is defined. This may have caused problems on cygwin.
........
r60346 | neal.norwitz | 2008-01-27 08:37:38 +0100 (Sun, 27 Jan 2008) | 3 lines
Use int for the sign rather than a char. char can be signed or unsigned.
It's system dependent. This might fix the problem with test_rfind failing.
........
r60347 | neal.norwitz | 2008-01-27 08:41:33 +0100 (Sun, 27 Jan 2008) | 1 line
Add stdarg include for va_list to get this to compile on cygwin
........
r60348 | raymond.hettinger | 2008-01-27 11:13:57 +0100 (Sun, 27 Jan 2008) | 1 line
Docstring nit
........
r60349 | raymond.hettinger | 2008-01-27 11:47:55 +0100 (Sun, 27 Jan 2008) | 1 line
Removed an unnecessary and confusing paragraph from the namedtuple docs.
........
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_asynchat.py | 46 | ||||
-rw-r--r-- | Lib/test/test_dict.py | 8 | ||||
-rw-r--r-- | Lib/test/test_generators.py | 20 | ||||
-rw-r--r-- | Lib/test/test_rational.py | 40 | ||||
-rw-r--r-- | Lib/test/test_resource.py | 10 | ||||
-rw-r--r-- | Lib/test/test_telnetlib.py | 11 | ||||
-rw-r--r-- | Lib/test/test_urllibnet.py | 40 | ||||
-rw-r--r-- | Lib/test/test_xmlrpc.py | 42 | ||||
-rw-r--r-- | Lib/test/test_zipfile.py | 1 |
9 files changed, 146 insertions, 72 deletions
diff --git a/Lib/test/test_asynchat.py b/Lib/test/test_asynchat.py index 83b0972..2912057 100644 --- a/Lib/test/test_asynchat.py +++ b/Lib/test/test_asynchat.py @@ -15,12 +15,17 @@ class echo_server(threading.Thread): # client each send chunk_size = 1 + def __init__(self, event): + threading.Thread.__init__(self) + self.event = event + def run(self): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) global PORT PORT = test_support.bind_port(sock, HOST, PORT) sock.listen(1) + self.event.set() conn, client = sock.accept() self.buffer = b"" # collect data until quit message is seen @@ -74,6 +79,16 @@ class echo_client(asynchat.async_chat): self.buffer = b"" +def start_echo_server(): + event = threading.Event() + s = echo_server(event) + s.start() + event.wait() + event.clear() + time.sleep(0.01) # Give server time to start accepting. + return s, event + + class TestAsynchat(unittest.TestCase): usepoll = False @@ -84,10 +99,13 @@ class TestAsynchat(unittest.TestCase): pass def line_terminator_check(self, term, server_chunk): - s = echo_server() + event = threading.Event() + s = echo_server(event) s.chunk_size = server_chunk s.start() - time.sleep(0.5) # Give server time to initialize + event.wait() + event.clear() + time.sleep(0.01) # Give server time to start accepting. c = echo_client(term) c.push(b"hello ") c.push(bytes("world%s" % term, "ascii")) @@ -119,9 +137,7 @@ class TestAsynchat(unittest.TestCase): def numeric_terminator_check(self, termlen): # Try reading a fixed number of bytes - s = echo_server() - s.start() - time.sleep(0.5) # Give server time to initialize + s, event = start_echo_server() c = echo_client(termlen) data = b"hello world, I'm not dead yet!\n" c.push(data) @@ -141,9 +157,7 @@ class TestAsynchat(unittest.TestCase): def test_none_terminator(self): # Try reading a fixed number of bytes - s = echo_server() - s.start() - time.sleep(0.5) # Give server time to initialize + s, event = start_echo_server() c = echo_client(None) data = b"hello world, I'm not dead yet!\n" c.push(data) @@ -155,9 +169,7 @@ class TestAsynchat(unittest.TestCase): self.assertEqual(c.buffer, data) def test_simple_producer(self): - s = echo_server() - s.start() - time.sleep(0.5) # Give server time to initialize + s, event = start_echo_server() c = echo_client(b'\n') data = b"hello world\nI'm not dead yet!\n" p = asynchat.simple_producer(data+SERVER_QUIT, buffer_size=8) @@ -168,9 +180,7 @@ class TestAsynchat(unittest.TestCase): self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"]) def test_string_producer(self): - s = echo_server() - s.start() - time.sleep(0.5) # Give server time to initialize + s, event = start_echo_server() c = echo_client(b'\n') data = b"hello world\nI'm not dead yet!\n" c.push_with_producer(data+SERVER_QUIT) @@ -181,9 +191,7 @@ class TestAsynchat(unittest.TestCase): def test_empty_line(self): # checks that empty lines are handled correctly - s = echo_server() - s.start() - time.sleep(0.5) # Give server time to initialize + s, event = start_echo_server() c = echo_client(b'\n') c.push(b"hello world\n\nI'm not dead yet!\n") c.push(SERVER_QUIT) @@ -194,9 +202,7 @@ class TestAsynchat(unittest.TestCase): [b"hello world", b"", b"I'm not dead yet!"]) def test_close_when_done(self): - s = echo_server() - s.start() - time.sleep(0.5) # Give server time to initialize + s, event = start_echo_server() c = echo_client(b'\n') c.push(b"hello world\nI'm not dead yet!\n") c.push(SERVER_QUIT) diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py index 53e6446..6a0b3c1 100644 --- a/Lib/test/test_dict.py +++ b/Lib/test/test_dict.py @@ -191,14 +191,6 @@ class DictTest(unittest.TestCase): self.assertRaises(ValueError, {}.update, [(1, 2, 3)]) - # SF #1615701: make d.update(m) honor __getitem__() and keys() in dict subclasses - class KeyUpperDict(dict): - def __getitem__(self, key): - return key.upper() - d.clear() - d.update(KeyUpperDict.fromkeys('abc')) - self.assertEqual(d, {'a':'A', 'b':'B', 'c':'C'}) - def test_fromkeys(self): self.assertEqual(dict.fromkeys('abc'), {'a':None, 'b':None, 'c':None}) d = {} diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py index 892535d..04f1359 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -382,7 +382,7 @@ From the Iterators list, about the types of these things. >>> type(i) <type 'generator'> >>> [s for s in dir(i) if not s.startswith('_')] -['close', 'gi_frame', 'gi_running', 'send', 'throw'] +['close', 'gi_code', 'gi_frame', 'gi_running', 'send', 'throw'] >>> print(i.__next__.__doc__) x.__next__() <==> next(x) >>> iter(i) is i @@ -899,6 +899,24 @@ This one caused a crash (see SF bug 567538): >>> print(next(g)) Traceback (most recent call last): StopIteration + + +Test the gi_code attribute + +>>> def f(): +... yield 5 +... +>>> g = f() +>>> g.gi_code is f.__code__ +True +>>> next(g) +5 +>>> next(g) +Traceback (most recent call last): +StopIteration +>>> g.gi_code is f.__code__ +True + """ # conjoin is a simple backtracking generator, named in honor of Icon's diff --git a/Lib/test/test_rational.py b/Lib/test/test_rational.py index 729527f..284a42a 100644 --- a/Lib/test/test_rational.py +++ b/Lib/test/test_rational.py @@ -9,10 +9,28 @@ import unittest from copy import copy, deepcopy from pickle import dumps, loads R = rational.Rational +gcd = rational.gcd + + +class GcdTest(unittest.TestCase): + + def testMisc(self): + self.assertEquals(0, gcd(0, 0)) + self.assertEquals(1, gcd(1, 0)) + self.assertEquals(-1, gcd(-1, 0)) + self.assertEquals(1, gcd(0, 1)) + self.assertEquals(-1, gcd(0, -1)) + self.assertEquals(1, gcd(7, 1)) + self.assertEquals(-1, gcd(7, -1)) + self.assertEquals(1, gcd(-23, 15)) + self.assertEquals(12, gcd(120, 84)) + self.assertEquals(-12, gcd(84, -120)) + def _components(r): return (r.numerator, r.denominator) + class RationalTest(unittest.TestCase): def assertTypedEquals(self, expected, actual): @@ -57,6 +75,8 @@ class RationalTest(unittest.TestCase): self.assertEquals((-3, 2), _components(R("-3/2 "))) self.assertEquals((3, 2), _components(R(" 03/02 \n "))) self.assertEquals((3, 2), _components(R(" 03/02 \n "))) + self.assertEquals((16, 5), _components(R(" 3.2 "))) + self.assertEquals((-16, 5), _components(R(" -3.2 "))) self.assertRaisesMessage( ZeroDivisionError, "Rational(3, 0)", @@ -76,9 +96,21 @@ class RationalTest(unittest.TestCase): ValueError, "Invalid literal for Rational: + 3/2", R, "+ 3/2") self.assertRaisesMessage( - # Only parse fractions, not decimals. - ValueError, "Invalid literal for Rational: 3.2", - R, "3.2") + # Avoid treating '.' as a regex special character. + ValueError, "Invalid literal for Rational: 3a2", + R, "3a2") + self.assertRaisesMessage( + # Only parse ordinary decimals, not scientific form. + ValueError, "Invalid literal for Rational: 3.2e4", + R, "3.2e4") + self.assertRaisesMessage( + # Don't accept combinations of decimals and rationals. + ValueError, "Invalid literal for Rational: 3/7.2", + R, "3/7.2") + self.assertRaisesMessage( + # Don't accept combinations of decimals and rationals. + ValueError, "Invalid literal for Rational: 3.2/7", + R, "3.2/7") def testImmutable(self): r = R(7, 3) @@ -370,7 +402,7 @@ class RationalTest(unittest.TestCase): self.assertEqual(id(r), id(deepcopy(r))) def test_main(): - run_unittest(RationalTest) + run_unittest(RationalTest, GcdTest) if __name__ == '__main__': test_main() diff --git a/Lib/test/test_resource.py b/Lib/test/test_resource.py index 1216560..987c8d7 100644 --- a/Lib/test/test_resource.py +++ b/Lib/test/test_resource.py @@ -15,7 +15,6 @@ class ResourceTest(unittest.TestCase): self.assertRaises(TypeError, resource.setrlimit, 42, 42, 42) def test_fsize_ismax(self): - try: (cur, max) = resource.getrlimit(resource.RLIMIT_FSIZE) except AttributeError: @@ -54,6 +53,13 @@ class ResourceTest(unittest.TestCase): try: f.write(b"Y") f.flush() + # On some systems (e.g., Ubuntu on hppa) the flush() + # doesn't always cause the exception, but the close() + # does eventually. Try closing several times in + # an attempt to ensure the file is really synced and + # the exception raised. + for i in range(5): + f.close() except IOError: if not limit_set: raise @@ -63,10 +69,10 @@ class ResourceTest(unittest.TestCase): resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max)) finally: f.close() - os.unlink(test_support.TESTFN) finally: if limit_set: resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max)) + test_support.unlink(test_support.TESTFN) def test_fsize_toobig(self): # Be sure that setrlimit is checking for really large values diff --git a/Lib/test/test_telnetlib.py b/Lib/test/test_telnetlib.py index c48de04..3a53ad9 100644 --- a/Lib/test/test_telnetlib.py +++ b/Lib/test/test_telnetlib.py @@ -7,13 +7,13 @@ from unittest import TestCase from test import test_support -def server(evt, ready): +def server(evt): serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) serv.settimeout(3) serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) serv.bind(("", 9091)) serv.listen(5) - ready.set() + evt.set() try: conn, addr = serv.accept() except socket.timeout: @@ -26,9 +26,10 @@ class GeneralTests(TestCase): def setUp(self): self.evt = threading.Event() - ready = threading.Event() - threading.Thread(target=server, args=(self.evt, ready)).start() - ready.wait() + threading.Thread(target=server, args=(self.evt,)).start() + self.evt.wait() + self.evt.clear() + time.sleep(.1) def tearDown(self): self.evt.wait() diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py index a7d3805..c9a483a 100644 --- a/Lib/test/test_urllibnet.py +++ b/Lib/test/test_urllibnet.py @@ -9,6 +9,20 @@ import sys import os import mimetools + +def _open_with_retry(func, host, *args, **kwargs): + # Connecting to remote hosts is flaky. Make it more robust + # by retrying the connection several times. + for i in range(3): + try: + return func(host, *args, **kwargs) + except IOError, last_exc: + continue + except: + raise + raise last_exc + + class URLTimeoutTest(unittest.TestCase): TIMEOUT = 10.0 @@ -20,7 +34,7 @@ class URLTimeoutTest(unittest.TestCase): socket.setdefaulttimeout(None) def testURLread(self): - f = urllib.urlopen("http://www.python.org/") + f = _open_with_retry(urllib.urlopen, "http://www.python.org/") x = f.read() class urlopenNetworkTests(unittest.TestCase): @@ -38,9 +52,12 @@ class urlopenNetworkTests(unittest.TestCase): """ + def urlopen(self, *args): + return _open_with_retry(urllib.urlopen, *args) + def test_basic(self): # Simple test expected to pass. - open_url = urllib.urlopen("http://www.python.org/") + open_url = self.urlopen("http://www.python.org/") for attr in ("read", "readline", "readlines", "fileno", "close", "info", "geturl"): self.assert_(hasattr(open_url, attr), "object returned from " @@ -52,7 +69,7 @@ class urlopenNetworkTests(unittest.TestCase): def test_readlines(self): # Test both readline and readlines. - open_url = urllib.urlopen("http://www.python.org/") + open_url = self.urlopen("http://www.python.org/") try: self.assert_(isinstance(open_url.readline(), bytes), "readline did not return bytes") @@ -63,7 +80,7 @@ class urlopenNetworkTests(unittest.TestCase): def test_info(self): # Test 'info'. - open_url = urllib.urlopen("http://www.python.org/") + open_url = self.urlopen("http://www.python.org/") try: info_obj = open_url.info() finally: @@ -76,7 +93,7 @@ class urlopenNetworkTests(unittest.TestCase): def test_geturl(self): # Make sure same URL as opened is returned by geturl. URL = "http://www.python.org/" - open_url = urllib.urlopen(URL) + open_url = self.urlopen(URL) try: gotten_url = open_url.geturl() finally: @@ -100,7 +117,7 @@ class urlopenNetworkTests(unittest.TestCase): # test can't pass on Windows. return # Make sure fd returned by fileno is valid. - open_url = urllib.urlopen("http://www.python.org/") + open_url = self.urlopen("http://www.python.org/") fd = open_url.fileno() FILE = os.fdopen(fd) try: @@ -125,9 +142,12 @@ class urlopenNetworkTests(unittest.TestCase): class urlretrieveNetworkTests(unittest.TestCase): """Tests urllib.urlretrieve using the network.""" + def urlretrieve(self, *args): + return _open_with_retry(urllib.urlretrieve, *args) + def test_basic(self): # Test basic functionality. - file_location,info = urllib.urlretrieve("http://www.python.org/") + file_location,info = self.urlretrieve("http://www.python.org/") self.assert_(os.path.exists(file_location), "file location returned by" " urlretrieve is not a valid path") FILE = open(file_location) @@ -140,8 +160,8 @@ class urlretrieveNetworkTests(unittest.TestCase): def test_specified_path(self): # Make sure that specifying the location of the file to write to works. - file_location,info = urllib.urlretrieve("http://www.python.org/", - test_support.TESTFN) + file_location,info = self.urlretrieve("http://www.python.org/", + test_support.TESTFN) self.assertEqual(file_location, test_support.TESTFN) self.assert_(os.path.exists(file_location)) FILE = open(file_location) @@ -153,7 +173,7 @@ class urlretrieveNetworkTests(unittest.TestCase): def test_header(self): # Make sure header returned as 2nd value from urlretrieve is good. - file_location, header = urllib.urlretrieve("http://www.python.org/") + file_location, header = self.urlretrieve("http://www.python.org/") os.unlink(file_location) self.assert_(isinstance(header, mimetools.Message), "header is not an instance of mimetools.Message") diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py index 16ef798..7b5af9e 100644 --- a/Lib/test/test_xmlrpc.py +++ b/Lib/test/test_xmlrpc.py @@ -261,6 +261,9 @@ class BinaryTestCase(unittest.TestCase): PORT = None +# The evt is set twice. First when the server is ready to serve. +# Second when the server has been shutdown. The user must clear +# the event after it has been set the first time to catch the second set. def http_server(evt, numrequests): class TestInstanceClass: def div(self, x, y): @@ -287,6 +290,7 @@ def http_server(evt, numrequests): serv.register_function(lambda x,y: x+y, 'add') serv.register_function(my_function) serv.register_instance(TestInstanceClass()) + evt.set() # handle up to 'numrequests' requests while numrequests > 0: @@ -300,14 +304,16 @@ def http_server(evt, numrequests): PORT = None evt.set() -def stop_serving(): - global PORT - if PORT is None: - return - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - sock.connect(('localhost', int(PORT))) - sock.send(b"") - sock.close() +# This function prevents errors like: +# <ProtocolError for localhost:57527/RPC2: 500 Internal Server Error> +def is_unavailable_exception(e): + '''Returns True if the given ProtocolError is the product of a server-side + exception caused by the 'temporarily unavailable' response sometimes + given by operations on non-blocking sockets.''' + + # sometimes we get a -1 error code and/or empty headers + if e.errcode == -1 or e.headers is None: + return True class SimpleServerTestCase(unittest.TestCase): @@ -320,13 +326,9 @@ class SimpleServerTestCase(unittest.TestCase): serv_args = (self.evt, 1) threading.Thread(target=http_server, args=serv_args).start() - # wait for port to be assigned to server - n = 1000 - while n > 0 and PORT is None: - time.sleep(0.001) - n -= 1 - - time.sleep(0.5) + # wait for the server to be ready + self.evt.wait() + self.evt.clear() def tearDown(self): # wait on the server thread to terminate @@ -457,13 +459,9 @@ class FailingServerTestCase(unittest.TestCase): serv_args = (self.evt, 1) threading.Thread(target=http_server, args=serv_args).start() - # wait for port to be assigned to server - n = 1000 - while n > 0 and PORT is None: - time.sleep(0.001) - n -= 1 - - time.sleep(0.5) + # wait for the server to be ready + self.evt.wait() + self.evt.clear() def tearDown(self): # wait on the server thread to terminate diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index 1b14d2a..c4f8f79 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -309,6 +309,7 @@ class TestsWithSourceFile(unittest.TestCase): correctfile = os.path.join(os.getcwd(), fpath[1:]) else: correctfile = os.path.join(os.getcwd(), fpath) + correctfile = os.path.normpath(correctfile) self.assertEqual(writtenfile, correctfile) |