Skip to content

Commit 9b0e918

Browse files
committed
Note: only the relevant parts of r79474 are merged.
Merged revisions 78793,78798-78799,78977,79095,79196,79474 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r78793 | florent.xicluna | 2010-03-08 13:25:35 +0100 (lun, 08 mar 2010) | 2 lines Fix macpath to deal with bytes ................ r78798 | florent.xicluna | 2010-03-08 14:32:17 +0100 (lun, 08 mar 2010) | 18 lines Merged revisions 78777,78787,78790 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78777 | florent.xicluna | 2010-03-08 00:49:03 +0100 (lun, 08 mar 2010) | 4 lines Backport the Popen.poll() protection from subprocess to multiprocessing. See #1731717. It should fix transient failures on test_multiprocessing. ........ r78787 | florent.xicluna | 2010-03-08 08:21:16 +0100 (lun, 08 mar 2010) | 2 lines Don't fail on a debug() statement, if the worker PID is (still) None. ........ r78790 | florent.xicluna | 2010-03-08 12:01:39 +0100 (lun, 08 mar 2010) | 2 lines On finalize, don't try to join not started process. ........ ................ r78799 | florent.xicluna | 2010-03-08 15:44:41 +0100 (lun, 08 mar 2010) | 2 lines Fix ntpath abspath to deal with bytes. ................ r78977 | florent.xicluna | 2010-03-15 14:14:39 +0100 (lun, 15 mar 2010) | 2 lines Fix \xhh specs, #1889. (an oversight of r60193, r60210). ................ r79095 | florent.xicluna | 2010-03-19 15:40:31 +0100 (ven, 19 mar 2010) | 2 lines Rename test.test_support to test.support for 3.x. ................ r79196 | florent.xicluna | 2010-03-21 13:29:50 +0100 (dim, 21 mar 2010) | 9 lines Merged revisions 79195 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r79195 | florent.xicluna | 2010-03-21 13:27:20 +0100 (dim, 21 mar 2010) | 2 lines Issue #8179: Fix macpath.realpath() on a non-existing path. ........ ................ r79474 | florent.xicluna | 2010-03-28 01:25:02 +0100 (dim, 28 mar 2010) | 33 lines Merged revisions 79297,79310,79382,79425-79427,79450 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r79297 | florent.xicluna | 2010-03-22 18:18:18 +0100 (lun, 22 mar 2010) | 2 lines #7668: Fix test_httpservers failure when sys.executable contains non-ASCII bytes. ........ r79310 | florent.xicluna | 2010-03-22 23:52:11 +0100 (lun, 22 mar 2010) | 2 lines Issue #8205: Remove the "Modules" directory from sys.path when Python is running from the build directory (POSIX only). ........ r79382 | florent.xicluna | 2010-03-24 20:33:25 +0100 (mer, 24 mar 2010) | 2 lines Skip tests which depend on multiprocessing.sharedctypes, if _ctypes is not available. ........ r79425 | florent.xicluna | 2010-03-25 21:32:07 +0100 (jeu, 25 mar 2010) | 2 lines Syntax cleanup `== None` -> `is None` ........ r79426 | florent.xicluna | 2010-03-25 21:33:49 +0100 (jeu, 25 mar 2010) | 2 lines #8207: Fix test_pep277 on OS X ........ r79427 | florent.xicluna | 2010-03-25 21:39:10 +0100 (jeu, 25 mar 2010) | 2 lines Fix test_unittest and test_warnings when running "python -Werror -m test.regrtest" ........ r79450 | florent.xicluna | 2010-03-26 20:32:44 +0100 (ven, 26 mar 2010) | 2 lines Ensure that the failed or unexpected tests are sorted before printing. ........ ................
1 parent e39b445 commit 9b0e918

File tree

13 files changed

+86
-53
lines changed

13 files changed

+86
-53
lines changed

Doc/reference/lexical_analysis.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ Notes:
503503
As in Standard C, up to three octal digits are accepted.
504504

505505
(2)
506-
Unlike in Standard C, at most two hex digits are accepted.
506+
Unlike in Standard C, exactly two hex digits are required.
507507

508508
(3)
509509
In a bytes literal, hexadecimal and octal escapes denote the byte with the

Lib/idlelib/PyShell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def __init__(self, tkconsole):
347347
rpcpid = None
348348

