summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Doc/library/gzip.rst2
-rw-r--r--Doc/library/logging.rst6
-rw-r--r--Doc/tutorial/introduction.rst6
-rw-r--r--Lib/compileall.py2
-rw-r--r--Lib/ctypes/test/test_internals.py8
-rw-r--r--Lib/logging/__init__.py2
-rw-r--r--Lib/test/test_importhooks.py10
-rw-r--r--Lib/test/test_tarfile.py21
-rw-r--r--Lib/test/test_unittest.py15
-rw-r--r--Lib/test/test_xml_etree.py4
-rw-r--r--Lib/unittest/loader.py28
-rw-r--r--Makefile.pre.in2
-rw-r--r--Misc/Porting2
13 files changed, 71 insertions, 37 deletions
diff --git a/Doc/library/gzip.rst b/Doc/library/gzip.rst
index a830593..b99ac74 100644
--- a/Doc/library/gzip.rst
+++ b/Doc/library/gzip.rst
@@ -67,7 +67,7 @@ The module defines the following items:
writing as *fileobj*, and retrieve the resulting memory buffer using the
:class:`StringIO` object's :meth:`getvalue` method.
- :class:`GzipFile` supports the :keyword:`with` statement.
+ :class:`GzipFile` supports iteration and the :keyword:`with` statement.
.. versionchanged:: 3.1
Support for the :keyword:`with` statement was added.
diff --git a/Doc/library/logging.rst b/Doc/library/logging.rst
index c5997ef..347c72c 100644
--- a/Doc/library/logging.rst
+++ b/Doc/library/logging.rst
@@ -734,7 +734,11 @@ functions.
Provides an overriding level *lvl* for all loggers which takes precedence over
the logger's own level. When the need arises to temporarily throttle logging
- output down across the whole application, this function can be useful.
+ output down across the whole application, this function can be useful. Its
+ effect is to disable all logging calls of severity *lvl* and below, so that
+ if you call it with a value of INFO, then all INFO and DEBUG events would be
+ discarded, whereas those of severity WARNING and above would be processed
+ according to the logger's effective level.
.. function:: addLevelName(lvl, levelName)
diff --git a/Doc/tutorial/introduction.rst b/Doc/tutorial/introduction.rst
index 97065af..f6339a7 100644
--- a/Doc/tutorial/introduction.rst
+++ b/Doc/tutorial/introduction.rst
@@ -482,6 +482,12 @@ concatenated and so on::
>>> 3*a[:3] + ['Boo!']
['spam', 'eggs', 100, 'spam', 'eggs', 100, 'spam', 'eggs', 100, 'Boo!']
+All slice operations return a new list containing the requested elements. This
+means that the following slice returns a shallow copy of the list *a*::
+
+ >>> a[:]
+ ['spam', 'eggs', 100, 1234]
+
Unlike strings, which are *immutable*, it is possible to change individual
elements of a list::
diff --git a/Lib/compileall.py b/Lib/compileall.py
index eb5e24b..ae86292 100644
--- a/Lib/compileall.py
+++ b/Lib/compileall.py
@@ -97,8 +97,6 @@ def compile_file(fullname, ddir=None, force=0, rx=None, quiet=0):
print('Compiling', fullname, '...')
try:
ok = py_compile.compile(fullname, None, dfile, True)
- except KeyboardInterrupt:
- raise KeyboardInterrupt
except py_compile.PyCompileError as err:
if quiet:
print('*** Error compiling', fullname, '...')
diff --git a/Lib/ctypes/test/test_internals.py b/Lib/ctypes/test/test_internals.py
index 03d820e..1c7e4a8 100644
--- a/Lib/ctypes/test/test_internals.py
+++ b/Lib/ctypes/test/test_internals.py
@@ -23,16 +23,16 @@ class ObjectsTestCase(unittest.TestCase):
def test_ints(self):
i = 42000123
- rc = grc(i)
+ refcnt = grc(i)
ci = c_int(i)
- self.assertEqual(rc, grc(i))
+ self.assertEqual(refcnt, grc(i))
self.assertEqual(ci._objects, None)
def test_c_char_p(self):
s = b"Hello, World"
- rc = grc(s)
+ refcnt = grc(s)
cs = c_char_p(s)
- self.assertEqual(rc + 1, grc(s))
+ self.assertEqual(refcnt + 1, grc(s))
self.assertSame(cs._objects, s)
def test_simple_struct(self):
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 3d7ff82..d9cd143 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -1555,7 +1555,7 @@ def log(level, msg, *args, **kwargs):
def disable(level):
"""
- Disable all logging calls less severe than 'level'.
+ Disable all logging calls of severity 'level' and below.
"""
root.manager.disable = level
diff --git a/Lib/test/test_importhooks.py b/Lib/test/test_importhooks.py
index 1da30b7..ec6730e 100644
--- a/Lib/test/test_importhooks.py
+++ b/Lib/test/test_importhooks.py
@@ -221,15 +221,9 @@ class ImportHooksTestCase(ImportHooksBaseTestCase):
def testBlocker(self):
mname = "exceptions" # an arbitrary harmless builtin module
- if mname in sys.modules:
- del sys.modules[mname]
+ support.unload(mname)
sys.meta_path.append(ImportBlocker(mname))
- try:
- __import__(mname)
- except ImportError:
- pass
- else:
- self.fail("'%s' was not supposed to be importable" % mname)
+ self.assertRaises(ImportError, __import__, mname)
def testImpWrapper(self):
i = ImpWrapper()
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index 89a2583..ff04ef8 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -68,7 +68,7 @@ class UstarReadTest(ReadTest):
"fileobj.readlines() failed")
self.assertTrue(len(lines2) == 114,
"fileobj.readlines() failed")
- self.assertTrue(lines2[83] == \
+ self.assertTrue(lines2[83] ==
"I will gladly admit that Python is not the fastest running scripting language.\n",
"fileobj.readlines() failed")
@@ -706,11 +706,12 @@ class WriteTest(WriteTestBase):
name = os.path.join(tempdir, name)
open(name, "wb").close()
- def exclude(name):
- return os.path.isfile(name)
+ exclude = os.path.isfile
tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1")
- tar.add(tempdir, arcname="empty_dir", exclude=exclude)
+ with support.check_warnings(("use the filter argument",
+ DeprecationWarning)):
+ tar.add(tempdir, arcname="empty_dir", exclude=exclude)
tar.close()
tar = tarfile.open(tmpname, "r")
@@ -888,10 +889,12 @@ class GNUWriteTest(unittest.TestCase):
tar = tarfile.open(tmpname)
member = tar.next()
- self.assertFalse(member is None, "unable to read longname member")
- self.assertTrue(tarinfo.name == member.name and \
- tarinfo.linkname == member.linkname, \
- "unable to read longname member")
+ self.assertIsNotNone(member,
+ "unable to read longname member")
+ self.assertEqual(tarinfo.name, member.name,
+ "unable to read longname member")
+ self.assertEqual(tarinfo.linkname, member.linkname,
+ "unable to read longname member")
def test_longname_1023(self):
self._test(("longnam/" * 127) + "longnam")
@@ -993,7 +996,7 @@ class PaxWriteTest(GNUWriteTest):
"test": "\xe4\xf6\xfc",
"\xe4\xf6\xfc": "test"}
- tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT, \
+ tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT,
pax_headers=pax_headers)
tar.addfile(tarfile.TarInfo("test"))
tar.close()
diff --git a/Lib/test/test_unittest.py b/Lib/test/test_unittest.py
index f24a929..b4716a4 100644
--- a/Lib/test/test_unittest.py
+++ b/Lib/test/test_unittest.py
@@ -291,6 +291,21 @@ class Test_TestLoader(TestCase):
suite = loader.loadTestsFromModule(m, use_load_tests=False)
self.assertEquals(load_tests_args, [])
+ def test_loadTestsFromModule__faulty_load_tests(self):
+ m = types.ModuleType('m')
+
+ def load_tests(loader, tests, pattern):
+ raise TypeError('some failure')
+ m.load_tests = load_tests
+
+ loader = unittest.TestLoader()
+ suite = loader.loadTestsFromModule(m)
+ self.assertIsInstance(suite, unittest.TestSuite)
+ self.assertEqual(suite.countTestCases(), 1)
+ test = list(suite)[0]
+
+ self.assertRaisesRegexp(TypeError, "some failure", test.m)
+
################################################################
### /Tests for TestLoader.loadTestsFromModule()
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index 3051540..f1990d1 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -597,8 +597,8 @@ def parsefile():
</ns0:root>
>>> parser = ET.XMLParser()
- >>> parser.version # XXX: Upgrade to 2.0.1?
- 'Expat 2.0.0'
+ >>> parser.version # doctest: +ELLIPSIS
+ 'Expat ...'
>>> parser.feed(open(SIMPLE_XMLFILE).read())
>>> print(serialize(parser.close()))
<root>
diff --git a/Lib/unittest/loader.py b/Lib/unittest/loader.py
index bfee3dc..4e9e152 100644
--- a/Lib/unittest/loader.py
+++ b/Lib/unittest/loader.py
@@ -23,12 +23,18 @@ def _make_failed_import_test(name, suiteClass):
# Python 2.3 compatibility
# format_exc returns two frames of discover.py as well
message += '\n%s' % traceback.format_exc()
+ return _make_failed_test('ModuleImportFailure', name, ImportError(message),
+ suiteClass)
- def testImportFailure(self):
- raise ImportError(message)
- attrs = {name: testImportFailure}
- ModuleImportFailure = type('ModuleImportFailure', (case.TestCase,), attrs)
- return suiteClass((ModuleImportFailure(name),))
+def _make_failed_load_tests(name, exception, suiteClass):
+ return _make_failed_test('LoadTestsFailure', name, exception, suiteClass)
+
+def _make_failed_test(classname, methodname, exception, suiteClass):
+ def testFailure(self):
+ raise exception
+ attrs = {methodname: testFailure}
+ TestClass = type(classname, (case.TestCase,), attrs)
+ return suiteClass((TestClass(methodname),))
class TestLoader(object):
@@ -63,7 +69,11 @@ class TestLoader(object):
load_tests = getattr(module, 'load_tests', None)
tests = self.suiteClass(tests)
if use_load_tests and load_tests is not None:
- return load_tests(self, tests, None)
+ try:
+ return load_tests(self, tests, None)
+ except Exception as e:
+ return _make_failed_load_tests(module.__name__, e,
+ self.suiteClass)
return tests
def loadTestsFromName(self, name, module=None):
@@ -234,7 +244,11 @@ class TestLoader(object):
for test in self._find_tests(full_path, pattern):
yield test
else:
- yield load_tests(self, tests, pattern)
+ try:
+ yield load_tests(self, tests, pattern)
+ except Exception as e:
+ yield _make_failed_load_tests(package.__name__, e,
+ self.suiteClass)
defaultTestLoader = TestLoader()
diff --git a/Makefile.pre.in b/Makefile.pre.in
index ea22f12..380f914 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -836,7 +836,7 @@ EXTRAPLATDIR= @EXTRAPLATDIR@
MACHDEPS= $(PLATDIR) $(EXTRAPLATDIR)
XMLLIBSUBDIRS= xml xml/dom xml/etree xml/parsers xml/sax
LIBSUBDIRS= tkinter tkinter/test tkinter/test/test_tkinter \
- tkinter/test/test_ttk site-packages test test/data \
+ tkinter/test/test_ttk site-packages test \
test/decimaltestdata test/xmltestdata \
encodings \
email email/mime email/test email/test/data \
diff --git a/Misc/Porting b/Misc/Porting
index ec9cf1f..51f73e6 100644
--- a/Misc/Porting
+++ b/Misc/Porting
@@ -31,7 +31,7 @@ target platform. Forget about the posix module for now -- simply take
it out of the config.c file.
Bang on it until you get a >>> prompt. (You may have to disable the
-importing of "site.py" by passing the -S options.)
+importing of "site.py" by passing the -S option.)
Then bang on it until it executes very simple Python statements.