summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/distutils/command/check.py2
-rw-r--r--Lib/inspect.py2
-rwxr-xr-xLib/test/regrtest.py66
-rw-r--r--Lib/test/test_ast.py8
-rw-r--r--Lib/test/test_inspect.py22
-rw-r--r--Lib/test/test_module.py8
-rw-r--r--Lib/test/test_strptime.py15
-rw-r--r--Lib/test/test_threading.py4
-rw-r--r--Lib/test/test_tokenize.py18
-rw-r--r--Lib/tokenize.py33
-rw-r--r--Lib/xml/__init__.py6
11 files changed, 124 insertions, 60 deletions
diff --git a/Lib/distutils/command/check.py b/Lib/distutils/command/check.py
index 9a8fca1..12844cb 100644
--- a/Lib/distutils/command/check.py
+++ b/Lib/distutils/command/check.py
@@ -92,7 +92,7 @@ class check(Command):
missing.append(attr)
if missing:
- self.warn("missing required meta-data: %s" % ' ,'.join(missing))
+ self.warn("missing required meta-data: %s" % ', '.join(missing))
if metadata.author:
if not metadata.author_email:
self.warn("missing meta-data: if 'author' supplied, " +
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 1f1b7f9..c489502 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -238,7 +238,7 @@ def isroutine(object):
def isabstract(object):
"""Return true if the object is an abstract base class (ABC)."""
- return isinstance(object, type) and object.__flags__ & TPFLAGS_IS_ABSTRACT
+ return bool(isinstance(object, type) and object.__flags__ & TPFLAGS_IS_ABSTRACT)
def getmembers(object, predicate=None):
"""Return all members of an object as (name, value) pairs sorted by name.
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
index 75a74fa..9fb0692 100755
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -193,6 +193,14 @@ if sys.platform == 'darwin':
newsoft = min(hard, max(soft, 1024*2048))
resource.setrlimit(resource.RLIMIT_STACK, (newsoft, hard))
+# Test result constants.
+PASSED = 1
+FAILED = 0
+ENV_CHANGED = -1
+SKIPPED = -2
+RESOURCE_DENIED = -3
+INTERRUPTED = -4
+
from test import support
RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network',
@@ -352,7 +360,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
try:
result = runtest(*args, **kwargs)
except BaseException as e:
- result = -4, e.__class__.__name__
+ result = INTERRUPTED, e.__class__.__name__
sys.stdout.flush()
print() # Force a newline (just in case)
print(json.dumps(result))
@@ -443,19 +451,18 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
def accumulate_result(test, result):
ok, test_time = result
test_times.append((test_time, test))
- if ok > 0:
+ if ok == PASSED:
good.append(test)
- return 'good'
- elif -2 < ok <= 0:
+ elif ok == FAILED:
bad.append(test)
- if ok == -1:
- environment_changed.append(test)
- return 'bad'
- else:
+ elif ok == ENV_CHANGED:
+ bad.append(test)
+ environment_changed.append(test)
+ elif ok == SKIPPED:
skipped.append(test)
- if ok == -3:
- resource_denieds.append(test)
- return 'skipped'
+ elif ok == RESOURCE_DENIED:
+ skipped.append(test)
+ resource_denieds.append(test)
if use_mp:
from threading import Thread
@@ -511,7 +518,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
print(stdout)
if stderr:
print(stderr, file=sys.stderr)
- if result[0] == -4:
+ if result[0] == INTERRUPTED:
assert result[1] == 'KeyboardInterrupt'
pending.clear()
raise KeyboardInterrupt # What else?
@@ -532,8 +539,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
try:
result = runtest(test, verbose, quiet,
testdir, huntrleaks, debug)
- which = accumulate_result(test, result)
- if verbose3 and which == 'bad':
+ accumulate_result(test, result)
+ if verbose3 and result[0] == FAILED:
print("Re-running test {} in verbose mode".format(test))
runtest(test, True, quiet, testdir, huntrleaks, debug)
except KeyboardInterrupt:
@@ -679,15 +686,14 @@ def runtest(test, verbose, quiet,
testdir -- test directory
huntrleaks -- run multiple times to test for leaks; requires a debug
build; a triple corresponding to -R's three arguments
- debug -- if true, print tracebacks for failed tests regardless of
- verbose setting
- Return:
- -4 KeyboardInterrupt when run under -j
- -3 test skipped because resource denied
- -2 test skipped for some other reason
- -1 test failed because it changed the execution environment
- 0 test failed
- 1 test passed
+
+ Returns one of the test result constants:
+ INTERRUPTED KeyboardInterrupt when run under -j
+ RESOURCE_DENIED test skipped because resource denied
+ SKIPPED test skipped for some other reason
+ ENV_CHANGED test failed because it changed the execution environment
+ FAILED test failed
+ PASSED test passed
"""
support.verbose = verbose # Tell tests to be moderately quiet
@@ -843,18 +849,18 @@ def runtest_inner(test, verbose, quiet,
if not quiet:
print(test, "skipped --", msg)
sys.stdout.flush()
- return -3, test_time
+ return RESOURCE_DENIED, test_time
except unittest.SkipTest as msg:
if not quiet:
print(test, "skipped --", msg)
sys.stdout.flush()
- return -2, test_time
+ return SKIPPED, test_time
except KeyboardInterrupt:
raise
except support.TestFailed as msg:
print("test", test, "failed --", msg)
sys.stdout.flush()
- return 0, test_time
+ return FAILED, test_time
except:
type, value = sys.exc_info()[:2]
print("test", test, "crashed --", str(type) + ":", value)
@@ -862,13 +868,13 @@ def runtest_inner(test, verbose, quiet,
if verbose or debug:
traceback.print_exc(file=sys.stdout)
sys.stdout.flush()
- return 0, test_time
+ return FAILED, test_time
else:
if refleak:
- return 0, test_time
+ return FAILED, test_time
if environment.changed:
- return -1, test_time
- return 1, test_time
+ return ENV_CHANGED, test_time
+ return PASSED, test_time
def cleanup_test_droppings(testname, verbose):
import shutil
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index 0a832c4..07697ac 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -154,6 +154,14 @@ class AST_Tests(unittest.TestCase):
im = ast.parse("from . import y").body[0]
self.assertIsNone(im.module)
+ def test_base_classes(self):
+ self.assertTrue(issubclass(ast.For, ast.stmt))
+ self.assertTrue(issubclass(ast.Name, ast.expr))
+ self.assertTrue(issubclass(ast.stmt, ast.AST))
+ self.assertTrue(issubclass(ast.expr, ast.AST))
+ self.assertTrue(issubclass(ast.comprehension, ast.AST))
+ self.assertTrue(issubclass(ast.Gt, ast.AST))
+
def test_nodeclasses(self):
x = ast.BinOp(1, 2, 3, lineno=0)
self.assertEquals(x.left, 1)
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index c1df23e..9dba30d 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -120,6 +120,28 @@ class TestPredicates(IsTestBase):
self.assertTrue('a' in members)
self.assertTrue('b' not in members)
+ def test_isabstract(self):
+ from abc import ABCMeta, abstractmethod
+
+ class AbstractClassExample(metaclass=ABCMeta):
+
+ @abstractmethod
+ def foo(self):
+ pass
+
+ class ClassExample(AbstractClassExample):
+ def foo(self):
+ pass
+
+ a = ClassExample()
+
+ # Test general behaviour.
+ self.assertTrue(inspect.isabstract(AbstractClassExample))
+ self.assertFalse(inspect.isabstract(ClassExample))
+ self.assertFalse(inspect.isabstract(a))
+ self.assertFalse(inspect.isabstract(int))
+ self.assertFalse(inspect.isabstract(5))
+
class TestInterpreterStack(IsTestBase):
def __init__(self, *args, **kwargs):
diff --git a/Lib/test/test_module.py b/Lib/test/test_module.py
index 0e56290..21ddc9a 100644
--- a/Lib/test/test_module.py
+++ b/Lib/test/test_module.py
@@ -55,6 +55,14 @@ class ModuleTests(unittest.TestCase):
{"__name__": "foo", "__doc__": "foodoc", "bar": 42})
self.assertTrue(foo.__dict__ is d)
+ def test_dont_clear_dict(self):
+ # See issue 7140.
+ def f():
+ foo = ModuleType("foo")
+ foo.bar = 4
+ return foo
+ self.assertEqual(f().__dict__["bar"], 4)
+
def test_main():
run_unittest(ModuleTests)
diff --git a/Lib/test/test_strptime.py b/Lib/test/test_strptime.py
index fb60ee4..9008717 100644
--- a/Lib/test/test_strptime.py
+++ b/Lib/test/test_strptime.py
@@ -493,9 +493,9 @@ class CacheTests(unittest.TestCase):
_strptime._strptime_time("10", "%d")
_strptime._strptime_time("2005", "%Y")
_strptime._TimeRE_cache.locale_time.lang = "Ni"
- original_time_re = id(_strptime._TimeRE_cache)
+ original_time_re = _strptime._TimeRE_cache
_strptime._strptime_time("10", "%d")
- self.assertNotEqual(original_time_re, id(_strptime._TimeRE_cache))
+ self.assertIsNot(original_time_re, _strptime._TimeRE_cache)
self.assertEqual(len(_strptime._regex_cache), 1)
def test_regex_cleanup(self):
@@ -514,11 +514,10 @@ class CacheTests(unittest.TestCase):
def test_new_localetime(self):
# A new LocaleTime instance should be created when a new TimeRE object
# is created.
- locale_time_id = id(_strptime._TimeRE_cache.locale_time)
+ locale_time_id = _strptime._TimeRE_cache.locale_time
_strptime._TimeRE_cache.locale_time.lang = "Ni"
_strptime._strptime_time("10", "%d")
- self.assertNotEqual(locale_time_id,
- id(_strptime._TimeRE_cache.locale_time))
+ self.assertIsNot(locale_time_id, _strptime._TimeRE_cache.locale_time)
def test_TimeRE_recreation(self):
# The TimeRE instance should be recreated upon changing the locale.
@@ -530,15 +529,15 @@ class CacheTests(unittest.TestCase):
try:
_strptime._strptime_time('10', '%d')
# Get id of current cache object.
- first_time_re_id = id(_strptime._TimeRE_cache)
+ first_time_re = _strptime._TimeRE_cache
try:
# Change the locale and force a recreation of the cache.
locale.setlocale(locale.LC_TIME, ('de_DE', 'UTF8'))
_strptime._strptime_time('10', '%d')
# Get the new cache object's id.
- second_time_re_id = id(_strptime._TimeRE_cache)
+ second_time_re = _strptime._TimeRE_cache
# They should not be equal.
- self.assertNotEqual(first_time_re_id, second_time_re_id)
+ self.assertIsNot(first_time_re, second_time_re)
# Possible test locale is not supported while initial locale is.
# If this is the case just suppress the exception and fall-through
# to the reseting to the original locale.
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 330a2c5..c5d8d79 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -185,11 +185,13 @@ class ThreadTests(BaseTestCase):
except AsyncExc:
pass
else:
+ # This code is unreachable but it reflects the intent. If we wanted
+ # to be smarter the above loop wouldn't be infinite.
self.fail("AsyncExc not raised")
try:
self.assertEqual(result, 1) # one thread state modified
except UnboundLocalError:
- # The exception was raised to quickly for us to get the result.
+ # The exception was raised too quickly for us to get the result.
pass
# `worker_started` is set by the thread when it's inside a try/except
diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py
index ba705ba..7b91ab2 100644
--- a/Lib/test/test_tokenize.py
+++ b/Lib/test/test_tokenize.py
@@ -531,6 +531,24 @@ pass the '-ucompiler' option to process the full directory.
... break
... else: True
True
+
+Evil tabs
+ >>> dump_tokens("def f():\\n\\tif x\\n \\tpass")
+ ENCODING 'utf-8' (0, 0) (0, 0)
+ NAME 'def' (1, 0) (1, 3)
+ NAME 'f' (1, 4) (1, 5)
+ OP '(' (1, 5) (1, 6)
+ OP ')' (1, 6) (1, 7)
+ OP ':' (1, 7) (1, 8)
+ NEWLINE '\\n' (1, 8) (1, 9)
+ INDENT '\\t' (2, 0) (2, 1)
+ NAME 'if' (2, 1) (2, 3)
+ NAME 'x' (2, 4) (2, 5)
+ NEWLINE '\\n' (2, 5) (2, 6)
+ INDENT ' \\t' (3, 0) (3, 9)
+ NAME 'pass' (3, 9) (3, 13)
+ DEDENT '' (4, 0) (4, 0)
+ DEDENT '' (4, 0) (4, 0)
"""
from test import support
diff --git a/Lib/tokenize.py b/Lib/tokenize.py
index fb58c6b..9d2a6bb 100644
--- a/Lib/tokenize.py
+++ b/Lib/tokenize.py
@@ -23,15 +23,15 @@ __author__ = 'Ka-Ping Yee <ping@lfw.org>'
__credits__ = ('GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, '
'Skip Montanaro, Raymond Hettinger, Trent Nelson, '
'Michael Foord')
-
import re, string, sys
from token import *
from codecs import lookup, BOM_UTF8
cookie_re = re.compile("coding[:=]\s*([-\w.]+)")
import token
-__all__ = [x for x in dir(token) if x[0] != '_'] + ["COMMENT", "tokenize",
- "detect_encoding", "NL", "untokenize", "ENCODING", "TokenInfo"]
+__all__ = [x for x in dir(token) if not x.startswith("_")]
+__all__.extend(["COMMENT", "tokenize", "detect_encoding", "NL", "untokenize",
+ "ENCODING", "TokenInfo"])
del token
COMMENT = N_TOKENS
@@ -407,7 +407,7 @@ def _tokenize(readline, encoding):
if encoding is not None:
line = line.decode(encoding)
- lnum = lnum + 1
+ lnum += 1
pos, max = 0, len(line)
if contstr: # continued string
@@ -435,12 +435,17 @@ def _tokenize(readline, encoding):
if not line: break
column = 0
while pos < max: # measure leading whitespace
- if line[pos] == ' ': column = column + 1
- elif line[pos] == '\t': column = (column/tabsize + 1)*tabsize
- elif line[pos] == '\f': column = 0
- else: break
- pos = pos + 1
- if pos == max: break
+ if line[pos] == ' ':
+ column += 1
+ elif line[pos] == '\t':
+ column = (column//tabsize + 1)*tabsize
+ elif line[pos] == '\f':
+ column = 0
+ else:
+ break
+ pos += 1
+ if pos == max:
+ break
if line[pos] in '#\r\n': # skip comments or blank lines
if line[pos] == '#':
@@ -516,13 +521,15 @@ def _tokenize(readline, encoding):
elif initial == '\\': # continued stmt
continued = 1
else:
- if initial in '([{': parenlev = parenlev + 1
- elif initial in ')]}': parenlev = parenlev - 1
+ if initial in '([{':
+ parenlev += 1
+ elif initial in ')]}':
+ parenlev -= 1
yield TokenInfo(OP, token, spos, epos, line)
else:
yield TokenInfo(ERRORTOKEN, line[pos],
(lnum, pos), (lnum, pos+1), line)
- pos = pos + 1
+ pos += 1
for indent in indents[1:]: # pop remaining indent levels
yield TokenInfo(DEDENT, '', (lnum, 0), (lnum, 0), '')
diff --git a/Lib/xml/__init__.py b/Lib/xml/__init__.py
index fa5e8cd..deed983 100644
--- a/Lib/xml/__init__.py
+++ b/Lib/xml/__init__.py
@@ -19,12 +19,6 @@ etree -- The ElementTree XML library. This is a subset of the full
__all__ = ["dom", "parsers", "sax", "etree"]
-# When being checked-out without options, this has the form
-# "<dollar>Revision: x.y </dollar>"
-# When exported using -kv, it is "x.y".
-__version__ = "$Revision$".split()[-2:][0]
-
-
_MINIMUM_XMLPLUS_VERSION = (0, 8, 4)