349349
def spawn_subprocess(self):
350-
if self.subprocess_arglist == None:
350+
if self.subprocess_arglist is None:
351351
self.subprocess_arglist = self.build_subprocess_arglist()
352352
args = self.subprocess_arglist
353353
self.rpcpid = os.spawnv(os.P_NOWAIT, sys.executable, args)

Lib/macpath.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,11 @@ def normpath(s):
172172
def abspath(path):
173173
"""Return an absolute path."""
174174
if not isabs(path):
175-
path = join(os.getcwd(), path)
175+
if isinstance(path, bytes):
176+
cwd = os.getcwdb()
177+
else:
178+
cwd = os.getcwd()
179+
path = join(cwd, path)
176180
return normpath(path)
177181

178182
# realpath is a no-op on systems without islink support
@@ -189,7 +193,10 @@ def realpath(path):
189193
path = components[0] + colon
190194
for c in components[1:]:
191195
path = join(path, c)
192-
path = Carbon.File.FSResolveAliasFile(path, 1)[0].as_pathname()
196+
try:
197+
path = Carbon.File.FSResolveAliasFile(path, 1)[0].as_pathname()
198+
except Carbon.File.Error:
199+
pass
193200
return path
194201

195202
supports_unicode_filenames = False

Lib/multiprocessing/forking.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ def __init__(self, process_obj):
104104

105105
def poll(self, flag=os.WNOHANG):
106106
if self.returncode is None:
107-
pid, sts = os.waitpid(self.pid, flag)
107+
try:
108+
pid, sts = os.waitpid(self.pid, flag)
109+
except os.error:
110+
# Child process not yet created. See #1731717
111+
# e.errno == errno.ECHILD == 10
112+
return None
108113
if pid == self.pid:
109114
if os.WIFSIGNALED(sts):
110115
self.returncode = -os.WTERMSIG(sts)

