mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
(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. ........
This commit is contained in:
parent
1bfd0cc5d4
commit
41fe615539
14 changed files with 60 additions and 95 deletions
|
@ -836,7 +836,7 @@ changes, or look through the Subversion logs for all the details.
|
||||||
|
|
||||||
The :mod:`site` module now reports exceptions occurring
|
The :mod:`site` module now reports exceptions occurring
|
||||||
when the :mod:`sitecustomize` module is imported, and will no longer
|
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`.)
|
Victor Stinner; :issue:`3137`.)
|
||||||
|
|
||||||
* The :mod:`socket` module's :class:`SSL` objects now support the
|
* The :mod:`socket` module's :class:`SSL` objects now support the
|
||||||
|
|
|
@ -942,7 +942,7 @@ def _syscmd_file(target,default=''):
|
||||||
if sys.platform in ('dos','win32','win16','os2'):
|
if sys.platform in ('dos','win32','win16','os2'):
|
||||||
# XXX Others too ?
|
# XXX Others too ?
|
||||||
return default
|
return default
|
||||||
target = _follow_symlinks(target)
|
target = _follow_symlinks(target).replace('"', '\\"')
|
||||||
try:
|
try:
|
||||||
f = os.popen('file "%s" 2> %s' % (target, DEV_NULL))
|
f = os.popen('file "%s" 2> %s' % (target, DEV_NULL))
|
||||||
except (AttributeError,os.error):
|
except (AttributeError,os.error):
|
||||||
|
|
|
@ -2,7 +2,6 @@ import unittest
|
||||||
from test import support
|
from test import support
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
|
||||||
|
|
||||||
|
|
||||||
class NoAll(RuntimeError):
|
class NoAll(RuntimeError):
|
||||||
|
@ -16,9 +15,8 @@ class AllTest(unittest.TestCase):
|
||||||
|
|
||||||
def check_all(self, modname):
|
def check_all(self, modname):
|
||||||
names = {}
|
names = {}
|
||||||
with warnings.catch_warnings():
|
with support.check_warnings((".* (module|package)",
|
||||||
warnings.filterwarnings("ignore", ".* (module|package)",
|
DeprecationWarning), quiet=True):
|
||||||
DeprecationWarning)
|
|
||||||
try:
|
try:
|
||||||
exec("import %s" % modname, names)
|
exec("import %s" % modname, names)
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -7,7 +7,6 @@ import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
import warnings
|
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
@ -4150,21 +4149,12 @@ class TestImportStar(TestCase):
|
||||||
self.assertTrue(hasattr(argparse, name))
|
self.assertTrue(hasattr(argparse, name))
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
with warnings.catch_warnings():
|
# silence warnings about version argument - these are expected
|
||||||
# silence warnings about version argument - these are expected
|
with support.check_warnings(
|
||||||
warnings.filterwarnings(
|
('The "version" argument to ArgumentParser is deprecated.',
|
||||||
action='ignore',
|
DeprecationWarning),
|
||||||
message='The "version" argument to ArgumentParser is deprecated.',
|
('The (format|print)_version method is deprecated',
|
||||||
category=DeprecationWarning)
|
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)
|
|
||||||
|
|
||||||
support.run_unittest(__name__)
|
support.run_unittest(__name__)
|
||||||
# Remove global references to avoid looking like we have refleaks.
|
# Remove global references to avoid looking like we have refleaks.
|
||||||
RFile.seen = {}
|
RFile.seen = {}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import unittest, os
|
import unittest
|
||||||
from test import support
|
from test import support
|
||||||
|
|
||||||
from random import random
|
from random import random
|
||||||
|
@ -395,10 +395,7 @@ class ComplexTest(unittest.TestCase):
|
||||||
finally:
|
finally:
|
||||||
if (fo is not None) and (not fo.closed):
|
if (fo is not None) and (not fo.closed):
|
||||||
fo.close()
|
fo.close()
|
||||||
try:
|
support.unlink(support.TESTFN)
|
||||||
os.remove(support.TESTFN)
|
|
||||||
except (OSError, IOError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_getnewargs(self):
|
def test_getnewargs(self):
|
||||||
self.assertEqual((1+2j).__getnewargs__(), (1.0, 2.0))
|
self.assertEqual((1+2j).__getnewargs__(), (1.0, 2.0))
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
"""Unit tests for contextlib.py, and other context managers."""
|
"""Unit tests for contextlib.py, and other context managers."""
|
||||||
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -9,6 +7,7 @@ import threading
|
||||||
from contextlib import * # Tests __all__
|
from contextlib import * # Tests __all__
|
||||||
from test import support
|
from test import support
|
||||||
|
|
||||||
|
|
||||||
class ContextManagerTestCase(unittest.TestCase):
|
class ContextManagerTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_contextmanager_plain(self):
|
def test_contextmanager_plain(self):
|
||||||
|
@ -33,16 +32,12 @@ class ContextManagerTestCase(unittest.TestCase):
|
||||||
yield 42
|
yield 42
|
||||||
finally:
|
finally:
|
||||||
state.append(999)
|
state.append(999)
|
||||||
try:
|
with self.assertRaises(ZeroDivisionError):
|
||||||
with woohoo() as x:
|
with woohoo() as x:
|
||||||
self.assertEqual(state, [1])
|
self.assertEqual(state, [1])
|
||||||
self.assertEqual(x, 42)
|
self.assertEqual(x, 42)
|
||||||
state.append(x)
|
state.append(x)
|
||||||
raise ZeroDivisionError()
|
raise ZeroDivisionError()
|
||||||
except ZeroDivisionError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
self.fail("Expected ZeroDivisionError")
|
|
||||||
self.assertEqual(state, [1, 42, 999])
|
self.assertEqual(state, [1, 42, 999])
|
||||||
|
|
||||||
def test_contextmanager_no_reraise(self):
|
def test_contextmanager_no_reraise(self):
|
||||||
|
@ -130,14 +125,11 @@ class ClosingTestCase(unittest.TestCase):
|
||||||
state.append(1)
|
state.append(1)
|
||||||
x = C()
|
x = C()
|
||||||
self.assertEqual(state, [])
|
self.assertEqual(state, [])
|
||||||
try:
|
with self.assertRaises(ZeroDivisionError):
|
||||||
with closing(x) as y:
|
with closing(x) as y:
|
||||||
self.assertEqual(x, y)
|
self.assertEqual(x, y)
|
||||||
1/0
|
1 / 0
|
||||||
except ZeroDivisionError:
|
self.assertEqual(state, [1])
|
||||||
self.assertEqual(state, [1])
|
|
||||||
else:
|
|
||||||
self.fail("Didn't raise ZeroDivisionError")
|
|
||||||
|
|
||||||
class FileContextTestCase(unittest.TestCase):
|
class FileContextTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
@ -150,20 +142,14 @@ class FileContextTestCase(unittest.TestCase):
|
||||||
f.write("Booh\n")
|
f.write("Booh\n")
|
||||||
self.assertTrue(f.closed)
|
self.assertTrue(f.closed)
|
||||||
f = None
|
f = None
|
||||||
try:
|
with self.assertRaises(ZeroDivisionError):
|
||||||
with open(tfn, "r") as f:
|
with open(tfn, "r") as f:
|
||||||
self.assertFalse(f.closed)
|
self.assertFalse(f.closed)
|
||||||
self.assertEqual(f.read(), "Booh\n")
|
self.assertEqual(f.read(), "Booh\n")
|
||||||
1/0
|
1 / 0
|
||||||
except ZeroDivisionError:
|
self.assertTrue(f.closed)
|
||||||
self.assertTrue(f.closed)
|
|
||||||
else:
|
|
||||||
self.fail("Didn't raise ZeroDivisionError")
|
|
||||||
finally:
|
finally:
|
||||||
try:
|
support.unlink(tfn)
|
||||||
os.remove(tfn)
|
|
||||||
except os.error:
|
|
||||||
pass
|
|
||||||
|
|
||||||
class LockContextTestCase(unittest.TestCase):
|
class LockContextTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
@ -172,14 +158,11 @@ class LockContextTestCase(unittest.TestCase):
|
||||||
with lock:
|
with lock:
|
||||||
self.assertTrue(locked())
|
self.assertTrue(locked())
|
||||||
self.assertFalse(locked())
|
self.assertFalse(locked())
|
||||||
try:
|
with self.assertRaises(ZeroDivisionError):
|
||||||
with lock:
|
with lock:
|
||||||
self.assertTrue(locked())
|
self.assertTrue(locked())
|
||||||
1/0
|
1 / 0
|
||||||
except ZeroDivisionError:
|
self.assertFalse(locked())
|
||||||
self.assertFalse(locked())
|
|
||||||
else:
|
|
||||||
self.fail("Didn't raise ZeroDivisionError")
|
|
||||||
|
|
||||||
def testWithLock(self):
|
def testWithLock(self):
|
||||||
lock = threading.Lock()
|
lock = threading.Lock()
|
||||||
|
|
|
@ -2,7 +2,6 @@ import builtins
|
||||||
import sys
|
import sys
|
||||||
import types
|
import types
|
||||||
import unittest
|
import unittest
|
||||||
import warnings
|
|
||||||
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from test import support
|
from test import support
|
||||||
|
|
|
@ -4,7 +4,6 @@ Test script for doctest.
|
||||||
|
|
||||||
from test import support
|
from test import support
|
||||||
import doctest
|
import doctest
|
||||||
import warnings
|
|
||||||
|
|
||||||
# NOTE: There are some additional tests relating to interaction with
|
# NOTE: There are some additional tests relating to interaction with
|
||||||
# zipimport in the test_zipimport_support test module.
|
# zipimport in the test_zipimport_support test module.
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
from test.support import run_unittest, check_syntax_error, check_warnings
|
from test.support import run_unittest, check_syntax_error, check_warnings
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,7 +53,9 @@ x = 2
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
run_unittest(GlobalTests)
|
with warnings.catch_warnings():
|
||||||
|
warnings.filterwarnings("error", module="<test string>")
|
||||||
|
run_unittest(GlobalTests)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main()
|
test_main()
|
||||||
|
|
|
@ -213,19 +213,13 @@ class TestVectorsTestCase(unittest.TestCase):
|
||||||
|
|
||||||
with warnings.catch_warnings():
|
with warnings.catch_warnings():
|
||||||
warnings.simplefilter('error', RuntimeWarning)
|
warnings.simplefilter('error', RuntimeWarning)
|
||||||
try:
|
with self.assertRaises(RuntimeWarning):
|
||||||
hmac.HMAC(b'a', b'b', digestmod=MockCrazyHash)
|
hmac.HMAC(b'a', b'b', digestmod=MockCrazyHash)
|
||||||
except RuntimeWarning:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
self.fail('Expected warning about missing block_size')
|
self.fail('Expected warning about missing block_size')
|
||||||
|
|
||||||
MockCrazyHash.block_size = 1
|
MockCrazyHash.block_size = 1
|
||||||
try:
|
with self.assertRaises(RuntimeWarning):
|
||||||
hmac.HMAC(b'a', b'b', digestmod=MockCrazyHash)
|
hmac.HMAC(b'a', b'b', digestmod=MockCrazyHash)
|
||||||
except RuntimeWarning:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
self.fail('Expected warning about small block_size')
|
self.fail('Expected warning about small block_size')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ import array
|
||||||
import threading
|
import threading
|
||||||
import random
|
import random
|
||||||
import unittest
|
import unittest
|
||||||
import warnings
|
|
||||||
import weakref
|
import weakref
|
||||||
import abc
|
import abc
|
||||||
from itertools import cycle, count
|
from itertools import cycle, count
|
||||||
|
|
|
@ -209,21 +209,19 @@ RobotTest(13, doc, good, bad, agent="googlebot")
|
||||||
class NetworkTestCase(unittest.TestCase):
|
class NetworkTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def testPasswordProtectedSite(self):
|
def testPasswordProtectedSite(self):
|
||||||
if not support.is_resource_enabled('network'):
|
support.requires('network')
|
||||||
return
|
# XXX it depends on an external resource which could be unavailable
|
||||||
# whole site is password-protected.
|
|
||||||
url = 'http://mueblesmoraleda.com'
|
url = 'http://mueblesmoraleda.com'
|
||||||
parser = urllib.robotparser.RobotFileParser()
|
parser = urllib.robotparser.RobotFileParser()
|
||||||
parser.set_url(url)
|
parser.set_url(url)
|
||||||
try:
|
try:
|
||||||
parser.read()
|
parser.read()
|
||||||
self.assertEqual(parser.can_fetch("*", url+"/robots.txt"), False)
|
|
||||||
except URLError:
|
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):
|
def testPythonOrg(self):
|
||||||
if not support.is_resource_enabled('network'):
|
support.requires('network')
|
||||||
return
|
|
||||||
parser = urllib.robotparser.RobotFileParser(
|
parser = urllib.robotparser.RobotFileParser(
|
||||||
"http://www.python.org/robots.txt")
|
"http://www.python.org/robots.txt")
|
||||||
parser.read()
|
parser.read()
|
||||||
|
|
|
@ -3,12 +3,10 @@
|
||||||
from test import support
|
from test import support
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
import warnings
|
|
||||||
|
|
||||||
class TestUntestedModules(unittest.TestCase):
|
class TestUntestedModules(unittest.TestCase):
|
||||||
def test_at_least_import_untested_modules(self):
|
def test_at_least_import_untested_modules(self):
|
||||||
with warnings.catch_warnings():
|
with support.check_warnings(quiet=True):
|
||||||
warnings.simplefilter("ignore")
|
|
||||||
import bdb
|
import bdb
|
||||||
import cgitb
|
import cgitb
|
||||||
import code
|
import code
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
# except if the test is specific to the Python implementation.
|
# except if the test is specific to the Python implementation.
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import cgi
|
||||||
|
|
||||||
from test import support
|
from test import support
|
||||||
from test.support import findfile
|
from test.support import findfile
|
||||||
|
@ -1305,7 +1306,7 @@ XINCLUDE["default.xml"] = """\
|
||||||
<p>Example.</p>
|
<p>Example.</p>
|
||||||
<xi:include href="{}"/>
|
<xi:include href="{}"/>
|
||||||
</document>
|
</document>
|
||||||
""".format(SIMPLE_XMLFILE)
|
""".format(cgi.escape(SIMPLE_XMLFILE, True))
|
||||||
|
|
||||||
def xinclude_loader(href, parse="xml", encoding=None):
|
def xinclude_loader(href, parse="xml", encoding=None):
|
||||||
try:
|
try:
|
||||||
|
@ -1808,6 +1809,23 @@ def check_issue6565():
|
||||||
|
|
||||||
class CleanContext(object):
|
class CleanContext(object):
|
||||||
"""Provide default namespace mapping and path cache."""
|
"""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):
|
def __enter__(self):
|
||||||
from xml.etree import ElementTree
|
from xml.etree import ElementTree
|
||||||
|
@ -1817,35 +1835,26 @@ class CleanContext(object):
|
||||||
ElementTree._namespace_map = self._nsmap.copy()
|
ElementTree._namespace_map = self._nsmap.copy()
|
||||||
# Copy the path cache (should be empty)
|
# Copy the path cache (should be empty)
|
||||||
ElementTree.ElementPath._cache = self._path_cache.copy()
|
ElementTree.ElementPath._cache = self._path_cache.copy()
|
||||||
|
self.checkwarnings.__enter__()
|
||||||
|
|
||||||
def __exit__(self, *args):
|
def __exit__(self, *args):
|
||||||
from xml.etree import ElementTree
|
from xml.etree import ElementTree
|
||||||
# Restore mapping and path cache
|
# Restore mapping and path cache
|
||||||
ElementTree._namespace_map = self._nsmap
|
ElementTree._namespace_map = self._nsmap
|
||||||
ElementTree.ElementPath._cache = self._path_cache
|
ElementTree.ElementPath._cache = self._path_cache
|
||||||
|
self.checkwarnings.__exit__(*args)
|
||||||
|
|
||||||
|
|
||||||
def test_main(module_name='xml.etree.ElementTree'):
|
def test_main(module_name='xml.etree.ElementTree'):
|
||||||
import warnings
|
|
||||||
from test import test_xml_etree
|
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
|
# The same doctests are used for both the Python and the C implementations
|
||||||
assert test_xml_etree.ET.__name__ == module_name
|
assert test_xml_etree.ET.__name__ == module_name
|
||||||
|
|
||||||
with warnings.catch_warnings(), CleanContext():
|
# XXX the C module should give the same warnings as the Python module
|
||||||
# Search behaviour is broken if search path starts with "/".
|
with CleanContext(quiet=not use_py_module):
|
||||||
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.")
|
|
||||||
|
|
||||||
support.run_doctest(test_xml_etree, verbosity=True)
|
support.run_doctest(test_xml_etree, verbosity=True)
|
||||||
|
|
||||||
# The module should not be changed by the tests
|
# The module should not be changed by the tests
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue