summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/_pyio.py2
-rw-r--r--Lib/dbm/dumb.py7
-rw-r--r--Lib/distutils/command/wininst-14.0-amd64.exebin589824 -> 587776 bytes
-rw-r--r--Lib/distutils/command/wininst-14.0.exebin460288 -> 458240 bytes
-rw-r--r--Lib/importlib/_bootstrap_external.py2
-rw-r--r--Lib/mailbox.py21
-rw-r--r--Lib/multiprocessing/context.py2
-rw-r--r--Lib/multiprocessing/spawn.py2
-rwxr-xr-xLib/tarfile.py31
-rw-r--r--Lib/test/_test_multiprocessing.py13
-rw-r--r--Lib/test/eintrdata/eintr_tester.py2
-rw-r--r--Lib/test/mp_preload.py18
-rw-r--r--Lib/test/support/__init__.py44
-rw-r--r--Lib/test/test_asyncore.py4
-rw-r--r--Lib/test/test_cmd_line.py9
-rw-r--r--Lib/test/test_dbm_dumb.py16
-rw-r--r--Lib/test/test_descr.py90
-rw-r--r--Lib/test/test_format.py26
-rw-r--r--Lib/test/test_fstring.py20
-rw-r--r--Lib/test/test_functools.py2
-rw-r--r--Lib/test/test_future.py63
-rw-r--r--Lib/test/test_gdb.py20
-rw-r--r--Lib/test/test_genericpath.py3
-rw-r--r--Lib/test/test_global.py6
-rw-r--r--Lib/test/test_importlib/test_locks.py2
-rw-r--r--Lib/test/test_mailbox.py4
-rw-r--r--Lib/test/test_pathlib.py7
-rw-r--r--Lib/test/test_posix.py6
-rw-r--r--Lib/test/test_pwd.py26
-rw-r--r--Lib/test/test_shutil.py6
-rw-r--r--Lib/test/test_socket.py21
-rw-r--r--Lib/test/test_stat.py3
-rw-r--r--Lib/test/test_support.py2
-rw-r--r--Lib/test/test_symtable.py8
-rw-r--r--Lib/test/test_syntax.py9
-rw-r--r--Lib/test/test_sysconfig.py5
-rw-r--r--Lib/test/test_threading.py2
37 files changed, 355 insertions, 149 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index d0947f0..2ebfb05 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -277,7 +277,7 @@ class OpenWrapper:
try:
UnsupportedOperation = io.UnsupportedOperation
except AttributeError:
- class UnsupportedOperation(ValueError, OSError):
+ class UnsupportedOperation(OSError, ValueError):
pass
diff --git a/Lib/dbm/dumb.py b/Lib/dbm/dumb.py
index e7c6440..2296dbf 100644
--- a/Lib/dbm/dumb.py
+++ b/Lib/dbm/dumb.py
@@ -97,8 +97,9 @@ class _Database(collections.MutableMapping):
try:
f = _io.open(self._dirfile, 'r', encoding="Latin-1")
except OSError:
- pass
+ self._modified = not self._readonly
else:
+ self._modified = False
with f:
for line in f:
line = line.rstrip()
@@ -113,7 +114,7 @@ class _Database(collections.MutableMapping):
# CAUTION: It's vital that _commit() succeed, and _commit() can
# be called from __del__(). Therefore we must never reference a
# global in this routine.
- if self._index is None:
+ if self._index is None or not self._modified:
return # nothing to do
try:
@@ -197,6 +198,7 @@ class _Database(collections.MutableMapping):
elif not isinstance(val, (bytes, bytearray)):
raise TypeError("values must be bytes or strings")
self._verify_open()
+ self._modified = True
if key not in self._index:
self._addkey(key, self._addval(val))
else:
@@ -229,6 +231,7 @@ class _Database(collections.MutableMapping):
if isinstance(key, str):
key = key.encode('utf-8')
self._verify_open()
+ self._modified = True
# The blocks used by the associated value are lost.
del self._index[key]
# XXX It's unclear why we do a _commit() here (the code always
diff --git a/Lib/distutils/command/wininst-14.0-amd64.exe b/Lib/distutils/command/wininst-14.0-amd64.exe
index 2229954..253c2e2 100644
--- a/Lib/distutils/command/wininst-14.0-amd64.exe
+++ b/Lib/distutils/command/wininst-14.0-amd64.exe
Binary files differ
diff --git a/Lib/distutils/command/wininst-14.0.exe b/Lib/distutils/command/wininst-14.0.exe
index 0dac110..46f5f35 100644
--- a/Lib/distutils/command/wininst-14.0.exe
+++ b/Lib/distutils/command/wininst-14.0.exe
Binary files differ
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index ab43446..9feec50 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -1440,6 +1440,4 @@ def _install(_bootstrap_module):
_setup(_bootstrap_module)
supported_loaders = _get_supported_file_loaders()
sys.path_hooks.extend([FileFinder.path_hook(*supported_loaders)])
- if _os.__name__ == 'nt':
- sys.meta_path.append(WindowsRegistryFinder)
sys.meta_path.append(PathFinder)
diff --git a/Lib/mailbox.py b/Lib/mailbox.py
index 0e23987..39f24f9 100644
--- a/Lib/mailbox.py
+++ b/Lib/mailbox.py
@@ -313,11 +313,12 @@ class Maildir(Mailbox):
# final position in order to prevent race conditions with changes
# from other programs
try:
- if hasattr(os, 'link'):
+ try:
os.link(tmp_file.name, dest)
- os.remove(tmp_file.name)
- else:
+ except (AttributeError, PermissionError):
os.rename(tmp_file.name, dest)
+ else:
+ os.remove(tmp_file.name)
except OSError as e:
os.remove(tmp_file.name)
if e.errno == errno.EEXIST:
@@ -1200,13 +1201,14 @@ class MH(Mailbox):
for key in self.iterkeys():
if key - 1 != prev:
changes.append((key, prev + 1))
- if hasattr(os, 'link'):
+ try:
os.link(os.path.join(self._path, str(key)),
os.path.join(self._path, str(prev + 1)))
- os.unlink(os.path.join(self._path, str(key)))
- else:
+ except (AttributeError, PermissionError):
os.rename(os.path.join(self._path, str(key)),
os.path.join(self._path, str(prev + 1)))
+ else:
+ os.unlink(os.path.join(self._path, str(key)))
prev += 1
self._next_key = prev + 1
if len(changes) == 0:
@@ -2076,13 +2078,14 @@ def _lock_file(f, dotlock=True):
else:
raise
try:
- if hasattr(os, 'link'):
+ try:
os.link(pre_lock.name, f.name + '.lock')
dotlock_done = True
- os.unlink(pre_lock.name)
- else:
+ except (AttributeError, PermissionError):
os.rename(pre_lock.name, f.name + '.lock')
dotlock_done = True
+ else:
+ os.unlink(pre_lock.name)
except FileExistsError:
os.remove(pre_lock.name)
raise ExternalClashError('dot lock unavailable: %s' %
diff --git a/Lib/multiprocessing/context.py b/Lib/multiprocessing/context.py
index 09455e2..623f6fb 100644
--- a/Lib/multiprocessing/context.py
+++ b/Lib/multiprocessing/context.py
@@ -196,7 +196,7 @@ class BaseContext(object):
def get_start_method(self, allow_none=False):
return self._name
- def set_start_method(self, method=None):
+ def set_start_method(self, method, force=False):
raise ValueError('cannot set start method of concrete context')
@property
diff --git a/Lib/multiprocessing/spawn.py b/Lib/multiprocessing/spawn.py
index dfb9f65..4aba372 100644
--- a/Lib/multiprocessing/spawn.py
+++ b/Lib/multiprocessing/spawn.py
@@ -217,7 +217,7 @@ def prepare(data):
process.ORIGINAL_DIR = data['orig_dir']
if 'start_method' in data:
- set_start_method(data['start_method'])
+ set_start_method(data['start_method'], force=True)
if 'init_main_from_name' in data:
_fixup_main_from_name(data['init_main_from_name'])
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index b78b1b1..5d4c86c 100755
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -50,9 +50,13 @@ import copy
import re
try:
- import grp, pwd
+ import pwd
except ImportError:
- grp = pwd = None
+ pwd = None
+try:
+ import grp
+except ImportError:
+ grp = None
# os.symlink on Windows prior to 6.0 raises NotImplementedError
symlink_exception = (AttributeError, NotImplementedError)
@@ -2219,22 +2223,25 @@ class TarFile(object):
def chown(self, tarinfo, targetpath, numeric_owner):
"""Set owner of targetpath according to tarinfo. If numeric_owner
- is True, use .gid/.uid instead of .gname/.uname.
+ is True, use .gid/.uid instead of .gname/.uname. If numeric_owner
+ is False, fall back to .gid/.uid when the search based on name
+ fails.
"""
- if pwd and hasattr(os, "geteuid") and os.geteuid() == 0:
+ if hasattr(os, "geteuid") and os.geteuid() == 0:
# We have to be root to do so.
- if numeric_owner:
- g = tarinfo.gid
- u = tarinfo.uid
- else:
+ g = tarinfo.gid
+ u = tarinfo.uid
+ if not numeric_owner:
try:
- g = grp.getgrnam(tarinfo.gname)[2]
+ if grp:
+ g = grp.getgrnam(tarinfo.gname)[2]
except KeyError:
- g = tarinfo.gid
+ pass
try:
- u = pwd.getpwnam(tarinfo.uname)[2]
+ if pwd:
+ u = pwd.getpwnam(tarinfo.uname)[2]
except KeyError:
- u = tarinfo.uid
+ pass
try:
if tarinfo.issym() and hasattr(os, "lchown"):
os.lchown(targetpath, u, g)
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index c00846c..b5f4782 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -3818,6 +3818,19 @@ class TestStartMethod(unittest.TestCase):
self.assertTrue(methods == ['fork', 'spawn'] or
methods == ['fork', 'spawn', 'forkserver'])
+ def test_preload_resources(self):
+ if multiprocessing.get_start_method() != 'forkserver':
+ self.skipTest("test only relevant for 'forkserver' method")
+ name = os.path.join(os.path.dirname(__file__), 'mp_preload.py')
+ rc, out, err = test.support.script_helper.assert_python_ok(name)
+ out = out.decode()
+ err = err.decode()
+ if out.rstrip() != 'ok' or err != '':
+ print(out)
+ print(err)
+ self.fail("failed spawning forkserver or grandchild")
+
+
#
# Check that killing process does not leak named semaphores
#
diff --git a/Lib/test/eintrdata/eintr_tester.py b/Lib/test/eintrdata/eintr_tester.py
index 9fbe04d..d194e77 100644
--- a/Lib/test/eintrdata/eintr_tester.py
+++ b/Lib/test/eintrdata/eintr_tester.py
@@ -20,6 +20,7 @@ import time
import unittest
from test import support
+android_not_root = support.android_not_root
@contextlib.contextmanager
def kill_on_error(proc):
@@ -311,6 +312,7 @@ class SocketEINTRTest(EINTRBaseTest):
# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=203162
@support.requires_freebsd_version(10, 3)
@unittest.skipUnless(hasattr(os, 'mkfifo'), 'needs mkfifo()')
+ @unittest.skipIf(android_not_root, "mkfifo not allowed, non root user")
def _test_open(self, do_open_close_reader, do_open_close_writer):
filename = support.TESTFN
diff --git a/Lib/test/mp_preload.py b/Lib/test/mp_preload.py
new file mode 100644
index 0000000..5314e8f
--- /dev/null
+++ b/Lib/test/mp_preload.py
@@ -0,0 +1,18 @@
+import multiprocessing
+
+multiprocessing.Lock()
+
+
+def f():
+ print("ok")
+
+
+if __name__ == "__main__":
+ ctx = multiprocessing.get_context("forkserver")
+ modname = "test.mp_preload"
+ # Make sure it's importable
+ __import__(modname)
+ ctx.set_forkserver_preload([modname])
+ proc = ctx.Process(target=f)
+ proc.start()
+ proc.join()
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 52c908e..15d8fc8 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -93,8 +93,10 @@ __all__ = [
"check__all__", "requires_android_level", "requires_multiprocessing_queue",
# sys
"is_jython", "is_android", "check_impl_detail", "unix_shell",
+ "setswitchinterval", "android_not_root",
# network
"HOST", "IPV6_ENABLED", "find_unused_port", "bind_port", "open_urlresource",
+ "bind_unix_socket",
# processes
'temp_umask', "reap_children",
# logging
@@ -360,9 +362,9 @@ if sys.platform.startswith("win"):
mode = 0
if stat.S_ISDIR(mode):
_waitfor(_rmtree_inner, fullname, waitall=True)
- _force_run(path, os.rmdir, fullname)
+ _force_run(fullname, os.rmdir, fullname)
else:
- _force_run(path, os.unlink, fullname)
+ _force_run(fullname, os.unlink, fullname)
_waitfor(_rmtree_inner, path, waitall=True)
_waitfor(lambda p: _force_run(p, os.rmdir, p), path)
else:
@@ -707,6 +709,15 @@ def bind_port(sock, host=HOST):
port = sock.getsockname()[1]
return port
+def bind_unix_socket(sock, addr):
+ """Bind a unix socket, raising SkipTest if PermissionError is raised."""
+ assert sock.family == socket.AF_UNIX
+ try:
+ sock.bind(addr)
+ except PermissionError:
+ sock.close()
+ raise unittest.SkipTest('cannot bind AF_UNIX sockets')
+
def _is_ipv6_enabled():
"""Check whether IPv6 is enabled on this host."""
if socket.has_ipv6:
@@ -768,6 +779,7 @@ is_jython = sys.platform.startswith('java')
_ANDROID_API_LEVEL = sysconfig.get_config_var('ANDROID_API_LEVEL')
is_android = (_ANDROID_API_LEVEL is not None and _ANDROID_API_LEVEL > 0)
+android_not_root = (is_android and os.geteuid() != 0)
if sys.platform != 'win32':
unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
@@ -1054,9 +1066,16 @@ def make_bad_fd():
file.close()
unlink(TESTFN)
-def check_syntax_error(testcase, statement):
- testcase.assertRaises(SyntaxError, compile, statement,
- '<test string>', 'exec')
+def check_syntax_error(testcase, statement, *, lineno=None, offset=None):
+ with testcase.assertRaises(SyntaxError) as cm:
+ compile(statement, '<test string>', 'exec')
+ err = cm.exception
+ testcase.assertIsNotNone(err.lineno)
+ if lineno is not None:
+ testcase.assertEqual(err.lineno, lineno)
+ testcase.assertIsNotNone(err.offset)
+ if offset is not None:
+ testcase.assertEqual(err.offset, offset)
def open_urlresource(url, *args, **kw):
import urllib.request, urllib.parse
@@ -2547,3 +2566,18 @@ def missing_compiler_executable(cmd_names=[]):
continue
if spawn.find_executable(cmd[0]) is None:
return cmd[0]
+
+
+_is_android_emulator = None
+def setswitchinterval(interval):
+ # Setting a very low gil interval on the Android emulator causes python
+ # to hang (issue #26939).
+ minimum_interval = 1e-5
+ if is_android and interval < minimum_interval:
+ global _is_android_emulator
+ if _is_android_emulator is None:
+ _is_android_emulator = (subprocess.check_output(
+ ['getprop', 'ro.kernel.qemu']).strip() == b'1')
+ if _is_android_emulator:
+ interval = minimum_interval
+ return sys.setswitchinterval(interval)
diff --git a/Lib/test/test_asyncore.py b/Lib/test/test_asyncore.py
index dbee593..51c6573 100644
--- a/Lib/test/test_asyncore.py
+++ b/Lib/test/test_asyncore.py
@@ -95,7 +95,9 @@ def bind_af_aware(sock, addr):
if HAS_UNIX_SOCKETS and sock.family == socket.AF_UNIX:
# Make sure the path doesn't exist.
support.unlink(addr)
- sock.bind(addr)
+ support.bind_unix_socket(sock, addr)
+ else:
+ sock.bind(addr)
class HelperFunctionTests(unittest.TestCase):
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index b71bb9f..ae2bcd4 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -8,7 +8,7 @@ import shutil
import sys
import subprocess
import tempfile
-from test.support import script_helper
+from test.support import script_helper, is_android
from test.support.script_helper import (spawn_python, kill_python, assert_python_ok,
assert_python_failure)
@@ -178,15 +178,16 @@ class CmdLineTest(unittest.TestCase):
if not stdout.startswith(pattern):
raise AssertionError("%a doesn't start with %a" % (stdout, pattern))
- @unittest.skipUnless(sys.platform == 'darwin', 'test specific to Mac OS X')
- def test_osx_utf8(self):
+ @unittest.skipUnless((sys.platform == 'darwin' or
+ is_android), 'test specific to Mac OS X and Android')
+ def test_osx_android_utf8(self):
def check_output(text):
decoded = text.decode('utf-8', 'surrogateescape')
expected = ascii(decoded).encode('ascii') + b'\n'
env = os.environ.copy()
# C locale gives ASCII locale encoding, but Python uses UTF-8
- # to parse the command line arguments on Mac OS X
+ # to parse the command line arguments on Mac OS X and Android.
env['LC_ALL'] = 'C'
p = subprocess.Popen(
diff --git a/Lib/test/test_dbm_dumb.py b/Lib/test/test_dbm_dumb.py
index 2d77f07..df531d6 100644
--- a/Lib/test/test_dbm_dumb.py
+++ b/Lib/test/test_dbm_dumb.py
@@ -5,6 +5,7 @@
import io
import operator
import os
+import stat
import unittest
import warnings
import dbm.dumb as dumbdbm
@@ -259,6 +260,21 @@ class DumbDBMTestCase(unittest.TestCase):
f = dumbdbm.open(_fname, flag)
f.close()
+ @unittest.skipUnless(hasattr(os, 'chmod'), 'test needs os.chmod()')
+ def test_readonly_files(self):
+ with support.temp_dir() as dir:
+ fname = os.path.join(dir, 'db')
+ with dumbdbm.open(fname, 'n') as f:
+ self.assertEqual(list(f.keys()), [])
+ for key in self._dict:
+ f[key] = self._dict[key]
+ os.chmod(fname + ".dir", stat.S_IRUSR)
+ os.chmod(fname + ".dat", stat.S_IRUSR)
+ os.chmod(dir, stat.S_IRUSR|stat.S_IXUSR)
+ with dumbdbm.open(fname, 'r') as f:
+ self.assertEqual(sorted(f.keys()), sorted(self._dict))
+ f.close() # don't write
+
def tearDown(self):
_delete_files()
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 1e08ed9..c5bff77 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -7,6 +7,7 @@ import pickle
import sys
import types
import unittest
+import warnings
import weakref
from copy import deepcopy
@@ -1661,6 +1662,77 @@ order (MRO) for bases """
self.assertEqual(b.foo, 3)
self.assertEqual(b.__class__, D)
+ @unittest.expectedFailure
+ def test_bad_new(self):
+ self.assertRaises(TypeError, object.__new__)
+ self.assertRaises(TypeError, object.__new__, '')
+ self.assertRaises(TypeError, list.__new__, object)
+ self.assertRaises(TypeError, object.__new__, list)
+ class C(object):
+ __new__ = list.__new__
+ self.assertRaises(TypeError, C)
+ class C(list):
+ __new__ = object.__new__
+ self.assertRaises(TypeError, C)
+
+ def test_object_new(self):
+ class A(object):
+ pass
+ object.__new__(A)
+ self.assertRaises(TypeError, object.__new__, A, 5)
+ object.__init__(A())
+ self.assertRaises(TypeError, object.__init__, A(), 5)
+
+ class A(object):
+ def __init__(self, foo):
+ self.foo = foo
+ object.__new__(A)
+ object.__new__(A, 5)
+ object.__init__(A(3))
+ self.assertRaises(TypeError, object.__init__, A(3), 5)
+
+ class A(object):
+ def __new__(cls, foo):
+ return object.__new__(cls)
+ object.__new__(A)
+ self.assertRaises(TypeError, object.__new__, A, 5)
+ object.__init__(A(3))
+ object.__init__(A(3), 5)
+
+ class A(object):
+ def __new__(cls, foo):
+ return object.__new__(cls)
+ def __init__(self, foo):
+ self.foo = foo
+ object.__new__(A)
+ self.assertRaises(TypeError, object.__new__, A, 5)
+ object.__init__(A(3))
+ self.assertRaises(TypeError, object.__init__, A(3), 5)
+
+ @unittest.expectedFailure
+ def test_restored_object_new(self):
+ class A(object):
+ def __new__(cls, *args, **kwargs):
+ raise AssertionError
+ self.assertRaises(AssertionError, A)
+ class B(A):
+ __new__ = object.__new__
+ def __init__(self, foo):
+ self.foo = foo
+ with warnings.catch_warnings():
+ warnings.simplefilter('error', DeprecationWarning)
+ b = B(3)
+ self.assertEqual(b.foo, 3)
+ self.assertEqual(b.__class__, B)
+ del B.__new__
+ self.assertRaises(AssertionError, B)
+ del A.__new__
+ with warnings.catch_warnings():
+ warnings.simplefilter('error', DeprecationWarning)
+ b = B(3)
+ self.assertEqual(b.foo, 3)
+ self.assertEqual(b.__class__, B)
+
def test_altmro(self):
# Testing mro() and overriding it...
class A(object):
@@ -3522,6 +3594,24 @@ order (MRO) for bases """
self.assertIsInstance(d, D)
self.assertEqual(d.foo, 1)
+ class C(object):
+ @staticmethod
+ def __new__(*args):
+ return args
+ self.assertEqual(C(1, 2), (C, 1, 2))
+ class D(C):
+ pass
+ self.assertEqual(D(1, 2), (D, 1, 2))
+
+ class C(object):
+ @classmethod
+ def __new__(*args):
+ return args
+ self.assertEqual(C(1, 2), (C, C, 1, 2))
+ class D(C):
+ pass
+ self.assertEqual(D(1, 2), (D, D, 1, 2))
+
def test_imul_bug(self):
# Testing for __imul__ problems...
# SF bug 544647
diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py
index 8afd5b8..5471be2 100644
--- a/Lib/test/test_format.py
+++ b/Lib/test/test_format.py
@@ -200,42 +200,28 @@ class FormatTest(unittest.TestCase):
testcommon("%#+37.34o", big, "+0o0012345670123456701234567012345670")
# next one gets one leading zero from precision
testcommon("%.33o", big, "012345670123456701234567012345670")
- # base marker shouldn't change that, since "0" is redundant
+ # base marker added in spite of leading zero (different to Python 2)
testcommon("%#.33o", big, "0o012345670123456701234567012345670")
- # but reduce precision, and base marker should add a zero
+ # reduce precision, and base marker is always added
testcommon("%#.32o", big, "0o12345670123456701234567012345670")
- # one leading zero from precision, and another from "0" flag & width
- testcommon("%034.33o", big, "0012345670123456701234567012345670")
- # base marker shouldn't change that
- testcommon("%0#34.33o", big, "0o012345670123456701234567012345670")
+ # one leading zero from precision, plus two from "0" flag & width
+ testcommon("%035.33o", big, "00012345670123456701234567012345670")
+ # base marker shouldn't change the size
+ testcommon("%0#35.33o", big, "0o012345670123456701234567012345670")
# Some small ints, in both Python int and flavors).
testcommon("%d", 42, "42")
testcommon("%d", -42, "-42")
- testcommon("%d", 42, "42")
- testcommon("%d", -42, "-42")
testcommon("%d", 42.0, "42")
testcommon("%#x", 1, "0x1")
- testcommon("%#x", 1, "0x1")
- testcommon("%#X", 1, "0X1")
testcommon("%#X", 1, "0X1")
testcommon("%#o", 1, "0o1")
- testcommon("%#o", 1, "0o1")
- testcommon("%#o", 0, "0o0")
testcommon("%#o", 0, "0o0")
testcommon("%o", 0, "0")
- testcommon("%o", 0, "0")
testcommon("%d", 0, "0")
- testcommon("%d", 0, "0")
- testcommon("%#x", 0, "0x0")
testcommon("%#x", 0, "0x0")
testcommon("%#X", 0, "0X0")
- testcommon("%#X", 0, "0X0")
testcommon("%x", 0x42, "42")
testcommon("%x", -0x42, "-42")
- testcommon("%x", 0x42, "42")
- testcommon("%x", -0x42, "-42")
- testcommon("%o", 0o42, "42")
- testcommon("%o", -0o42, "-42")
testcommon("%o", 0o42, "42")
testcommon("%o", -0o42, "-42")
# alternate float formatting
diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py
index 8205083..708ed25 100644
--- a/Lib/test/test_fstring.py
+++ b/Lib/test/test_fstring.py
@@ -70,18 +70,18 @@ f'{a * x()}'"""
# Make sure x was called.
self.assertTrue(x.called)
- def test_literal_eval(self):
- # With no expressions, an f-string is okay.
- self.assertEqual(ast.literal_eval("f'x'"), 'x')
- self.assertEqual(ast.literal_eval("f'x' 'y'"), 'xy')
-
- # But this should raise an error.
- with self.assertRaisesRegex(ValueError, 'malformed node or string'):
- ast.literal_eval("f'x{3}'")
+ def test_docstring(self):
+ def f():
+ f'''Not a docstring'''
+ self.assertIsNone(f.__doc__)
+ def g():
+ '''Not a docstring''' \
+ f''
+ self.assertIsNone(g.__doc__)
- # As should this, which uses a different ast node
+ def test_literal_eval(self):
with self.assertRaisesRegex(ValueError, 'malformed node or string'):
- ast.literal_eval("f'{3}'")
+ ast.literal_eval("f'x'")
def test_ast_compile_time_concat(self):
x = ['']
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index 75427df..ba2a52f 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -1322,7 +1322,7 @@ class TestLRU:
f.cache_clear()
orig_si = sys.getswitchinterval()
- sys.setswitchinterval(1e-6)
+ support.setswitchinterval(1e-6)
try:
# create n threads in order to fill cache
threads = [threading.Thread(target=full, args=[k])
diff --git a/Lib/test/test_future.py b/Lib/test/test_future.py
index 213b2ba..2f1c410 100644
--- a/Lib/test/test_future.py
+++ b/Lib/test/test_future.py
@@ -2,6 +2,7 @@
import unittest
from test import support
+import os
import re
rx = re.compile(r'\((\S+).py, line (\d+)')
@@ -12,6 +13,12 @@ def get_error_location(msg):
class FutureTest(unittest.TestCase):
+ def check_syntax_error(self, err, basename, lineno, offset=0):
+ self.assertIn('%s.py, line %d' % (basename, lineno), str(err))
+ self.assertEqual(os.path.basename(err.filename), basename + '.py')
+ self.assertEqual(err.lineno, lineno)
+ self.assertEqual(err.offset, offset)
+
def test_future1(self):
with support.CleanImport('future_test1'):
from test import future_test1
@@ -27,68 +34,44 @@ class FutureTest(unittest.TestCase):
from test import test_future3
def test_badfuture3(self):
- try:
+ with self.assertRaises(SyntaxError) as cm:
from test import badsyntax_future3
- except SyntaxError as msg:
- self.assertEqual(get_error_location(msg), ("badsyntax_future3", '3'))
- else:
- self.fail("expected exception didn't occur")
+ self.check_syntax_error(cm.exception, "badsyntax_future3", 3)
def test_badfuture4(self):
- try:
+ with self.assertRaises(SyntaxError) as cm:
from test import badsyntax_future4
- except SyntaxError as msg:
- self.assertEqual(get_error_location(msg), ("badsyntax_future4", '3'))
- else:
- self.fail("expected exception didn't occur")
+ self.check_syntax_error(cm.exception, "badsyntax_future4", 3)
def test_badfuture5(self):
- try:
+ with self.assertRaises(SyntaxError) as cm:
from test import badsyntax_future5
- except SyntaxError as msg:
- self.assertEqual(get_error_location(msg), ("badsyntax_future5", '4'))
- else:
- self.fail("expected exception didn't occur")
+ self.check_syntax_error(cm.exception, "badsyntax_future5", 4)
def test_badfuture6(self):
- try:
+ with self.assertRaises(SyntaxError) as cm:
from test import badsyntax_future6
- except SyntaxError as msg:
- self.assertEqual(get_error_location(msg), ("badsyntax_future6", '3'))
- else:
- self.fail("expected exception didn't occur")
+ self.check_syntax_error(cm.exception, "badsyntax_future6", 3)
def test_badfuture7(self):
- try:
+ with self.assertRaises(SyntaxError) as cm:
from test import badsyntax_future7
- except SyntaxError as msg:
- self.assertEqual(get_error_location(msg), ("badsyntax_future7", '3'))
- else:
- self.fail("expected exception didn't occur")
+ self.check_syntax_error(cm.exception, "badsyntax_future7", 3, 53)
def test_badfuture8(self):
- try:
+ with self.assertRaises(SyntaxError) as cm:
from test import badsyntax_future8
- except SyntaxError as msg:
- self.assertEqual(get_error_location(msg), ("badsyntax_future8", '3'))
- else:
- self.fail("expected exception didn't occur")
+ self.check_syntax_error(cm.exception, "badsyntax_future8", 3)
def test_badfuture9(self):
- try:
+ with self.assertRaises(SyntaxError) as cm:
from test import badsyntax_future9
- except SyntaxError as msg:
- self.assertEqual(get_error_location(msg), ("badsyntax_future9", '3'))
- else:
- self.fail("expected exception didn't occur")
+ self.check_syntax_error(cm.exception, "badsyntax_future9", 3, 0)
def test_badfuture10(self):
- try:
+ with self.assertRaises(SyntaxError) as cm:
from test import badsyntax_future10
- except SyntaxError as msg:
- self.assertEqual(get_error_location(msg), ("badsyntax_future10", '3'))
- else:
- self.fail("expected exception didn't occur")
+ self.check_syntax_error(cm.exception, "badsyntax_future10", 3, 0)
def test_parserhack(self):
# test that the parser.c::future_hack function works as expected
diff --git a/Lib/test/test_gdb.py b/Lib/test/test_gdb.py
index 2bd4457..60f1d92 100644
--- a/Lib/test/test_gdb.py
+++ b/Lib/test/test_gdb.py
@@ -679,7 +679,7 @@ class StackNavigationTests(DebuggerTests):
def test_pyup_command(self):
'Verify that the "py-up" command works'
bt = self.get_stack_trace(script=self.get_sample_script(),
- cmds_after_breakpoint=['py-up'])
+ cmds_after_breakpoint=['py-up', 'py-up'])
self.assertMultilineMatches(bt,
r'''^.*
#[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\)
@@ -698,7 +698,7 @@ $''')
def test_up_at_top(self):
'Verify handling of "py-up" at the top of the stack'
bt = self.get_stack_trace(script=self.get_sample_script(),
- cmds_after_breakpoint=['py-up'] * 4)
+ cmds_after_breakpoint=['py-up'] * 5)
self.assertEndsWith(bt,
'Unable to find an older python frame\n')
@@ -708,7 +708,7 @@ $''')
def test_up_then_down(self):
'Verify "py-up" followed by "py-down"'
bt = self.get_stack_trace(script=self.get_sample_script(),
- cmds_after_breakpoint=['py-up', 'py-down'])
+ cmds_after_breakpoint=['py-up', 'py-up', 'py-down'])
self.assertMultilineMatches(bt,
r'''^.*
#[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\)
@@ -727,6 +727,7 @@ class PyBtTests(DebuggerTests):
self.assertMultilineMatches(bt,
r'''^.*
Traceback \(most recent call first\):
+ <built-in method id of module object .*>
File ".*gdb_sample.py", line 10, in baz
id\(42\)
File ".*gdb_sample.py", line 7, in bar
@@ -815,7 +816,6 @@ id(42)
)
self.assertIn('Garbage-collecting', gdb_output)
- @unittest.skip("FIXME: builtin method is not shown in py-bt and py-bt-full")
@unittest.skipIf(python_is_optimized(),
"Python was compiled with optimizations")
# Some older versions of gdb will fail with
@@ -854,7 +854,7 @@ class PyPrintTests(DebuggerTests):
def test_basic_command(self):
'Verify that the "py-print" command works'
bt = self.get_stack_trace(script=self.get_sample_script(),
- cmds_after_breakpoint=['py-print args'])
+ cmds_after_breakpoint=['py-up', 'py-print args'])
self.assertMultilineMatches(bt,
r".*\nlocal 'args' = \(1, 2, 3\)\n.*")
@@ -863,7 +863,7 @@ class PyPrintTests(DebuggerTests):
@unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
def test_print_after_up(self):
bt = self.get_stack_trace(script=self.get_sample_script(),
- cmds_after_breakpoint=['py-up', 'py-print c', 'py-print b', 'py-print a'])
+ cmds_after_breakpoint=['py-up', 'py-up', 'py-print c', 'py-print b', 'py-print a'])
self.assertMultilineMatches(bt,
r".*\nlocal 'c' = 3\nlocal 'b' = 2\nlocal 'a' = 1\n.*")
@@ -871,7 +871,7 @@ class PyPrintTests(DebuggerTests):
"Python was compiled with optimizations")
def test_printing_global(self):
bt = self.get_stack_trace(script=self.get_sample_script(),
- cmds_after_breakpoint=['py-print __name__'])
+ cmds_after_breakpoint=['py-up', 'py-print __name__'])
self.assertMultilineMatches(bt,
r".*\nglobal '__name__' = '__main__'\n.*")
@@ -879,7 +879,7 @@ class PyPrintTests(DebuggerTests):
"Python was compiled with optimizations")
def test_printing_builtin(self):
bt = self.get_stack_trace(script=self.get_sample_script(),
- cmds_after_breakpoint=['py-print len'])
+ cmds_after_breakpoint=['py-up', 'py-print len'])
self.assertMultilineMatches(bt,
r".*\nbuiltin 'len' = <built-in method len of module object at remote 0x-?[0-9a-f]+>\n.*")
@@ -888,7 +888,7 @@ class PyLocalsTests(DebuggerTests):
"Python was compiled with optimizations")
def test_basic_command(self):
bt = self.get_stack_trace(script=self.get_sample_script(),
- cmds_after_breakpoint=['py-locals'])
+ cmds_after_breakpoint=['py-up', 'py-locals'])
self.assertMultilineMatches(bt,
r".*\nargs = \(1, 2, 3\)\n.*")
@@ -897,7 +897,7 @@ class PyLocalsTests(DebuggerTests):
"Python was compiled with optimizations")
def test_locals_after_up(self):
bt = self.get_stack_trace(script=self.get_sample_script(),
- cmds_after_breakpoint=['py-up', 'py-locals'])
+ cmds_after_breakpoint=['py-up', 'py-up', 'py-locals'])
self.assertMultilineMatches(bt,
r".*\na = 1\nb = 2\nc = 3\n.*")
diff --git a/Lib/test/test_genericpath.py b/Lib/test/test_genericpath.py
index ae5dd6a..f698e13 100644
--- a/Lib/test/test_genericpath.py
+++ b/Lib/test/test_genericpath.py
@@ -8,6 +8,7 @@ import sys
import unittest
import warnings
from test import support
+android_not_root = support.android_not_root
def create_file(filename, data=b'foo'):
@@ -212,6 +213,7 @@ class GenericTest:
def test_samefile_on_symlink(self):
self._test_samefile_on_link_func(os.symlink)
+ @unittest.skipIf(android_not_root, "hard links not allowed, non root user")
def test_samefile_on_link(self):
self._test_samefile_on_link_func(os.link)
@@ -251,6 +253,7 @@ class GenericTest:
def test_samestat_on_symlink(self):
self._test_samestat_on_link_func(os.symlink)
+ @unittest.skipIf(android_not_root, "hard links not allowed, non root user")
def test_samestat_on_link(self):
self._test_samestat_on_link_func(os.link)
diff --git a/Lib/test/test_global.py b/Lib/test/test_global.py
index 37ec672..9eeccf1 100644
--- a/Lib/test/test_global.py
+++ b/Lib/test/test_global.py
@@ -24,7 +24,7 @@ def wrong1():
global a
global b
"""
- check_syntax_error(self, prog_text_1)
+ check_syntax_error(self, prog_text_1, lineno=4, offset=4)
def test2(self):
prog_text_2 = """\
@@ -32,7 +32,7 @@ def wrong2():
print(x)
global x
"""
- check_syntax_error(self, prog_text_2)
+ check_syntax_error(self, prog_text_2, lineno=3, offset=4)
def test3(self):
prog_text_3 = """\
@@ -41,7 +41,7 @@ def wrong3():
x = 2
global x
"""
- check_syntax_error(self, prog_text_3)
+ check_syntax_error(self, prog_text_3, lineno=4, offset=4)
def test4(self):
prog_text_4 = """\
diff --git a/Lib/test/test_importlib/test_locks.py b/Lib/test/test_importlib/test_locks.py
index b2aadff..dbce9c2 100644
--- a/Lib/test/test_importlib/test_locks.py
+++ b/Lib/test/test_importlib/test_locks.py
@@ -57,7 +57,7 @@ if threading is not None:
def setUp(self):
try:
self.old_switchinterval = sys.getswitchinterval()
- sys.setswitchinterval(0.000001)
+ support.setswitchinterval(0.000001)
except AttributeError:
self.old_switchinterval = None
diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py
index aeabdbb..2ba9443 100644
--- a/Lib/test/test_mailbox.py
+++ b/Lib/test/test_mailbox.py
@@ -2137,9 +2137,9 @@ class MaildirTestCase(unittest.TestCase):
if mbox:
fp.write(FROM_)
fp.write(DUMMY_MESSAGE)
- if hasattr(os, "link"):
+ try:
os.link(tmpname, newname)
- else:
+ except (AttributeError, PermissionError):
with open(newname, "w") as fp:
fp.write(DUMMY_MESSAGE)
self._msgfiles.append(newname)
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py
index f98c1fe..ce1ca15 100644
--- a/Lib/test/test_pathlib.py
+++ b/Lib/test/test_pathlib.py
@@ -10,6 +10,7 @@ import tempfile
import unittest
from test import support
+android_not_root = support.android_not_root
TESTFN = support.TESTFN
try:
@@ -1864,6 +1865,7 @@ class _BasePathTest(object):
self.assertFalse((P / 'fileA' / 'bah').is_fifo())
@unittest.skipUnless(hasattr(os, "mkfifo"), "os.mkfifo() required")
+ @unittest.skipIf(android_not_root, "mkfifo not allowed, non root user")
def test_is_fifo_true(self):
P = self.cls(BASE, 'myfifo')
os.mkfifo(str(P))
@@ -1886,7 +1888,8 @@ class _BasePathTest(object):
try:
sock.bind(str(P))
except OSError as e:
- if "AF_UNIX path too long" in str(e):
+ if (isinstance(e, PermissionError) or
+ "AF_UNIX path too long" in str(e)):
self.skipTest("cannot bind Unix socket: " + str(e))
self.assertTrue(P.is_socket())
self.assertFalse(P.is_fifo())
@@ -2080,6 +2083,8 @@ class PosixPathTest(_BasePathTest, unittest.TestCase):
self.assertEqual(given, expect)
self.assertEqual(set(p.rglob("FILEd*")), set())
+ @unittest.skipUnless(hasattr(pwd, 'getpwall'),
+ 'pwd module does not expose getpwall()')
def test_expanduser(self):
P = self.cls
support.import_module('pwd')
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index 63c74cd..029d081 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -1,6 +1,7 @@
"Test posix functions"
from test import support
+android_not_root = support.android_not_root
# Skip these tests if there is no posix module.
posix = support.import_module('posix')
@@ -422,6 +423,7 @@ class PosixTester(unittest.TestCase):
posix.stat, list(os.fsencode(support.TESTFN)))
@unittest.skipUnless(hasattr(posix, 'mkfifo'), "don't have mkfifo()")
+ @unittest.skipIf(android_not_root, "mkfifo not allowed, non root user")
def test_mkfifo(self):
support.unlink(support.TESTFN)
posix.mkfifo(support.TESTFN, stat.S_IRUSR | stat.S_IWUSR)
@@ -429,6 +431,7 @@ class PosixTester(unittest.TestCase):
@unittest.skipUnless(hasattr(posix, 'mknod') and hasattr(stat, 'S_IFIFO'),
"don't have mknod()/S_IFIFO")
+ @unittest.skipIf(android_not_root, "mknod not allowed, non root user")
def test_mknod(self):
# Test using mknod() to create a FIFO (the only use specified
# by POSIX).
@@ -907,6 +910,7 @@ class PosixTester(unittest.TestCase):
posix.close(f)
@unittest.skipUnless(os.link in os.supports_dir_fd, "test needs dir_fd support in os.link()")
+ @unittest.skipIf(android_not_root, "hard link not allowed, non root user")
def test_link_dir_fd(self):
f = posix.open(posix.getcwd(), posix.O_RDONLY)
try:
@@ -930,6 +934,7 @@ class PosixTester(unittest.TestCase):
@unittest.skipUnless((os.mknod in os.supports_dir_fd) and hasattr(stat, 'S_IFIFO'),
"test requires both stat.S_IFIFO and dir_fd support for os.mknod()")
+ @unittest.skipIf(android_not_root, "mknod not allowed, non root user")
def test_mknod_dir_fd(self):
# Test using mknodat() to create a FIFO (the only use specified
# by POSIX).
@@ -1013,6 +1018,7 @@ class PosixTester(unittest.TestCase):
posix.close(f)
@unittest.skipUnless(os.mkfifo in os.supports_dir_fd, "test needs dir_fd support in os.mkfifo()")
+ @unittest.skipIf(android_not_root, "mkfifo not allowed, non root user")
def test_mkfifo_dir_fd(self):
support.unlink(support.TESTFN)
f = posix.open(posix.getcwd(), posix.O_RDONLY)
diff --git a/Lib/test/test_pwd.py b/Lib/test/test_pwd.py
index b7b1a4a..ac9cff7 100644
--- a/Lib/test/test_pwd.py
+++ b/Lib/test/test_pwd.py
@@ -4,10 +4,19 @@ from test import support
pwd = support.import_module('pwd')
+def _getpwall():
+ # Android does not have getpwall.
+ if hasattr(pwd, 'getpwall'):
+ return pwd.getpwall()
+ elif hasattr(pwd, 'getpwuid'):
+ return [pwd.getpwuid(0)]
+ else:
+ return []
+
class PwdTest(unittest.TestCase):
def test_values(self):
- entries = pwd.getpwall()
+ entries = _getpwall()
for e in entries:
self.assertEqual(len(e), 7)
@@ -33,7 +42,7 @@ class PwdTest(unittest.TestCase):
# and check afterwards (done in test_values_extended)
def test_values_extended(self):
- entries = pwd.getpwall()
+ entries = _getpwall()
entriesbyname = {}
entriesbyuid = {}
@@ -57,12 +66,13 @@ class PwdTest(unittest.TestCase):
self.assertRaises(TypeError, pwd.getpwuid, 3.14)
self.assertRaises(TypeError, pwd.getpwnam)
self.assertRaises(TypeError, pwd.getpwnam, 42)
- self.assertRaises(TypeError, pwd.getpwall, 42)
+ if hasattr(pwd, 'getpwall'):
+ self.assertRaises(TypeError, pwd.getpwall, 42)
# try to get some errors
bynames = {}
byuids = {}
- for (n, p, u, g, gecos, d, s) in pwd.getpwall():
+ for (n, p, u, g, gecos, d, s) in _getpwall():
bynames[n] = u
byuids[u] = n
@@ -96,13 +106,17 @@ class PwdTest(unittest.TestCase):
# loop, say), pwd.getpwuid() might still be able to find data for that
# uid. Using sys.maxint may provoke the same problems, but hopefully
# it will be a more repeatable failure.
+ # Android accepts a very large span of uids including sys.maxsize and
+ # -1; it raises KeyError with 1 or 2 for example.
fakeuid = sys.maxsize
self.assertNotIn(fakeuid, byuids)
- self.assertRaises(KeyError, pwd.getpwuid, fakeuid)
+ if not support.is_android:
+ self.assertRaises(KeyError, pwd.getpwuid, fakeuid)
# -1 shouldn't be a valid uid because it has a special meaning in many
# uid-related functions
- self.assertRaises(KeyError, pwd.getpwuid, -1)
+ if not support.is_android:
+ self.assertRaises(KeyError, pwd.getpwuid, -1)
# should be out of uid_t range
self.assertRaises(KeyError, pwd.getpwuid, 2**128)
self.assertRaises(KeyError, pwd.getpwuid, -2**128)
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
index af5f00f..46e2c57 100644
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -22,7 +22,8 @@ import tarfile
import warnings
from test import support
-from test.support import TESTFN, check_warnings, captured_stdout, requires_zlib
+from test.support import (TESTFN, check_warnings, captured_stdout,
+ requires_zlib, android_not_root)
try:
import bz2
@@ -787,6 +788,7 @@ class TestShutil(unittest.TestCase):
@unittest.skipIf(os.name == 'nt', 'temporarily disabled on Windows')
@unittest.skipUnless(hasattr(os, 'link'), 'requires os.link')
+ @unittest.skipIf(android_not_root, "hard links not allowed, non root user")
def test_dont_copy_file_onto_link_to_itself(self):
# bug 851123.
os.mkdir(TESTFN)
@@ -839,6 +841,7 @@ class TestShutil(unittest.TestCase):
# Issue #3002: copyfile and copytree block indefinitely on named pipes
@unittest.skipUnless(hasattr(os, "mkfifo"), 'requires os.mkfifo()')
+ @unittest.skipIf(android_not_root, "mkfifo not allowed, non root user")
def test_copyfile_named_pipe(self):
os.mkfifo(TESTFN)
try:
@@ -849,6 +852,7 @@ class TestShutil(unittest.TestCase):
finally:
os.remove(TESTFN)
+ @unittest.skipIf(android_not_root, "mkfifo not allowed, non root user")
@unittest.skipUnless(hasattr(os, "mkfifo"), 'requires os.mkfifo()')
@support.skip_unless_symlink
def test_copytree_named_pipe(self):
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 59564c9..6b29e18 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -278,8 +278,14 @@ class ThreadableTest:
def clientRun(self, test_func):
self.server_ready.wait()
- self.clientSetUp()
- self.client_ready.set()
+ try:
+ self.clientSetUp()
+ except BaseException as e:
+ self.queue.put(e)
+ self.clientTearDown()
+ return
+ finally:
+ self.client_ready.set()
if self.server_crashed:
self.clientTearDown()
return
@@ -520,8 +526,11 @@ class ConnectedStreamTestMixin(SocketListeningTestMixin,
self.serv_conn = self.cli
def clientTearDown(self):
- self.serv_conn.close()
- self.serv_conn = None
+ try:
+ self.serv_conn.close()
+ self.serv_conn = None
+ except AttributeError:
+ pass
super().clientTearDown()
@@ -540,7 +549,7 @@ class UnixSocketTestBase(SocketTestBase):
def bindSock(self, sock):
path = tempfile.mktemp(dir=self.dir_path)
- sock.bind(path)
+ support.bind_unix_socket(sock, path)
self.addCleanup(support.unlink, path)
class UnixStreamBase(UnixSocketTestBase):
@@ -4631,7 +4640,7 @@ class TestUnixDomain(unittest.TestCase):
def bind(self, sock, path):
# Bind the socket
try:
- sock.bind(path)
+ support.bind_unix_socket(sock, path)
except OSError as e:
if str(e) == "AF_UNIX path too long":
self.skipTest(
diff --git a/Lib/test/test_stat.py b/Lib/test/test_stat.py
index f1a5938..cd02a6e 100644
--- a/Lib/test/test_stat.py
+++ b/Lib/test/test_stat.py
@@ -1,7 +1,7 @@
import unittest
import os
import sys
-from test.support import TESTFN, import_fresh_module
+from test.support import TESTFN, import_fresh_module, android_not_root
c_stat = import_fresh_module('stat', fresh=['_stat'])
py_stat = import_fresh_module('stat', blocked=['_stat'])
@@ -168,6 +168,7 @@ class TestFilemode:
self.assertS_IS("LNK", st_mode)
@unittest.skipUnless(hasattr(os, 'mkfifo'), 'os.mkfifo not available')
+ @unittest.skipIf(android_not_root, "mkfifo not allowed, non root user")
def test_fifo(self):
os.mkfifo(TESTFN, 0o700)
st_mode, modestr = self.get_mode()
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index 553822b..e83a4d6 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -240,7 +240,7 @@ class TestSupport(unittest.TestCase):
self.assertEqual(cm.exception.errno, errno.EBADF)
def test_check_syntax_error(self):
- support.check_syntax_error(self, "def class")
+ support.check_syntax_error(self, "def class", lineno=1, offset=9)
with self.assertRaises(AssertionError):
support.check_syntax_error(self, "x=1")
diff --git a/Lib/test/test_symtable.py b/Lib/test/test_symtable.py
index 3047165..dfaee17 100644
--- a/Lib/test/test_symtable.py
+++ b/Lib/test/test_symtable.py
@@ -159,15 +159,17 @@ class SymtableTest(unittest.TestCase):
def test_filename_correct(self):
### Bug tickler: SyntaxError file name correct whether error raised
### while parsing or building symbol table.
- def checkfilename(brokencode):
+ def checkfilename(brokencode, offset):
try:
symtable.symtable(brokencode, "spam", "exec")
except SyntaxError as e:
self.assertEqual(e.filename, "spam")
+ self.assertEqual(e.lineno, 1)
+ self.assertEqual(e.offset, offset)
else:
self.fail("no SyntaxError for %r" % (brokencode,))
- checkfilename("def f(x): foo)(") # parse-time
- checkfilename("def f(x): global x") # symtable-build-time
+ checkfilename("def f(x): foo)(", 14) # parse-time
+ checkfilename("def f(x): global x", 10) # symtable-build-time
symtable.symtable("pass", b"spam", "exec")
with self.assertWarns(DeprecationWarning), \
self.assertRaises(TypeError):
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index 80e36fd..7f7e6da 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -544,7 +544,7 @@ from test import support
class SyntaxTestCase(unittest.TestCase):
def _check_error(self, code, errtext,
- filename="<testcase>", mode="exec", subclass=None):
+ filename="<testcase>", mode="exec", subclass=None, lineno=None, offset=None):
"""Check that compiling code raises SyntaxError with errtext.
errtest is a regular expression that must be present in the
@@ -559,6 +559,11 @@ class SyntaxTestCase(unittest.TestCase):
mo = re.search(errtext, str(err))
if mo is None:
self.fail("SyntaxError did not contain '%r'" % (errtext,))
+ self.assertEqual(err.filename, filename)
+ if lineno is not None:
+ self.assertEqual(err.lineno, lineno)
+ if offset is not None:
+ self.assertEqual(err.offset, offset)
else:
self.fail("compile() did not raise SyntaxError")
@@ -569,7 +574,7 @@ class SyntaxTestCase(unittest.TestCase):
self._check_error("del f()", "delete")
def test_global_err_then_warn(self):
- # Bug tickler: The SyntaxError raised for one global statement
+ # Bug #763201: The SyntaxError raised for one global statement
# shouldn't be clobbered by a SyntaxWarning issued for a later one.
source = """if 1:
def error(a):
diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py
index 091e905..355bc61 100644
--- a/Lib/test/test_sysconfig.py
+++ b/Lib/test/test_sysconfig.py
@@ -385,7 +385,9 @@ class TestSysConfig(unittest.TestCase):
self.assertIsNotNone(vars['SO'])
self.assertEqual(vars['SO'], vars['EXT_SUFFIX'])
- @unittest.skipUnless(sys.platform == 'linux', 'Linux-specific test')
+ @unittest.skipUnless(sys.platform == 'linux' and
+ hasattr(sys.implementation, '_multiarch'),
+ 'multiarch-specific test')
def test_triplet_in_ext_suffix(self):
import ctypes, platform, re
machine = platform.machine()
@@ -395,7 +397,6 @@ class TestSysConfig(unittest.TestCase):
if re.match('(i[3-6]86|x86_64)$', machine):
if ctypes.sizeof(ctypes.c_char_p()) == 4:
self.assertTrue(suffix.endswith('i386-linux-gnu.so') or
- suffix.endswith('i686-linux-android.so') or
suffix.endswith('x86_64-linux-gnux32.so'),
suffix)
else: # 8 byte pointer size
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 845e7d4..2c2914f 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -462,7 +462,7 @@ class ThreadTests(BaseTestCase):
self.addCleanup(sys.setswitchinterval, old_interval)
# Make the bug more likely to manifest.
- sys.setswitchinterval(1e-6)
+ test.support.setswitchinterval(1e-6)
for i in range(20):
t = threading.Thread(target=lambda: None)