Lib/multiprocessing/pool.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,10 @@ def _terminate_pool(cls, taskqueue, inqueue, outqueue, pool,
387387
if pool and hasattr(pool[0], 'terminate'):
388388
debug('joining pool workers')
389389
for p in pool:
390-
p.join()
390+
if p.is_alive():
391+
# worker has not yet exited
392+
debug('cleaning up worker %d' % p.pid)
393+
p.join()
391394

392395
#
393396
# Class whose instances are returned by `Pool.apply_async()`

Lib/multiprocessing/process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def exitcode(self):
179179
@property
180180
def ident(self):
181181
'''
182-
Return indentifier (PID) of process or `None` if it has yet to start
182+
Return identifier (PID) of process or `None` if it has yet to start
183183
'''
184184
if self is _current_process:
185185
return os.getpid()

Lib/ntpath.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,8 @@ def abspath(path):
561561
path = _getfullpathname(path)
562562
except WindowsError:
563563
pass # Bad path - return unchanged.
564+
elif isinstance(path, bytes):
565+
path = os.getcwdb()
564566
else:
565567
path = os.getcwd()
566568
return normpath(path)

Lib/test/regrtest.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,6 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
453453
if module not in save_modules and module.startswith("test."):
454454
support.unload(module)
455455

456-
# The lists won't be sorted if running with -r
457-
good.sort()
458-
bad.sort()
459-
skipped.sort()
460-
461456
if good and not quiet:
462457
if not bad and not skipped and len(good) > 1:
463458
print("All", end=' ')
@@ -893,7 +888,8 @@ def printlist(x, width=70, indent=4):
893888

894889
from textwrap import fill
895890
blanks = ' ' * indent
896-
print(fill(' '.join(map(str, x)), width,
891+
# Print the sorted list: 'x' may be a '--random' list or a set()
892+
print(fill(' '.join(str(elt) for elt in sorted(x)), width,
897893
initial_indent=blanks, subsequent_indent=blanks))
898894

899895
# Map sys.platform to a string containing the basenames of tests

Lib/test/test_httpservers.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,22 @@ def setUp(self):
294294
self.cgi_dir = os.path.join(self.parent_dir, 'cgi-bin')
295295
os.mkdir(self.cgi_dir)
296296

297+
# The shebang line should be pure ASCII: use symlink if possible.
298+
# See issue #7668.
299+
if hasattr(os, 'symlink'):
300+
self.pythonexe = os.path.join(self.parent_dir, 'python')
301+
os.symlink(sys.executable, self.pythonexe)
302+
else:
303+
self.pythonexe = sys.executable
304+
297305
self.file1_path = os.path.join(self.cgi_dir, 'file1.py')
298306
with open(self.file1_path, 'w') as file1:
299-
file1.write(cgi_file1 % sys.executable)
307+
file1.write(cgi_file1 % self.pythonexe)
300308
os.chmod(self.file1_path, 0o777)
301309

302310
self.file2_path = os.path.join(self.cgi_dir, 'file2.py')
303311
with open(self.file2_path, 'w') as file2:
304-
file2.write(cgi_file2 % sys.executable)
312+
file2.write(cgi_file2 % self.pythonexe)
305313
os.chmod(self.file2_path, 0o777)
306314

307315
self.cwd = os.getcwd()
@@ -310,6 +318,8 @@ def setUp(self):
310318
def tearDown(self):
311319
try:
312320
os.chdir(self.cwd)
321+
if self.pythonexe != sys.executable:
322+
os.remove(self.pythonexe)
313323
os.remove(self.file1_path)
314324
os.remove(self.file2_path)
315325
os.rmdir(self.cgi_dir)

Lib/test/test_multiprocessing.py

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ def latin(s):
6363

6464
WIN32 = (sys.platform == "win32")
6565

66+
#
67+
# Some tests require ctypes
68+
#
69+
70+
try:
71+
from ctypes import Structure, Value, copy, c_int, c_double
72+
except ImportError:
73+
Structure = object
74+
c_int = c_double = None
75+
6676
#
6777
# Creates a wrapper for a function which records the time it takes to finish
6878
#
@@ -506,7 +516,7 @@ def test_task_done(self):
506516
queue = self.JoinableQueue()
507517

508518
if sys.version_info < (2, 5) and not hasattr(queue, 'task_done'):
509-
return
519+
self.skipTest("requires 'queue.task_done()' method")
510520

511521
workers = [self.Process(target=self._test_task_done, args=(queue,))
512522
for i in range(4)]
@@ -783,6 +793,8 @@ def test_event(self):
783793

784794
class _TestValue(BaseTestCase):
785795

796+
ALLOWED_TYPES = ('processes',)
797+
786798
codes_values = [
787799
('i', 4343, 24234),
788800
('d', 3.625, -4.25),
@@ -795,10 +807,8 @@ def _test(self, values):
795807
sv.value = cv[2]
796808

797809

810+
@unittest.skipIf(c_int is None, "requires _ctypes")
798811
def test_value(self, raw=False):
799-
if self.TYPE != 'processes':
800-
return
801-
802812
if raw:
803813
values = [self.RawValue(code, value)
804814
for code, value, _ in self.codes_values]
@@ -816,13 +826,12 @@ def test_value(self, raw=False):
816826
for sv, cv in zip(values, self.codes_values):
817827
self.assertEqual(sv.value, cv[2])
818828

829+
@unittest.skipIf(c_int is None, "requires _ctypes")
819830
def test_rawvalue(self):
820831
self.test_value(raw=True)
821832

833+
@unittest.skipIf(c_int is None, "requires _ctypes")
822834
def test_getobj_getlock(self):
823-
if self.TYPE != 'processes':
824-
return
825-
826835
val1 = self.Value('i', 5)
827836
lock1 = val1.get_lock()
828837
obj1 = val1.get_obj()
@@ -850,14 +859,14 @@ def test_getobj_getlock(self):
850859

851860
class _TestArray(BaseTestCase):
852861

862+
ALLOWED_TYPES = ('processes',)
863+
853864
def f(self, seq):
854865
for i in range(1, len(seq)):
855866
seq[i] += seq[i-1]
856867

868+
@unittest.skipIf(c_int is None, "requires _ctypes")
857869
def test_array(self, raw=False):
858-
if self.TYPE != 'processes':
859-
return
860-
861870
seq = [680, 626, 934, 821, 150, 233, 548, 982, 714, 831]
862871
if raw:
863872
arr = self.RawArray('i', seq)
@@ -880,13 +889,12 @@ def test_array(self, raw=False):
880889

881890
self.assertEqual(list(arr[:]), seq)
882891

892+
@unittest.skipIf(c_int is None, "requires _ctypes")
883893
def test_rawarray(self):
884894
self.test_array(raw=True)
885895

896+
@unittest.skipIf(c_int is None, "requires _ctypes")
886897
def test_getobj_getlock_obj(self):
887-
if self.TYPE != 'processes':
888-
return
889-
890898
arr1 = self.Array('i', list(range(10)))
891899
lock1 = arr1.get_lock()
892900
obj1 = arr1.get_obj()
@@ -1538,12 +1546,6 @@ def test_heap(self):
15381546
#
15391547
#
15401548

1541-
try:
1542-
from ctypes import Structure, Value, copy, c_int, c_double
1543-
except ImportError:
1544-
Structure = object
1545-
c_int = c_double = None
1546-
15471549
class _Foo(Structure):
15481550
_fields_ = [
15491551
('x', c_int),
@@ -1563,10 +1565,8 @@ def _double(self, x, y, foo, arr, string):
15631565
for i in range(len(arr)):
15641566
arr[i] *= 2
15651567

1568+
@unittest.skipIf(c_int is None, "requires _ctypes")
15661569
def test_sharedctypes(self, lock=False):
1567-
if c_int is None:
1568-
return
1569-
15701570
x = Value('i', 7, lock=lock)
15711571
y = Value(ctypes.c_double, 1.0/3.0, lock=lock)
15721572
foo = Value(_Foo, 3, 2, lock=lock)
@@ -1589,10 +1589,8 @@ def test_sharedctypes(self, lock=False):
15891589
def test_synchronize(self):
15901590
self.test_sharedctypes(lock=True)
15911591

1592+
@unittest.skipIf(c_int is None, "requires _ctypes")
15921593
def test_copy(self):
1593-
if c_int is None:
1594-
return
1595-
15961594
foo = _Foo(2, 5.0)
15971595
bar = copy(foo)
15981596
foo.x = 0
@@ -1664,13 +1662,17 @@ class _TestImportStar(BaseTestCase):
16641662
ALLOWED_TYPES = ('processes',)
16651663

16661664
def test_import(self):
1667-
modules = (
1665+
modules = [
16681666
'multiprocessing', 'multiprocessing.connection',
16691667
'multiprocessing.heap', 'multiprocessing.managers',
16701668
'multiprocessing.pool', 'multiprocessing.process',
1671-
'multiprocessing.reduction', 'multiprocessing.sharedctypes',
1669+
'multiprocessing.reduction',
16721670
'multiprocessing.synchronize', 'multiprocessing.util'
1673-
)
1671+
]
1672+
1673+
if c_int is not None:
1674+
# This module requires _ctypes
1675+
modules.append('multiprocessing.sharedctypes')
16741676

16751677
for name in modules:
16761678
__import__(name)
@@ -1730,12 +1732,12 @@ def test_level(self):
17301732

17311733
class TestInvalidHandle(unittest.TestCase):
17321734

1735+
@unittest.skipIf(WIN32, "skipped on Windows")
17331736
def test_invalid_handles(self):
1734-
if WIN32:
1735-
return
17361737
conn = _multiprocessing.Connection(44977608)
17371738
self.assertRaises(IOError, conn.poll)
17381739
self.assertRaises(IOError, _multiprocessing.Connection, -1)
1740+
17391741
#
17401742
# Functions used to create test cases from the base ones in this module
17411743
#
@@ -1752,7 +1754,7 @@ def get_attributes(Source, names):
17521754
def create_test_cases(Mixin, type):
17531755
result = {}
17541756
glob = globals()
1755-
Type = type[0].upper() + type[1:]
1757+
Type = type.capitalize()
17561758

17571759
for name in list(glob.keys()):
17581760
if name.startswith('_Test'):

Lib/test/test_warnings.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ def warnings_state(module):
2727
except NameError:
2828
pass
2929
original_warnings = warning_tests.warnings
30+
original_filters = module.filters
3031
try:
32+
module.filters = original_filters[:]
33+
module.simplefilter("once")
3134
warning_tests.warnings = module
3235
yield
3336
finally:
3437
warning_tests.warnings = original_warnings
38+
module.filters = original_filters
3539

3640

3741
class BaseTest(unittest.TestCase):
@@ -194,6 +198,7 @@ class WarnTests(unittest.TestCase):
194198
def test_message(self):
195199
with original_warnings.catch_warnings(record=True,
196200
module=self.module) as w:
201+
self.module.simplefilter("once")
197202
for i in range(4):
198203
text = 'multi %d' %i # Different text on each call.
199204
self.module.warn(text)
@@ -206,6 +211,7 @@ def test_warn_nonstandard_types(self):
206211
for ob in (Warning, None, 42):
207212
with original_warnings.catch_warnings(record=True,
208213
module=self.module) as w:
214+
self.module.simplefilter("once")
209215
self.module.warn(ob)
210216
# Don't directly compare objects since
211217
# ``Warning() != Warning()``.

0 commit comments

Comments
 (0)