[pypy-svn] r78777 - in pypy/branch/fast-forward/lib-python/modified-2.7.0: . multiprocessing test
afa at codespeak.net
afa at codespeak.net
Fri Nov 5 23:55:25 CET 2010
Author: afa
Date: Fri Nov 5 23:55:23 2010
New Revision: 78777
Modified:
pypy/branch/fast-forward/lib-python/modified-2.7.0/multiprocessing/__init__.py
pypy/branch/fast-forward/lib-python/modified-2.7.0/sysconfig.py
pypy/branch/fast-forward/lib-python/modified-2.7.0/test/regrtest.py
pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_file2k.py
pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_fileio.py
pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_multiprocessing.py
pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_scope.py
pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_socket.py
pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_support.py
pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_threading.py
Log:
Merge the previous change into the modified version of the files
Modified: pypy/branch/fast-forward/lib-python/modified-2.7.0/multiprocessing/__init__.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/modified-2.7.0/multiprocessing/__init__.py (original)
+++ pypy/branch/fast-forward/lib-python/modified-2.7.0/multiprocessing/__init__.py Fri Nov 5 23:55:23 2010
@@ -116,7 +116,8 @@
num = 0
elif 'bsd' in sys.platform or sys.platform == 'darwin':
try:
- num = int(os.popen('sysctl -n hw.ncpu').read())
+ with os.popen('sysctl -n hw.ncpu') as p:
+ num = int(p.read())
except ValueError:
num = 0
else:
Modified: pypy/branch/fast-forward/lib-python/modified-2.7.0/sysconfig.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/modified-2.7.0/sysconfig.py (original)
+++ pypy/branch/fast-forward/lib-python/modified-2.7.0/sysconfig.py Fri Nov 5 23:55:23 2010
@@ -93,21 +93,28 @@
_EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
_CONFIG_VARS = None
_USER_BASE = None
+
+def _safe_realpath(path):
+ try:
+ return realpath(path)
+ except OSError:
+ return path
+
if sys.executable:
- _PROJECT_BASE = os.path.dirname(realpath(sys.executable))
+ _PROJECT_BASE = os.path.dirname(_safe_realpath(sys.executable))
else:
# sys.executable can be empty if argv[0] has been changed and Python is
# unable to retrieve the real program name
- _PROJECT_BASE = realpath(os.getcwd())
+ _PROJECT_BASE = _safe_realpath(os.getcwd())
if os.name == "nt" and "pcbuild" in _PROJECT_BASE[-8:].lower():
- _PROJECT_BASE = realpath(os.path.join(_PROJECT_BASE, pardir))
+ _PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir))
# PC/VS7.1
if os.name == "nt" and "\\pc\\v" in _PROJECT_BASE[-10:].lower():
- _PROJECT_BASE = realpath(os.path.join(_PROJECT_BASE, pardir, pardir))
+ _PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir, pardir))
# PC/AMD64
if os.name == "nt" and "\\pcbuild\\amd64" in _PROJECT_BASE[-14:].lower():
- _PROJECT_BASE = realpath(os.path.join(_PROJECT_BASE, pardir, pardir))
+ _PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir, pardir))
def is_python_build():
for fn in ("Setup.dist", "Setup.local"):
@@ -188,7 +195,7 @@
vars['SO'] = '.pyd'
vars['EXE'] = '.exe'
vars['VERSION'] = _PY_VERSION_SHORT_NO_DOT
- vars['BINDIR'] = os.path.dirname(realpath(sys.executable))
+ vars['BINDIR'] = os.path.dirname(_safe_realpath(sys.executable))
#
# public APIs
@@ -308,8 +315,12 @@
# from a different directory.
if _PYTHON_BUILD and os.name == "posix":
base = _PROJECT_BASE
+ try:
+ cwd = os.getcwd()
+ except OSError:
+ cwd = None
if (not os.path.isabs(_CONFIG_VARS['srcdir']) and
- base != os.getcwd()):
+ base != cwd):
# srcdir is relative and we are not in the same directory
# as the executable. Assume executable is in the build
# directory and make srcdir absolute.
Modified: pypy/branch/fast-forward/lib-python/modified-2.7.0/test/regrtest.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/modified-2.7.0/test/regrtest.py (original)
+++ pypy/branch/fast-forward/lib-python/modified-2.7.0/test/regrtest.py Fri Nov 5 23:55:23 2010
@@ -133,11 +133,7 @@
decimal - Test the decimal module against a large suite that
verifies compliance with standards.
- compiler - Test the compiler package by compiling all the source
- in the standard library and test suite. This takes
- a long time. Enabling this resource also allows
- test_tokenize to verify round-trip lexing on every
- file in the test library.
+ cpu - Used for certain CPU-heavy tests.
subprocess Run all tests for the subprocess module.
@@ -215,7 +211,7 @@
from test import test_support
RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network', 'bsddb',
- 'decimal', 'compiler', 'subprocess', 'urlfetch', 'gui',
+ 'decimal', 'cpu', 'subprocess', 'urlfetch', 'gui',
'xpickle')
TEMPDIR = os.path.abspath(tempfile.gettempdir())
@@ -365,9 +361,6 @@
usage(2, "-T and -j don't go together!")
if use_mp and findleaks:
usage(2, "-l and -j don't go together!")
- if use_mp and max(sys.flags):
- # TODO: inherit the environment and the flags
- print "Warning: flags and environment variables are ignored with -j option"
good = []
bad = []
@@ -496,6 +489,8 @@
)
yield (test, args_tuple)
pending = tests_and_args()
+ opt_args = test_support.args_from_interpreter_flags()
+ base_cmd = [sys.executable] + opt_args + ['-m', 'test.regrtest']
def work():
# A worker thread.
try:
@@ -506,8 +501,7 @@
output.put((None, None, None, None))
return
# -E is needed by some tests, e.g. test_import
- popen = Popen([sys.executable, '-E', '-m', 'test.regrtest',
- '--slaveargs', json.dumps(args_tuple)],
+ popen = Popen(base_cmd + ['--slaveargs', json.dumps(args_tuple)],
stdout=PIPE, stderr=PIPE,
universal_newlines=True,
close_fds=(os.name != 'nt'))
@@ -810,11 +804,12 @@
def get_asyncore_socket_map(self):
asyncore = sys.modules.get('asyncore')
- return asyncore and asyncore.socket_map or {}
+ # XXX Making a copy keeps objects alive until __exit__ gets called.
+ return asyncore and asyncore.socket_map.copy() or {}
def restore_asyncore_socket_map(self, saved_map):
asyncore = sys.modules.get('asyncore')
if asyncore is not None:
- asyncore.socket_map.clear()
+ asyncore.close_all(ignore_all=True)
asyncore.socket_map.update(saved_map)
def resource_info(self):
@@ -830,9 +825,11 @@
return self
def __exit__(self, exc_type, exc_val, exc_tb):
+ saved_values = self.saved_values
+ del self.saved_values
for name, get, restore in self.resource_info():
current = get()
- original = self.saved_values[name]
+ original = saved_values.pop(name)
# Check for changes to the resource's value
if current != original:
self.changed = True
@@ -933,6 +930,10 @@
def cleanup_test_droppings(testname, verbose):
import shutil
import stat
+ import gc
+
+ # First kill any dangling references to open files etc.
+ gc.collect()
# Try to clean up junk commonly left behind. While tests shouldn't leave
# any files or directories behind, when a test fails that can be tedious
@@ -1273,6 +1274,7 @@
test_bsddb3
test_curses
test_epoll
+ test_gdb
test_gdbm
test_largefile
test_locale
Modified: pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_file2k.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_file2k.py (original)
+++ pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_file2k.py Fri Nov 5 23:55:23 2010
@@ -136,6 +136,14 @@
def testReadWhenWriting(self):
self.assertRaises(IOError, self.f.read)
+ def testNastyWritelinesGenerator(self):
+ def nasty():
+ for i in range(5):
+ if i == 3:
+ self.f.close()
+ yield str(i)
+ self.assertRaises(ValueError, self.f.writelines, nasty())
+
def testIssue5677(self):
# Remark: Do not perform more than one test per open file,
# since that does NOT catch the readline error on Windows.
@@ -173,7 +181,7 @@
class OtherFileTests(unittest.TestCase):
def testOpenDir(self):
- this_dir = os.path.dirname(__file__)
+ this_dir = os.path.dirname(__file__) or os.curdir
for mode in (None, "w"):
try:
if mode:
Modified: pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_fileio.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_fileio.py (original)
+++ pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_fileio.py Fri Nov 5 23:55:23 2010
@@ -269,7 +269,6 @@
# OS'es that don't support /dev/tty.
pass
else:
- f = _FileIO("/dev/tty", "a")
self.assertEquals(f.readable(), False)
self.assertEquals(f.writable(), True)
if sys.platform != "darwin" and \
@@ -348,6 +347,7 @@
f.truncate(15)
self.assertEqual(f.tell(), 5)
self.assertEqual(f.seek(0, os.SEEK_END), 15)
+ f.close()
def testTruncateOnWindows(self):
def bug801631():
Modified: pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_multiprocessing.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_multiprocessing.py (original)
+++ pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_multiprocessing.py Fri Nov 5 23:55:23 2010
@@ -34,6 +34,12 @@
from multiprocessing import util
+try:
+ from multiprocessing.sharedctypes import Value, copy
+ HAS_SHAREDCTYPES = True
+except ImportError:
+ HAS_SHAREDCTYPES = False
+
#
#
#
@@ -72,16 +78,6 @@
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
#
@@ -119,6 +115,13 @@
else:
return self.assertEqual(value, res)
+ # For the sanity of Windows users, rather than crashing or freezing in
+ # multiple ways.
+ def __reduce__(self, *args):
+ raise NotImplementedError("shouldn't try to pickle a test case")
+
+ __reduce_ex__ = __reduce__
+
#
# Return the value of a semaphore
#
@@ -157,12 +160,13 @@
self.assertEqual(current.ident, os.getpid())
self.assertEqual(current.exitcode, None)
- def _test(self, q, *args, **kwds):
- current = self.current_process()
+ @classmethod
+ def _test(cls, q, *args, **kwds):
+ current = cls.current_process()
q.put(args)
q.put(kwds)
q.put(current.name)
- if self.TYPE != 'threads':
+ if cls.TYPE != 'threads':
q.put(bytes(current.authkey))
q.put(current.pid)
@@ -205,7 +209,8 @@
self.assertEquals(p.is_alive(), False)
self.assertNotIn(p, self.active_children())
- def _test_terminate(self):
+ @classmethod
+ def _test_terminate(cls):
time.sleep(1000)
def test_terminate(self):
@@ -254,13 +259,14 @@
p.join()
self.assertNotIn(p, self.active_children())
- def _test_recursion(self, wconn, id):
+ @classmethod
+ def _test_recursion(cls, wconn, id):
from multiprocessing import forking
wconn.send(id)
if len(id) < 2:
for i in range(2):
- p = self.Process(
- target=self._test_recursion, args=(wconn, id+[i])
+ p = cls.Process(
+ target=cls._test_recursion, args=(wconn, id+[i])
)
p.start()
p.join()
@@ -343,7 +349,8 @@
class _TestQueue(BaseTestCase):
- def _test_put(self, queue, child_can_start, parent_can_continue):
+ @classmethod
+ def _test_put(cls, queue, child_can_start, parent_can_continue):
child_can_start.wait()
for i in range(6):
queue.get()
@@ -407,7 +414,8 @@
proc.join()
- def _test_get(self, queue, child_can_start, parent_can_continue):
+ @classmethod
+ def _test_get(cls, queue, child_can_start, parent_can_continue):
child_can_start.wait()
#queue.put(1)
queue.put(2)
@@ -468,7 +476,8 @@
proc.join()
- def _test_fork(self, queue):
+ @classmethod
+ def _test_fork(cls, queue):
for i in range(10, 20):
queue.put(i)
# note that at this point the items may only be buffered, so the
@@ -517,7 +526,8 @@
q.get()
self.assertEqual(q.qsize(), 0)
- def _test_task_done(self, q):
+ @classmethod
+ def _test_task_done(cls, q):
for obj in iter(q.get, None):
time.sleep(DELTA)
q.task_done()
@@ -630,7 +640,8 @@
class _TestCondition(BaseTestCase):
- def f(self, cond, sleeping, woken, timeout=None):
+ @classmethod
+ def f(cls, cond, sleeping, woken, timeout=None):
cond.acquire()
sleeping.release()
cond.wait(timeout)
@@ -762,7 +773,8 @@
class _TestEvent(BaseTestCase):
- def _test_event(self, event):
+ @classmethod
+ def _test_event(cls, event):
time.sleep(TIMEOUT2)
event.set()
@@ -802,6 +814,8 @@
#
#
+ at unittest.skipUnless(HAS_SHAREDCTYPES,
+ "requires multiprocessing.sharedctypes")
class _TestValue(BaseTestCase):
ALLOWED_TYPES = ('processes',)
@@ -813,12 +827,12 @@
('c', latin('x'), latin('y'))
]
- def _test(self, values):
- for sv, cv in zip(values, self.codes_values):
+ @classmethod
+ def _test(cls, values):
+ for sv, cv in zip(values, cls.codes_values):
sv.value = cv[2]
- @unittest.skipIf(c_int is None, "requires _ctypes")
def test_value(self, raw=False):
if raw:
values = [self.RawValue(code, value)
@@ -837,11 +851,9 @@
for sv, cv in zip(values, self.codes_values):
self.assertEqual(sv.value, cv[2])
- @unittest.skipIf(c_int is None, "requires _ctypes")
def test_rawvalue(self):
self.test_value(raw=True)
- @unittest.skipIf(c_int is None, "requires _ctypes")
def test_getobj_getlock(self):
val1 = self.Value('i', 5)
lock1 = val1.get_lock()
@@ -872,7 +884,8 @@
ALLOWED_TYPES = ('processes',)
- def f(self, seq):
+ @classmethod
+ def f(cls, seq):
for i in range(1, len(seq)):
seq[i] += seq[i-1]
@@ -1218,7 +1231,8 @@
ALLOWED_TYPES = ('manager',)
- def _putter(self, address, authkey):
+ @classmethod
+ def _putter(cls, address, authkey):
manager = QueueManager2(
address=address, authkey=authkey, serializer=SERIALIZER
)
@@ -1256,7 +1270,8 @@
class _TestManagerRestart(BaseTestCase):
- def _putter(self, address, authkey):
+ @classmethod
+ def _putter(cls, address, authkey):
manager = QueueManager(
address=address, authkey=authkey, serializer=SERIALIZER)
manager.connect()
@@ -1268,7 +1283,11 @@
authkey = os.urandom(32)
manager = QueueManager(
address=('localhost', 0), authkey=authkey, serializer=SERIALIZER)
- addr = manager.get_server().address
+ srvr = manager.get_server()
+ addr = srvr.address
+ # Close the connection.Listener socket which gets opened as a part
+ # of manager.get_server(). It's not needed for the test.
+ srvr.listener.close()
manager.start()
p = self.Process(target=self._putter, args=(manager.address, authkey))
@@ -1292,7 +1311,8 @@
ALLOWED_TYPES = ('processes', 'threads')
- def _echo(self, conn):
+ @classmethod
+ def _echo(cls, conn):
for msg in iter(conn.recv_bytes, SENTINEL):
conn.send_bytes(msg)
conn.close()
@@ -1441,8 +1461,9 @@
ALLOWED_TYPES = ('processes', 'threads')
- def _test(self, address):
- conn = self.connection.Client(address)
+ @classmethod
+ def _test(cls, address):
+ conn = cls.connection.Client(address)
conn.send('hello')
conn.close()
@@ -1598,11 +1619,14 @@
('y', c_double)
]
+ at unittest.skipUnless(HAS_SHAREDCTYPES,
+ "requires multiprocessing.sharedctypes")
class _TestSharedCTypes(BaseTestCase):
ALLOWED_TYPES = ('processes',)
- def _double(self, x, y, foo, arr, string):
+ @classmethod
+ def _double(cls, x, y, foo, arr, string):
x.value *= 2
y.value *= 2
foo.x *= 2
@@ -1611,14 +1635,13 @@
for i in range(len(arr)):
arr[i] *= 2
- @unittest.skipIf(Value is None, "requires ctypes.Value")
def test_sharedctypes(self, lock=False):
x = Value('i', 7, lock=lock)
y = Value(c_double, 1.0/3.0, lock=lock)
foo = Value(_Foo, 3, 2, lock=lock)
arr = self.Array('d', range(10), lock=lock)
string = self.Array('c', 20, lock=lock)
- string.value = 'hello'
+ string.value = latin('hello')
p = self.Process(target=self._double, args=(x, y, foo, arr, string))
p.start()
@@ -1632,14 +1655,12 @@
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(ctypes_copy is None, "requires ctypes.copy")
def test_copy(self):
foo = _Foo(2, 5.0)
- bar = ctypes_copy(foo)
+ bar = copy(foo)
foo.x = 0
foo.y = 0
self.assertEqual(bar.x, 2)
@@ -1653,7 +1674,8 @@
ALLOWED_TYPES = ('processes',)
- def _test_finalize(self, conn):
+ @classmethod
+ def _test_finalize(cls, conn):
class Foo(object):
pass
@@ -1747,7 +1769,8 @@
logger.info('nor will this')
logger.setLevel(LOG_LEVEL)
- def _test_level(self, conn):
+ @classmethod
+ def _test_level(cls, conn):
logger = multiprocessing.get_logger()
conn.send(logger.getEffectiveLevel())
Modified: pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_scope.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_scope.py (original)
+++ pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_scope.py Fri Nov 5 23:55:23 2010
@@ -648,6 +648,13 @@
self.assertEqual(2, global_ns["result2"])
self.assertEqual(9, global_ns["result9"])
+ def testTopIsNotSignificant(self):
+ # See #9997.
+ def top(a):
+ pass
+ def b():
+ global a
+
def test_main():
with check_warnings(("import \* only allowed at module level",
Modified: pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_socket.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_socket.py (original)
+++ pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_socket.py Fri Nov 5 23:55:23 2010
@@ -15,6 +15,7 @@
import contextlib
from weakref import proxy
import signal
+import math
def try_address(host, port=0, family=socket.AF_INET):
"""Try to bind a socket on the given host:port and return True
@@ -185,6 +186,11 @@
def clientSetUp(self):
self.cli = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ def clientTearDown(self):
+ self.cli.close()
+ self.cli = None
+ ThreadableTest.clientTearDown(self)
+
class SocketConnectedTest(ThreadedTCPSocketTest):
def __init__(self, methodName='runTest'):
@@ -351,8 +357,10 @@
# Find one service that exists, then check all the related interfaces.
# I've ordered this by protocols that have both a tcp and udp
# protocol, at least for modern Linuxes.
- if sys.platform in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6',
- 'freebsd7', 'freebsd8', 'darwin'):
+ if (sys.platform.startswith('linux') or
+ sys.platform.startswith('freebsd') or
+ sys.platform.startswith('netbsd') or
+ sys.platform == 'darwin'):
# avoid the 'echo' service on this platform, as there is an
# assumption breaking non-standard port/protocol entry
services = ('daytime', 'qotd', 'domain')
@@ -510,6 +518,7 @@
# Testing getsockname()
port = self._get_unused_port()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ self.addCleanup(sock.close)
sock.bind(("0.0.0.0", port))
name = sock.getsockname()
# XXX(nnorwitz): http://tinyurl.com/os5jz seems to indicate
@@ -523,12 +532,14 @@
# Testing getsockopt()
# We know a socket should start without reuse==0
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ self.addCleanup(sock.close)
reuse = sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR)
self.assertFalse(reuse != 0, "initial mode is reuse")
def testSetSockOpt(self):
# Testing setsockopt()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ self.addCleanup(sock.close)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
reuse = sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR)
self.assertFalse(reuse == 0, "failed to set reuse mode")
@@ -561,15 +572,15 @@
finally:
sock.close()
+ @unittest.skipUnless(os.name == "nt", "Windows specific")
def test_sock_ioctl(self):
- if os.name != "nt":
- return
self.assertTrue(hasattr(socket.socket, 'ioctl'))
self.assertTrue(hasattr(socket, 'SIO_RCVALL'))
self.assertTrue(hasattr(socket, 'RCVALL_ON'))
self.assertTrue(hasattr(socket, 'RCVALL_OFF'))
self.assertTrue(hasattr(socket, 'SIO_KEEPALIVE_VALS'))
s = socket.socket()
+ self.addCleanup(s.close)
self.assertRaises(ValueError, s.ioctl, -1, None)
s.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 100, 100))
@@ -612,6 +623,42 @@
socket.AI_PASSIVE)
+ def check_sendall_interrupted(self, with_timeout):
+ # socketpair() is not stricly required, but it makes things easier.
+ if not hasattr(signal, 'alarm') or not hasattr(socket, 'socketpair'):
+ self.skipTest("signal.alarm and socket.socketpair required for this test")
+ # Our signal handlers clobber the C errno by calling a math function
+ # with an invalid domain value.
+ def ok_handler(*args):
+ self.assertRaises(ValueError, math.acosh, 0)
+ def raising_handler(*args):
+ self.assertRaises(ValueError, math.acosh, 0)
+ 1 // 0
+ c, s = socket.socketpair()
+ old_alarm = signal.signal(signal.SIGALRM, raising_handler)
+ try:
+ if with_timeout:
+ # Just above the one second minimum for signal.alarm
+ c.settimeout(1.5)
+ with self.assertRaises(ZeroDivisionError):
+ signal.alarm(1)
+ c.sendall(b"x" * (1024**2))
+ if with_timeout:
+ signal.signal(signal.SIGALRM, ok_handler)
+ signal.alarm(1)
+ self.assertRaises(socket.timeout, c.sendall, b"x" * (1024**2))
+ finally:
+ signal.signal(signal.SIGALRM, old_alarm)
+ c.close()
+ s.close()
+
+ def test_sendall_interrupted(self):
+ self.check_sendall_interrupted(False)
+
+ def test_sendall_interrupted_with_timeout(self):
+ self.check_sendall_interrupted(True)
+
+
@unittest.skipUnless(thread, 'Threading required for this test.')
class BasicTCPTest(SocketConnectedTest):
@@ -674,12 +721,23 @@
return # On Windows, this doesn't exist
fd = self.cli_conn.fileno()
sock = socket.fromfd(fd, socket.AF_INET, socket.SOCK_STREAM)
+ self.addCleanup(sock.close)
msg = sock.recv(1024)
self.assertEqual(msg, MSG)
def _testFromFd(self):
self.serv_conn.send(MSG)
+ def testDup(self):
+ # Testing dup()
+ sock = self.cli_conn.dup()
+ self.addCleanup(sock.close)
+ msg = sock.recv(1024)
+ self.assertEqual(msg, MSG)
+
+ def _testDup(self):
+ self.serv_conn.send(MSG)
+
def testShutdown(self):
# Testing shutdown()
msg = self.cli_conn.recv(1024)
@@ -790,6 +848,7 @@
read, write, err = select.select([self.serv], [], [])
if self.serv in read:
conn, addr = self.serv.accept()
+ conn.close()
else:
self.fail("Error trying to do accept after select.")
@@ -800,6 +859,7 @@
def testConnect(self):
# Testing non-blocking connect
conn, addr = self.serv.accept()
+ conn.close()
def _testConnect(self):
self.cli.settimeout(10)
@@ -818,6 +878,7 @@
read, write, err = select.select([conn], [], [])
if conn in read:
msg = conn.recv(len(MSG))
+ conn.close()
self.assertEqual(msg, MSG)
else:
self.fail("Error during select call to non-blocking socket.")
@@ -1067,6 +1128,7 @@
def test_connect(self):
port = test_support.find_unused_port()
cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ self.addCleanup(cli.close)
with self.assertRaises(socket.error) as cm:
cli.connect((HOST, port))
self.assertEqual(cm.exception.errno, errno.ECONNREFUSED)
@@ -1104,16 +1166,19 @@
def _justAccept(self):
conn, addr = self.serv.accept()
+ conn.close()
testFamily = _justAccept
def _testFamily(self):
self.cli = socket.create_connection((HOST, self.port), timeout=30)
+ self.addCleanup(self.cli.close)
self.assertEqual(self.cli.family, 2)
testSourceAddress = _justAccept
def _testSourceAddress(self):
self.cli = socket.create_connection((HOST, self.port), timeout=30,
source_address=('', self.source_port))
+ self.addCleanup(self.cli.close)
self.assertEqual(self.cli.getsockname()[1], self.source_port)
# The port number being used is sufficient to show that the bind()
# call happened.
@@ -1125,6 +1190,7 @@
socket.setdefaulttimeout(42)
try:
self.cli = socket.create_connection((HOST, self.port))
+ self.addCleanup(self.cli.close)
finally:
socket.setdefaulttimeout(None)
self.assertEquals(self.cli.gettimeout(), 42)
@@ -1136,6 +1202,7 @@
socket.setdefaulttimeout(30)
try:
self.cli = socket.create_connection((HOST, self.port), timeout=None)
+ self.addCleanup(self.cli.close)
finally:
socket.setdefaulttimeout(None)
self.assertEqual(self.cli.gettimeout(), None)
@@ -1148,6 +1215,7 @@
testTimeoutValueNonamed = _justAccept
def _testTimeoutValueNonamed(self):
self.cli = socket.create_connection((HOST, self.port), 30)
+ self.addCleanup(self.cli.close)
self.assertEqual(self.cli.gettimeout(), 30)
@unittest.skipUnless(thread, 'Threading required for this test.')
@@ -1167,6 +1235,7 @@
def testInsideTimeout(self):
conn, addr = self.serv.accept()
+ self.addCleanup(conn.close)
time.sleep(3)
conn.send("done!")
testOutsideTimeout = testInsideTimeout
Modified: pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_support.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_support.py (original)
+++ pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_support.py Fri Nov 5 23:55:23 2010
@@ -1008,7 +1008,7 @@
return obj
def requires_resource(resource):
- if resource_is_enabled(resource):
+ if is_resource_enabled(resource):
return _id
else:
return unittest.skip("resource {0!r} is not enabled".format(resource))
@@ -1203,3 +1203,23 @@
return b"".join(chr(x) for x in b)
except TypeError:
return bytes(b)
+
+def args_from_interpreter_flags():
+ """Return a list of command-line arguments reproducing the current
+ settings in sys.flags."""
+ flag_opt_map = {
+ 'bytes_warning': 'b',
+ 'dont_write_bytecode': 'B',
+ 'ignore_environment': 'E',
+ 'no_user_site': 's',
+ 'no_site': 'S',
+ 'optimize': 'O',
+ 'py3k_warning': '3',
+ 'verbose': 'v',
+ }
+ args = []
+ for flag, opt in flag_opt_map.items():
+ v = getattr(sys.flags, flag)
+ if v > 0:
+ args.append('-' + opt * v)
+ return args
Modified: pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_threading.py
==============================================================================
--- pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_threading.py (original)
+++ pypy/branch/fast-forward/lib-python/modified-2.7.0/test/test_threading.py Fri Nov 5 23:55:23 2010
@@ -307,7 +307,7 @@
# Issue1733757
# Avoid a deadlock when sys.settrace steps into threading._shutdown
import subprocess
- rc = subprocess.call([sys.executable, "-c", """if 1:
+ p = subprocess.Popen([sys.executable, "-c", """if 1:
import sys, threading
# A deadlock-killer, to prevent the
@@ -327,9 +327,16 @@
return func
sys.settrace(func)
- """])
+ """],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ self.addCleanup(p.stdout.close)
+ self.addCleanup(p.stderr.close)
+ stdout, stderr = p.communicate()
+ rc = p.returncode
self.assertFalse(rc == 2, "interpreted was blocked")
- self.assertTrue(rc == 0, "Unexpected error")
+ self.assertTrue(rc == 0,
+ "Unexpected error: " + repr(stderr))
def test_join_nondaemon_on_shutdown(self):
# Issue 1722344
@@ -350,6 +357,8 @@
"""],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
+ self.addCleanup(p.stdout.close)
+ self.addCleanup(p.stderr.close)
stdout, stderr = p.communicate()
self.assertEqual(stdout.strip(),
"Woke up, sleep function is: <built-in function sleep>")
@@ -423,6 +432,7 @@
p = subprocess.Popen([sys.executable, "-c", script], stdout=subprocess.PIPE)
rc = p.wait()
data = p.stdout.read().replace('\r', '')
+ p.stdout.close()
self.assertEqual(data, "end of main\nend of thread\n")
self.assertFalse(rc == 2, "interpreter was blocked")
self.assertTrue(rc == 0, "Unexpected error")
@@ -467,7 +477,8 @@
return
# Skip platforms with known problems forking from a worker thread.
# See http://bugs.python.org/issue3863.
- if sys.platform in ('freebsd4', 'freebsd5', 'freebsd6', 'os2emx'):
+ if sys.platform in ('freebsd4', 'freebsd5', 'freebsd6', 'netbsd5',
+ 'os2emx'):
print >>sys.stderr, ('Skipping test_3_join_in_forked_from_thread'
' due to known OS bugs on'), sys.platform
return
More information about the Pypy-commit
mailing list