[Python-checkins] r79610 - in python/branches/py3k: Doc/whatsnew/2.7.rst Lib/platform.py Lib/test/test___all__.py Lib/test/test_argparse.py Lib/test/test_complex.py Lib/test/test_contextlib.py Lib/test/test_descr.py Lib/test/test_doctest.py Lib/test/test_global.py Lib/test/test_hmac.py Lib/test/test_io.py Lib/test/test_robotparser.py Lib/test/test_sundry.py Lib/test/test_xml_etree.py
florent.xicluna
python-checkins at python.org
Fri Apr 2 20:52:12 CEST 2010
Author: florent.xicluna
Date: Fri Apr 2 20:52:12 2010
New Revision: 79610
Log:
(partially)
Merged revisions 79534,79537,79539,79558,79606 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r79534 | florent.xicluna | 2010-03-31 23:21:54 +0200 (mer, 31 mar 2010) | 2 lines
Fix test for xml.etree when using a non-ascii path. And use check_warnings instead of catch_warnings.
........
r79537 | florent.xicluna | 2010-03-31 23:40:32 +0200 (mer, 31 mar 2010) | 2 lines
Fix typo
........
r79539 | florent.xicluna | 2010-04-01 00:01:03 +0200 (jeu, 01 avr 2010) | 2 lines
Replace catch_warnings with check_warnings when it makes sense. Use assertRaises context manager to simplify some tests.
........
r79558 | florent.xicluna | 2010-04-01 20:17:09 +0200 (jeu, 01 avr 2010) | 2 lines
#7092: Fix some -3 warnings, and fix Lib/platform.py when the path contains a double-quote.
........
r79606 | florent.xicluna | 2010-04-02 19:26:42 +0200 (ven, 02 avr 2010) | 2 lines
Backport some robotparser test and skip the test if the external resource is not available.
........
Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Doc/whatsnew/2.7.rst
python/branches/py3k/Lib/platform.py
python/branches/py3k/Lib/test/test___all__.py
python/branches/py3k/Lib/test/test_argparse.py
python/branches/py3k/Lib/test/test_complex.py
python/branches/py3k/Lib/test/test_contextlib.py
python/branches/py3k/Lib/test/test_descr.py
python/branches/py3k/Lib/test/test_doctest.py
python/branches/py3k/Lib/test/test_global.py
python/branches/py3k/Lib/test/test_hmac.py
python/branches/py3k/Lib/test/test_io.py
python/branches/py3k/Lib/test/test_robotparser.py
python/branches/py3k/Lib/test/test_sundry.py
python/branches/py3k/Lib/test/test_xml_etree.py
Modified: python/branches/py3k/Doc/whatsnew/2.7.rst
==============================================================================
--- python/branches/py3k/Doc/whatsnew/2.7.rst (original)
+++ python/branches/py3k/Doc/whatsnew/2.7.rst Fri Apr 2 20:52:12 2010
@@ -836,7 +836,7 @@
The :mod:`site` module now reports exceptions occurring
when the :mod:`sitecustomize` module is imported, and will no longer
- catch and swallow the :exc:`KeyboardError` exception. (Fixed by
+ catch and swallow the :exc:`KeyboardInterrupt` exception. (Fixed by
Victor Stinner; :issue:`3137`.)
* The :mod:`socket` module's :class:`SSL` objects now support the
Modified: python/branches/py3k/Lib/platform.py
==============================================================================
--- python/branches/py3k/Lib/platform.py (original)
+++ python/branches/py3k/Lib/platform.py Fri Apr 2 20:52:12 2010
@@ -942,7 +942,7 @@
if sys.platform in ('dos','win32','win16','os2'):
# XXX Others too ?
return default
- target = _follow_symlinks(target)
+ target = _follow_symlinks(target).replace('"', '\\"')
try:
f = os.popen('file "%s" 2> %s' % (target, DEV_NULL))
except (AttributeError,os.error):
Modified: python/branches/py3k/Lib/test/test___all__.py
==============================================================================
--- python/branches/py3k/Lib/test/test___all__.py (original)
+++ python/branches/py3k/Lib/test/test___all__.py Fri Apr 2 20:52:12 2010
@@ -2,7 +2,6 @@
from test import support
import os
import sys
-import warnings
class NoAll(RuntimeError):
@@ -16,9 +15,8 @@
def check_all(self, modname):
names = {}
- with warnings.catch_warnings():
- warnings.filterwarnings("ignore", ".* (module|package)",
- DeprecationWarning)
+ with support.check_warnings((".* (module|package)",
+ DeprecationWarning), quiet=True):
try:
exec("import %s" % modname, names)
except:
Modified: python/branches/py3k/Lib/test/test_argparse.py
==============================================================================
--- python/branches/py3k/Lib/test/test_argparse.py (original)
+++ python/branches/py3k/Lib/test/test_argparse.py Fri Apr 2 20:52:12 2010
@@ -7,7 +7,6 @@
import textwrap
import tempfile
import unittest
-import warnings
import argparse
from io import StringIO
@@ -4150,21 +4149,12 @@
self.assertTrue(hasattr(argparse, name))
def test_main():
- with warnings.catch_warnings():
- # silence warnings about version argument - these are expected
- warnings.filterwarnings(
- action='ignore',
- message='The "version" argument to ArgumentParser is deprecated.',
- category=DeprecationWarning)
- warnings.filterwarnings(
- action='ignore',
- message='The format_version method is deprecated',
- category=DeprecationWarning)
- warnings.filterwarnings(
- action='ignore',
- message='The print_version method is deprecated',
- category=DeprecationWarning)
-
+ # silence warnings about version argument - these are expected
+ with support.check_warnings(
+ ('The "version" argument to ArgumentParser is deprecated.',
+ DeprecationWarning),
+ ('The (format|print)_version method is deprecated',
+ DeprecationWarning)):
support.run_unittest(__name__)
# Remove global references to avoid looking like we have refleaks.
RFile.seen = {}
Modified: python/branches/py3k/Lib/test/test_complex.py
==============================================================================
--- python/branches/py3k/Lib/test/test_complex.py (original)
+++ python/branches/py3k/Lib/test/test_complex.py Fri Apr 2 20:52:12 2010
@@ -1,4 +1,4 @@
-import unittest, os
+import unittest
from test import support
from random import random
@@ -395,10 +395,7 @@
finally:
if (fo is not None) and (not fo.closed):
fo.close()
- try:
- os.remove(support.TESTFN)
- except (OSError, IOError):
- pass
+ support.unlink(support.TESTFN)
def test_getnewargs(self):
self.assertEqual((1+2j).__getnewargs__(), (1.0, 2.0))
Modified: python/branches/py3k/Lib/test/test_contextlib.py
==============================================================================
--- python/branches/py3k/Lib/test/test_contextlib.py (original)
+++ python/branches/py3k/Lib/test/test_contextlib.py Fri Apr 2 20:52:12 2010
@@ -1,7 +1,5 @@
"""Unit tests for contextlib.py, and other context managers."""
-
-import os
import sys
import tempfile
import unittest
@@ -9,6 +7,7 @@
from contextlib import * # Tests __all__
from test import support
+
class ContextManagerTestCase(unittest.TestCase):
def test_contextmanager_plain(self):
@@ -33,16 +32,12 @@
yield 42
finally:
state.append(999)
- try:
+ with self.assertRaises(ZeroDivisionError):
with woohoo() as x:
self.assertEqual(state, [1])
self.assertEqual(x, 42)
state.append(x)
raise ZeroDivisionError()
- except ZeroDivisionError:
- pass
- else:
- self.fail("Expected ZeroDivisionError")
self.assertEqual(state, [1, 42, 999])
def test_contextmanager_no_reraise(self):
@@ -130,14 +125,11 @@
state.append(1)
x = C()
self.assertEqual(state, [])
- try:
+ with self.assertRaises(ZeroDivisionError):
with closing(x) as y:
self.assertEqual(x, y)
- 1/0
- except ZeroDivisionError:
- self.assertEqual(state, [1])
- else:
- self.fail("Didn't raise ZeroDivisionError")
+ 1 / 0
+ self.assertEqual(state, [1])
class FileContextTestCase(unittest.TestCase):
@@ -150,20 +142,14 @@
f.write("Booh\n")
self.assertTrue(f.closed)
f = None
- try:
+ with self.assertRaises(ZeroDivisionError):
with open(tfn, "r") as f:
self.assertFalse(f.closed)
self.assertEqual(f.read(), "Booh\n")
- 1/0
- except ZeroDivisionError:
- self.assertTrue(f.closed)
- else:
- self.fail("Didn't raise ZeroDivisionError")
+ 1 / 0
+ self.assertTrue(f.closed)
finally:
- try:
- os.remove(tfn)
- except os.error:
- pass
+ support.unlink(tfn)
class LockContextTestCase(unittest.TestCase):
@@ -172,14 +158,11 @@
with lock:
self.assertTrue(locked())
self.assertFalse(locked())
- try:
+ with self.assertRaises(ZeroDivisionError):
with lock:
self.assertTrue(locked())
- 1/0
- except ZeroDivisionError:
- self.assertFalse(locked())
- else:
- self.fail("Didn't raise ZeroDivisionError")
+ 1 / 0
+ self.assertFalse(locked())
def testWithLock(self):
lock = threading.Lock()
Modified: python/branches/py3k/Lib/test/test_descr.py
==============================================================================
--- python/branches/py3k/Lib/test/test_descr.py (original)
+++ python/branches/py3k/Lib/test/test_descr.py Fri Apr 2 20:52:12 2010
@@ -2,7 +2,6 @@
import sys
import types
import unittest
-import warnings
from copy import deepcopy
from test import support
Modified: python/branches/py3k/Lib/test/test_doctest.py
==============================================================================
--- python/branches/py3k/Lib/test/test_doctest.py (original)
+++ python/branches/py3k/Lib/test/test_doctest.py Fri Apr 2 20:52:12 2010
@@ -4,7 +4,6 @@
from test import support
import doctest
-import warnings
# NOTE: There are some additional tests relating to interaction with
# zipimport in the test_zipimport_support test module.
Modified: python/branches/py3k/Lib/test/test_global.py
==============================================================================
--- python/branches/py3k/Lib/test/test_global.py (original)
+++ python/branches/py3k/Lib/test/test_global.py Fri Apr 2 20:52:12 2010
@@ -2,7 +2,6 @@
from test.support import run_unittest, check_syntax_error, check_warnings
import unittest
-
import warnings
@@ -54,7 +53,9 @@
def test_main():
- run_unittest(GlobalTests)
+ with warnings.catch_warnings():
+ warnings.filterwarnings("error", module="<test string>")
+ run_unittest(GlobalTests)
if __name__ == "__main__":
test_main()
Modified: python/branches/py3k/Lib/test/test_hmac.py
==============================================================================
--- python/branches/py3k/Lib/test/test_hmac.py (original)
+++ python/branches/py3k/Lib/test/test_hmac.py Fri Apr 2 20:52:12 2010
@@ -213,19 +213,13 @@
with warnings.catch_warnings():
warnings.simplefilter('error', RuntimeWarning)
- try:
+ with self.assertRaises(RuntimeWarning):
hmac.HMAC(b'a', b'b', digestmod=MockCrazyHash)
- except RuntimeWarning:
- pass
- else:
self.fail('Expected warning about missing block_size')
MockCrazyHash.block_size = 1
- try:
+ with self.assertRaises(RuntimeWarning):
hmac.HMAC(b'a', b'b', digestmod=MockCrazyHash)
- except RuntimeWarning:
- pass
- else:
self.fail('Expected warning about small block_size')
Modified: python/branches/py3k/Lib/test/test_io.py
==============================================================================
--- python/branches/py3k/Lib/test/test_io.py (original)
+++ python/branches/py3k/Lib/test/test_io.py Fri Apr 2 20:52:12 2010
@@ -26,7 +26,6 @@
import threading
import random
import unittest
-import warnings
import weakref
import abc
from itertools import cycle, count
Modified: python/branches/py3k/Lib/test/test_robotparser.py
==============================================================================
--- python/branches/py3k/Lib/test/test_robotparser.py (original)
+++ python/branches/py3k/Lib/test/test_robotparser.py Fri Apr 2 20:52:12 2010
@@ -209,21 +209,19 @@
class NetworkTestCase(unittest.TestCase):
def testPasswordProtectedSite(self):
- if not support.is_resource_enabled('network'):
- return
- # whole site is password-protected.
+ support.requires('network')
+ # XXX it depends on an external resource which could be unavailable
url = 'http://mueblesmoraleda.com'
parser = urllib.robotparser.RobotFileParser()
parser.set_url(url)
try:
parser.read()
- self.assertEqual(parser.can_fetch("*", url+"/robots.txt"), False)
except URLError:
- self.skipTest('mueblesmoraleda.com is unavailable')
+ self.skipTest('%s is unavailable' % url)
+ self.assertEqual(parser.can_fetch("*", url+"/robots.txt"), False)
def testPythonOrg(self):
- if not support.is_resource_enabled('network'):
- return
+ support.requires('network')
parser = urllib.robotparser.RobotFileParser(
"http://www.python.org/robots.txt")
parser.read()
Modified: python/branches/py3k/Lib/test/test_sundry.py
==============================================================================
--- python/branches/py3k/Lib/test/test_sundry.py (original)
+++ python/branches/py3k/Lib/test/test_sundry.py Fri Apr 2 20:52:12 2010
@@ -3,12 +3,10 @@
from test import support
import sys
import unittest
-import warnings
class TestUntestedModules(unittest.TestCase):
def test_at_least_import_untested_modules(self):
- with warnings.catch_warnings():
- warnings.simplefilter("ignore")
+ with support.check_warnings(quiet=True):
import bdb
import cgitb
import code
Modified: python/branches/py3k/Lib/test/test_xml_etree.py
==============================================================================
--- python/branches/py3k/Lib/test/test_xml_etree.py (original)
+++ python/branches/py3k/Lib/test/test_xml_etree.py Fri Apr 2 20:52:12 2010
@@ -12,6 +12,7 @@
# except if the test is specific to the Python implementation.
import sys
+import cgi
from test import support
from test.support import findfile
@@ -1305,7 +1306,7 @@
<p>Example.</p>
<xi:include href="{}"/>
</document>
-""".format(SIMPLE_XMLFILE)
+""".format(cgi.escape(SIMPLE_XMLFILE, True))
def xinclude_loader(href, parse="xml", encoding=None):
try:
@@ -1808,6 +1809,23 @@
class CleanContext(object):
"""Provide default namespace mapping and path cache."""
+ checkwarnings = None
+
+ def __init__(self, quiet=False):
+ deprecations = (
+ # Search behaviour is broken if search path starts with "/".
+ ("This search is broken in 1.3 and earlier, and will be fixed "
+ "in a future version. If you rely on the current behaviour, "
+ "change it to '.+'", FutureWarning),
+ # Element.getchildren() and Element.getiterator() are deprecated.
+ ("This method will be removed in future versions. "
+ "Use .+ instead.", DeprecationWarning),
+ ("This method will be removed in future versions. "
+ "Use .+ instead.", PendingDeprecationWarning),
+ # XMLParser.doctype() is deprecated.
+ ("This method of XMLParser is deprecated. Define doctype.. "
+ "method on the TreeBuilder target.", DeprecationWarning))
+ self.checkwarnings = support.check_warnings(*deprecations, quiet=quiet)
def __enter__(self):
from xml.etree import ElementTree
@@ -1817,35 +1835,26 @@
ElementTree._namespace_map = self._nsmap.copy()
# Copy the path cache (should be empty)
ElementTree.ElementPath._cache = self._path_cache.copy()
+ self.checkwarnings.__enter__()
def __exit__(self, *args):
from xml.etree import ElementTree
# Restore mapping and path cache
ElementTree._namespace_map = self._nsmap
ElementTree.ElementPath._cache = self._path_cache
+ self.checkwarnings.__exit__(*args)
def test_main(module_name='xml.etree.ElementTree'):
- import warnings
from test import test_xml_etree
- def ignore(message, category=DeprecationWarning):
- warnings.filterwarnings("ignore", message, category)
+
+ use_py_module = (module_name == 'xml.etree.ElementTree')
# The same doctests are used for both the Python and the C implementations
assert test_xml_etree.ET.__name__ == module_name
- with warnings.catch_warnings(), CleanContext():
- # Search behaviour is broken if search path starts with "/".
- ignore("This search is broken in 1.3 and earlier, and will be fixed "
- "in a future version. If you rely on the current behaviour, "
- "change it to '.+'", FutureWarning)
- # Element.getchildren() and Element.getiterator() are deprecated.
- ignore("This method will be removed in future versions. "
- "Use .+ instead.")
- # XMLParser.doctype() is deprecated.
- ignore("This method of XMLParser is deprecated. "
- "Define doctype.. method on the TreeBuilder target.")
-
+ # XXX the C module should give the same warnings as the Python module
+ with CleanContext(quiet=not use_py_module):
support.run_doctest(test_xml_etree, verbosity=True)
# The module should not be changed by the tests
More information about the Python-checkins
mailing list