Merged revisions 70554,70588-70589,70598,70605,70611-70621,70623-70624,70626-70627 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r70554 | benjamin.peterson | 2009-03-23 16:25:15 -0500 (Mon, 23 Mar 2009) | 1 line complain when there's no last exception ........ r70588 | benjamin.peterson | 2009-03-24 17:56:32 -0500 (Tue, 24 Mar 2009) | 1 line fix newline issue in test summary ........ r70589 | benjamin.peterson | 2009-03-24 18:07:07 -0500 (Tue, 24 Mar 2009) | 1 line another style nit ........ r70598 | benjamin.peterson | 2009-03-25 16:24:04 -0500 (Wed, 25 Mar 2009) | 1 line add shorthands for expected failures and unexpected success ........ r70605 | benjamin.peterson | 2009-03-26 11:32:23 -0500 (Thu, 26 Mar 2009) | 1 line remove uneeded function ........ r70611 | benjamin.peterson | 2009-03-26 13:35:37 -0500 (Thu, 26 Mar 2009) | 1 line add much better tests for python version information parsing ........ r70612 | benjamin.peterson | 2009-03-26 13:55:48 -0500 (Thu, 26 Mar 2009) | 1 line more and more implementations now support sys.subversion ........ r70613 | benjamin.peterson | 2009-03-26 13:58:30 -0500 (Thu, 26 Mar 2009) | 1 line roll old test in with new one ........ r70614 | benjamin.peterson | 2009-03-26 14:09:21 -0500 (Thu, 26 Mar 2009) | 1 line add support for PyPy ........ r70615 | benjamin.peterson | 2009-03-26 14:58:18 -0500 (Thu, 26 Mar 2009) | 5 lines add some useful utilities for skipping tests with unittest's new skipping ability most significantly apply a modified portion of the patch from #4242 with patches for skipping implementation details ........ r70616 | benjamin.peterson | 2009-03-26 15:05:50 -0500 (Thu, 26 Mar 2009) | 1 line rename TestCase.skip() to skipTest() because it causes annoying problems with trial #5571 ........ r70617 | benjamin.peterson | 2009-03-26 15:17:27 -0500 (Thu, 26 Mar 2009) | 1 line apply the second part of #4242's patch; classify all the implementation details in test_descr ........ r70618 | benjamin.peterson | 2009-03-26 15:48:25 -0500 (Thu, 26 Mar 2009) | 1 line remove test_support.TestSkipped and just use unittest.SkipTest ........ r70619 | benjamin.peterson | 2009-03-26 15:49:40 -0500 (Thu, 26 Mar 2009) | 1 line fix naming ........ r70620 | benjamin.peterson | 2009-03-26 16:10:30 -0500 (Thu, 26 Mar 2009) | 1 line fix incorrect auto-translation of TestSkipped -> unittest.SkipTest ........ r70621 | benjamin.peterson | 2009-03-26 16:11:16 -0500 (Thu, 26 Mar 2009) | 1 line must pass argument to get expected behavior ;) ........ r70623 | benjamin.peterson | 2009-03-26 16:30:10 -0500 (Thu, 26 Mar 2009) | 1 line add missing import ........ r70624 | benjamin.peterson | 2009-03-26 16:30:54 -0500 (Thu, 26 Mar 2009) | 1 line ** is required here ........ r70626 | benjamin.peterson | 2009-03-26 16:40:29 -0500 (Thu, 26 Mar 2009) | 1 line update email tests to use SkipTest ........ r70627 | benjamin.peterson | 2009-03-26 16:44:43 -0500 (Thu, 26 Mar 2009) | 1 line fix another name ........
This commit is contained in:
parent
b556452055
commit
e549ead826
|
@ -575,7 +575,7 @@ Test cases
|
||||||
instance.
|
instance.
|
||||||
|
|
||||||
|
|
||||||
.. method:: skip(reason)
|
.. method:: skipTest(reason)
|
||||||
|
|
||||||
Calling this during the a test method or :meth:`setUp` skips the current
|
Calling this during the a test method or :meth:`setUp` skips the current
|
||||||
test. See :ref:`unittest-skipping` for more information.
|
test. See :ref:`unittest-skipping` for more information.
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# email package unit tests for (optional) Asian codecs
|
# email package unit tests for (optional) Asian codecs
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from test.support import TestSkipped, run_unittest
|
from test.support import run_unittest
|
||||||
|
|
||||||
from email.test.test_email import TestEmailBase
|
from email.test.test_email import TestEmailBase
|
||||||
from email.Charset import Charset
|
from email.Charset import Charset
|
||||||
|
@ -15,7 +15,7 @@ from email.Message import Message
|
||||||
try:
|
try:
|
||||||
str('foo', 'euc-jp')
|
str('foo', 'euc-jp')
|
||||||
except LookupError:
|
except LookupError:
|
||||||
raise TestSkipped
|
raise unittest.SkipTest
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1240,15 +1240,17 @@ _sys_version_parser = re.compile(
|
||||||
'\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*'
|
'\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*'
|
||||||
'\[([^\]]+)\]?', re.ASCII)
|
'\[([^\]]+)\]?', re.ASCII)
|
||||||
|
|
||||||
_jython_sys_version_parser = re.compile(
|
|
||||||
r'([\d\.]+)', re.ASCII)
|
|
||||||
|
|
||||||
_ironpython_sys_version_parser = re.compile(
|
_ironpython_sys_version_parser = re.compile(
|
||||||
r'IronPython\s*'
|
r'IronPython\s*'
|
||||||
'([\d\.]+)'
|
'([\d\.]+)'
|
||||||
'(?: \(([\d\.]+)\))?'
|
'(?: \(([\d\.]+)\))?'
|
||||||
' on (.NET [\d\.]+)', re.ASCII)
|
' on (.NET [\d\.]+)', re.ASCII)
|
||||||
|
|
||||||
|
_pypy_sys_version_parser = re.compile(
|
||||||
|
r'([\w.+]+)\s*'
|
||||||
|
'\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*'
|
||||||
|
'\[PyPy [^\]]+\]?')
|
||||||
|
|
||||||
_sys_version_cache = {}
|
_sys_version_cache = {}
|
||||||
|
|
||||||
def _sys_version(sys_version=None):
|
def _sys_version(sys_version=None):
|
||||||
|
@ -1290,25 +1292,29 @@ def _sys_version(sys_version=None):
|
||||||
'failed to parse IronPython sys.version: %s' %
|
'failed to parse IronPython sys.version: %s' %
|
||||||
repr(sys_version))
|
repr(sys_version))
|
||||||
version, alt_version, compiler = match.groups()
|
version, alt_version, compiler = match.groups()
|
||||||
branch = ''
|
|
||||||
revision = ''
|
|
||||||
buildno = ''
|
buildno = ''
|
||||||
builddate = ''
|
builddate = ''
|
||||||
|
|
||||||
elif sys.platform[:4] == 'java':
|
elif sys.platform[:4] == 'java':
|
||||||
# Jython
|
# Jython
|
||||||
name = 'Jython'
|
name = 'Jython'
|
||||||
match = _jython_sys_version_parser.match(sys_version)
|
match = _sys_version_parser.match(sys_version)
|
||||||
if match is None:
|
if match is None:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
'failed to parse Jython sys.version: %s' %
|
'failed to parse Jython sys.version: %s' %
|
||||||
repr(sys_version))
|
repr(sys_version))
|
||||||
version, = match.groups()
|
version, buildno, builddate, buildtime, _ = match.groups()
|
||||||
branch = ''
|
|
||||||
revision = ''
|
|
||||||
compiler = sys.platform
|
compiler = sys.platform
|
||||||
buildno = ''
|
|
||||||
builddate = ''
|
elif "PyPy" in sys_version:
|
||||||
|
# PyPy
|
||||||
|
name = "PyPy"
|
||||||
|
match = _pypy_sys_version_parser.match(sys_version)
|
||||||
|
if match is None:
|
||||||
|
raise ValueError("failed to parse PyPy sys.version: %s" %
|
||||||
|
repr(sys_version))
|
||||||
|
version, buildno, builddate, buildtime = match.groups()
|
||||||
|
compiler = ""
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# CPython
|
# CPython
|
||||||
|
@ -1319,14 +1325,15 @@ def _sys_version(sys_version=None):
|
||||||
repr(sys_version))
|
repr(sys_version))
|
||||||
version, buildno, builddate, buildtime, compiler = \
|
version, buildno, builddate, buildtime, compiler = \
|
||||||
match.groups()
|
match.groups()
|
||||||
|
name = 'CPython'
|
||||||
|
builddate = builddate + ' ' + buildtime
|
||||||
|
|
||||||
if hasattr(sys, 'subversion'):
|
if hasattr(sys, 'subversion'):
|
||||||
# sys.subversion was added in Python 2.5
|
# sys.subversion was added in Python 2.5
|
||||||
name, branch, revision = sys.subversion
|
_, branch, revision = sys.subversion
|
||||||
else:
|
else:
|
||||||
name = 'CPython'
|
|
||||||
branch = ''
|
branch = ''
|
||||||
revision = ''
|
revision = ''
|
||||||
builddate = builddate + ' ' + buildtime
|
|
||||||
|
|
||||||
# Add the patchlevel version if missing
|
# Add the patchlevel version if missing
|
||||||
l = version.split('.')
|
l = version.split('.')
|
||||||
|
|
|
@ -139,6 +139,7 @@ import sys
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
import warnings
|
import warnings
|
||||||
|
import unittest
|
||||||
from inspect import isabstract
|
from inspect import isabstract
|
||||||
|
|
||||||
# I see no other way to suppress these warnings;
|
# I see no other way to suppress these warnings;
|
||||||
|
@ -614,7 +615,7 @@ def runtest_inner(test, generate, verbose, quiet, test_times,
|
||||||
print(test, "skipped --", msg)
|
print(test, "skipped --", msg)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
return -2
|
return -2
|
||||||
except (ImportError, support.TestSkipped) as msg:
|
except (ImportError, unittest.SkipTest) as msg:
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print(test, "skipped --", msg)
|
print(test, "skipped --", msg)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
|
@ -8,12 +8,12 @@ import errno
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import os.path
|
import platform
|
||||||
import shutil
|
import shutil
|
||||||
import warnings
|
import warnings
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
__all__ = ["Error", "TestFailed", "TestSkipped", "ResourceDenied", "import_module",
|
__all__ = ["Error", "TestFailed", "ResourceDenied", "import_module",
|
||||||
"verbose", "use_resources", "max_memuse", "record_original_stdout",
|
"verbose", "use_resources", "max_memuse", "record_original_stdout",
|
||||||
"get_original_stdout", "unload", "unlink", "rmtree", "forget",
|
"get_original_stdout", "unload", "unlink", "rmtree", "forget",
|
||||||
"is_resource_enabled", "requires", "find_unused_port", "bind_port",
|
"is_resource_enabled", "requires", "find_unused_port", "bind_port",
|
||||||
|
@ -24,7 +24,7 @@ __all__ = ["Error", "TestFailed", "TestSkipped", "ResourceDenied", "import_modul
|
||||||
"TransientResource", "transient_internet", "run_with_locale",
|
"TransientResource", "transient_internet", "run_with_locale",
|
||||||
"set_memlimit", "bigmemtest", "bigaddrspacetest", "BasicTestRunner",
|
"set_memlimit", "bigmemtest", "bigaddrspacetest", "BasicTestRunner",
|
||||||
"run_unittest", "run_doctest", "threading_setup", "threading_cleanup",
|
"run_unittest", "run_doctest", "threading_setup", "threading_cleanup",
|
||||||
"reap_children"]
|
"reap_children", "cpython_only", "check_impl_detail"]
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
"""Base class for regression test exceptions."""
|
"""Base class for regression test exceptions."""
|
||||||
|
@ -32,17 +32,7 @@ class Error(Exception):
|
||||||
class TestFailed(Error):
|
class TestFailed(Error):
|
||||||
"""Test failed."""
|
"""Test failed."""
|
||||||
|
|
||||||
class TestSkipped(Error):
|
class ResourceDenied(unittest.SkipTest):
|
||||||
"""Test skipped.
|
|
||||||
|
|
||||||
This can be raised to indicate that a test was deliberatly
|
|
||||||
skipped, but not because a feature wasn't available. For
|
|
||||||
example, if some resource can't be used, such as the network
|
|
||||||
appears to be unavailable, this should be raised instead of
|
|
||||||
TestFailed.
|
|
||||||
"""
|
|
||||||
|
|
||||||
class ResourceDenied(TestSkipped):
|
|
||||||
"""Test skipped because it requested a disallowed resource.
|
"""Test skipped because it requested a disallowed resource.
|
||||||
|
|
||||||
This is raised when a test calls requires() for a resource that
|
This is raised when a test calls requires() for a resource that
|
||||||
|
@ -51,7 +41,7 @@ class ResourceDenied(TestSkipped):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def import_module(name, deprecated=False):
|
def import_module(name, deprecated=False):
|
||||||
"""Import the module to be tested, raising TestSkipped if it is not
|
"""Import the module to be tested, raising SkipTest if it is not
|
||||||
available."""
|
available."""
|
||||||
with warnings.catch_warnings():
|
with warnings.catch_warnings():
|
||||||
if deprecated:
|
if deprecated:
|
||||||
|
@ -60,7 +50,7 @@ def import_module(name, deprecated=False):
|
||||||
try:
|
try:
|
||||||
module = __import__(name, level=0)
|
module = __import__(name, level=0)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise TestSkipped("No module named " + name)
|
raise unittest.SkipTest("No module named " + name)
|
||||||
else:
|
else:
|
||||||
return module
|
return module
|
||||||
|
|
||||||
|
@ -124,7 +114,7 @@ def requires(resource, msg=None):
|
||||||
possibility of False being returned occurs when regrtest.py is executing."""
|
possibility of False being returned occurs when regrtest.py is executing."""
|
||||||
# see if the caller's module is __main__ - if so, treat as if
|
# see if the caller's module is __main__ - if so, treat as if
|
||||||
# the resource was set
|
# the resource was set
|
||||||
if sys._getframe().f_back.f_globals.get("__name__") == "__main__":
|
if sys._getframe(1).f_globals.get("__name__") == "__main__":
|
||||||
return
|
return
|
||||||
if not is_resource_enabled(resource):
|
if not is_resource_enabled(resource):
|
||||||
if msg is None:
|
if msg is None:
|
||||||
|
@ -357,12 +347,8 @@ def make_bad_fd():
|
||||||
unlink(TESTFN)
|
unlink(TESTFN)
|
||||||
|
|
||||||
def check_syntax_error(testcase, statement):
|
def check_syntax_error(testcase, statement):
|
||||||
try:
|
testcase.assertRaises(SyntaxError, compile, statement,
|
||||||
compile(statement, '<test string>', 'exec')
|
'<test string>', 'exec')
|
||||||
except SyntaxError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
testcase.fail('Missing SyntaxError: "%s"' % statement)
|
|
||||||
|
|
||||||
def open_urlresource(url, *args, **kw):
|
def open_urlresource(url, *args, **kw):
|
||||||
import urllib.request, urllib.parse
|
import urllib.request, urllib.parse
|
||||||
|
@ -522,6 +508,21 @@ def captured_output(stream_name):
|
||||||
def captured_stdout():
|
def captured_stdout():
|
||||||
return captured_output("stdout")
|
return captured_output("stdout")
|
||||||
|
|
||||||
|
def gc_collect():
|
||||||
|
"""Force as many objects as possible to be collected.
|
||||||
|
|
||||||
|
In non-CPython implementations of Python, this is needed because timely
|
||||||
|
deallocation is not guaranteed by the garbage collector. (Even in CPython
|
||||||
|
this can be the case in case of reference cycles.) This means that __del__
|
||||||
|
methods may be called later than expected and weakrefs may remain alive for
|
||||||
|
longer than expected. This function tries its best to force all garbage
|
||||||
|
objects to disappear.
|
||||||
|
"""
|
||||||
|
import gc
|
||||||
|
gc.collect()
|
||||||
|
gc.collect()
|
||||||
|
gc.collect()
|
||||||
|
|
||||||
|
|
||||||
#=======================================================================
|
#=======================================================================
|
||||||
# Decorator for running a function in a different locale, correctly resetting
|
# Decorator for running a function in a different locale, correctly resetting
|
||||||
|
@ -681,6 +682,55 @@ class BasicTestRunner:
|
||||||
test(result)
|
test(result)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def _id(obj):
|
||||||
|
return obj
|
||||||
|
|
||||||
|
def requires_resource(resource):
|
||||||
|
if resource_is_enabled(resource):
|
||||||
|
return _id
|
||||||
|
else:
|
||||||
|
return unittest.skip("resource {0!r} is not enabled".format(resource))
|
||||||
|
|
||||||
|
def cpython_only(test):
|
||||||
|
"""
|
||||||
|
Decorator for tests only applicable on CPython.
|
||||||
|
"""
|
||||||
|
return impl_detail(cpython=True)(test)
|
||||||
|
|
||||||
|
def impl_detail(msg=None, **guards):
|
||||||
|
if check_impl_detail(**guards):
|
||||||
|
return _id
|
||||||
|
if msg is None:
|
||||||
|
guardnames, default = _parse_guards(guards)
|
||||||
|
if default:
|
||||||
|
msg = "implementation detail not available on {0}"
|
||||||
|
else:
|
||||||
|
msg = "implementation detail specific to {0}"
|
||||||
|
guardnames = sorted(guardnames.keys())
|
||||||
|
msg = msg.format(' or '.join(guardnames))
|
||||||
|
return unittest.skip(msg)
|
||||||
|
|
||||||
|
def _parse_guards(guards):
|
||||||
|
# Returns a tuple ({platform_name: run_me}, default_value)
|
||||||
|
if not guards:
|
||||||
|
return ({'cpython': True}, False)
|
||||||
|
is_true = guards.values()[0]
|
||||||
|
assert guards.values() == [is_true] * len(guards) # all True or all False
|
||||||
|
return (guards, not is_true)
|
||||||
|
|
||||||
|
# Use the following check to guard CPython's implementation-specific tests --
|
||||||
|
# or to run them only on the implementation(s) guarded by the arguments.
|
||||||
|
def check_impl_detail(**guards):
|
||||||
|
"""This function returns True or False depending on the host platform.
|
||||||
|
Examples:
|
||||||
|
if check_impl_detail(): # only on CPython (default)
|
||||||
|
if check_impl_detail(jython=True): # only on Jython
|
||||||
|
if check_impl_detail(cpython=False): # everywhere except on CPython
|
||||||
|
"""
|
||||||
|
guards, default = _parse_guards(guards)
|
||||||
|
return guards.get(platform.python_implementation().lower(), default)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _run_suite(suite):
|
def _run_suite(suite):
|
||||||
"""Run tests from a unittest.TestSuite-derived class."""
|
"""Run tests from a unittest.TestSuite-derived class."""
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from test.support import verbose, TestSkipped, run_unittest
|
from test.support import verbose, run_unittest
|
||||||
from _locale import (setlocale, LC_ALL, LC_CTYPE, LC_NUMERIC, RADIXCHAR, THOUSEP, nl_langinfo,
|
from _locale import (setlocale, LC_ALL, LC_CTYPE, LC_NUMERIC, RADIXCHAR, THOUSEP, nl_langinfo,
|
||||||
localeconv, Error)
|
localeconv, Error)
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -7,7 +7,7 @@ from platform import uname
|
||||||
if uname()[0] == "Darwin":
|
if uname()[0] == "Darwin":
|
||||||
maj, min, mic = [int(part) for part in uname()[2].split(".")]
|
maj, min, mic = [int(part) for part in uname()[2].split(".")]
|
||||||
if (maj, min, mic) < (8, 0, 0):
|
if (maj, min, mic) < (8, 0, 0):
|
||||||
raise TestSkipped("locale support broken for OS X < 10.4")
|
raise unittest.SkipTest("locale support broken for OS X < 10.4")
|
||||||
|
|
||||||
candidate_locales = ['es_UY', 'fr_FR', 'fi_FI', 'es_CO', 'pt_PT', 'it_IT',
|
candidate_locales = ['es_UY', 'fr_FR', 'fi_FI', 'es_CO', 'pt_PT', 'it_IT',
|
||||||
'et_EE', 'es_PY', 'no_NO', 'nl_NL', 'lv_LV', 'el_GR', 'be_BY', 'fr_BE',
|
'et_EE', 'es_PY', 'no_NO', 'nl_NL', 'lv_LV', 'el_GR', 'be_BY', 'fr_BE',
|
||||||
|
|
|
@ -16,16 +16,16 @@ import curses.panel
|
||||||
# 'curses' resource be given on the regrtest command line using the -u
|
# 'curses' resource be given on the regrtest command line using the -u
|
||||||
# option. If not available, nothing after this line will be executed.
|
# option. If not available, nothing after this line will be executed.
|
||||||
|
|
||||||
from test.support import requires, TestSkipped
|
from test.support import requires
|
||||||
requires('curses')
|
requires('curses')
|
||||||
|
|
||||||
# XXX: if newterm was supported we could use it instead of initscr and not exit
|
# XXX: if newterm was supported we could use it instead of initscr and not exit
|
||||||
term = os.environ.get('TERM')
|
term = os.environ.get('TERM')
|
||||||
if not term or term == 'unknown':
|
if not term or term == 'unknown':
|
||||||
raise TestSkipped("$TERM=%r, calling initscr() may cause exit" % term)
|
raise unittest.SkipTest("$TERM=%r, calling initscr() may cause exit" % term)
|
||||||
|
|
||||||
if sys.platform == "cygwin":
|
if sys.platform == "cygwin":
|
||||||
raise TestSkipped("cygwin's curses mostly just hangs")
|
raise unittest.SkipTest("cygwin's curses mostly just hangs")
|
||||||
|
|
||||||
def window_funcs(stdscr):
|
def window_funcs(stdscr):
|
||||||
"Test the methods of windows"
|
"Test the methods of windows"
|
||||||
|
|
|
@ -31,8 +31,7 @@ import pickle, copy
|
||||||
import unittest
|
import unittest
|
||||||
from decimal import *
|
from decimal import *
|
||||||
import numbers
|
import numbers
|
||||||
from test.support import (TestSkipped, run_unittest, run_doctest,
|
from test.support import run_unittest, run_doctest, is_resource_enabled
|
||||||
is_resource_enabled)
|
|
||||||
import random
|
import random
|
||||||
try:
|
try:
|
||||||
import threading
|
import threading
|
||||||
|
@ -194,7 +193,7 @@ class DecimalTest(unittest.TestCase):
|
||||||
def eval_file(self, file):
|
def eval_file(self, file):
|
||||||
global skip_expected
|
global skip_expected
|
||||||
if skip_expected:
|
if skip_expected:
|
||||||
raise TestSkipped
|
raise unittest.SkipTest
|
||||||
return
|
return
|
||||||
for line in open(file):
|
for line in open(file):
|
||||||
line = line.replace('\r\n', '').replace('\n', '')
|
line = line.replace('\r\n', '').replace('\n', '')
|
||||||
|
|
|
@ -65,8 +65,9 @@ class OperatorsTest(unittest.TestCase):
|
||||||
# Find method in parent class
|
# Find method in parent class
|
||||||
while meth not in t.__dict__:
|
while meth not in t.__dict__:
|
||||||
t = t.__bases__[0]
|
t = t.__bases__[0]
|
||||||
|
# in some implementations (e.g. PyPy), 'm' can be a regular unbound
|
||||||
self.assertEqual(m, t.__dict__[meth])
|
# method object; the getattr() below obtains its underlying function.
|
||||||
|
self.assertEqual(getattr(m, 'im_func', m), t.__dict__[meth])
|
||||||
self.assertEqual(m(a), res)
|
self.assertEqual(m(a), res)
|
||||||
bm = getattr(a, meth)
|
bm = getattr(a, meth)
|
||||||
self.assertEqual(bm(), res)
|
self.assertEqual(bm(), res)
|
||||||
|
@ -85,7 +86,9 @@ class OperatorsTest(unittest.TestCase):
|
||||||
m = getattr(t, meth)
|
m = getattr(t, meth)
|
||||||
while meth not in t.__dict__:
|
while meth not in t.__dict__:
|
||||||
t = t.__bases__[0]
|
t = t.__bases__[0]
|
||||||
self.assertEqual(m, t.__dict__[meth])
|
# in some implementations (e.g. PyPy), 'm' can be a regular unbound
|
||||||
|
# method object; the getattr() below obtains its underlying function.
|
||||||
|
self.assertEqual(getattr(m, 'im_func', m), t.__dict__[meth])
|
||||||
self.assertEqual(m(a, b), res)
|
self.assertEqual(m(a, b), res)
|
||||||
bm = getattr(a, meth)
|
bm = getattr(a, meth)
|
||||||
self.assertEqual(bm(b), res)
|
self.assertEqual(bm(b), res)
|
||||||
|
@ -97,7 +100,9 @@ class OperatorsTest(unittest.TestCase):
|
||||||
m = getattr(t, meth)
|
m = getattr(t, meth)
|
||||||
while meth not in t.__dict__:
|
while meth not in t.__dict__:
|
||||||
t = t.__bases__[0]
|
t = t.__bases__[0]
|
||||||
self.assertEqual(m, t.__dict__[meth])
|
# in some implementations (e.g. PyPy), 'm' can be a regular unbound
|
||||||
|
# method object; the getattr() below obtains its underlying function.
|
||||||
|
self.assertEqual(getattr(m, 'im_func', m), t.__dict__[meth])
|
||||||
self.assertEqual(m(a, slice(b, c)), res)
|
self.assertEqual(m(a, slice(b, c)), res)
|
||||||
bm = getattr(a, meth)
|
bm = getattr(a, meth)
|
||||||
self.assertEqual(bm(slice(b, c)), res)
|
self.assertEqual(bm(slice(b, c)), res)
|
||||||
|
@ -110,7 +115,9 @@ class OperatorsTest(unittest.TestCase):
|
||||||
m = getattr(t, meth)
|
m = getattr(t, meth)
|
||||||
while meth not in t.__dict__:
|
while meth not in t.__dict__:
|
||||||
t = t.__bases__[0]
|
t = t.__bases__[0]
|
||||||
self.assertEqual(m, t.__dict__[meth])
|
# in some implementations (e.g. PyPy), 'm' can be a regular unbound
|
||||||
|
# method object; the getattr() below obtains its underlying function.
|
||||||
|
self.assertEqual(getattr(m, 'im_func', m), t.__dict__[meth])
|
||||||
d['a'] = deepcopy(a)
|
d['a'] = deepcopy(a)
|
||||||
m(d['a'], b)
|
m(d['a'], b)
|
||||||
self.assertEqual(d['a'], res)
|
self.assertEqual(d['a'], res)
|
||||||
|
@ -127,7 +134,9 @@ class OperatorsTest(unittest.TestCase):
|
||||||
m = getattr(t, meth)
|
m = getattr(t, meth)
|
||||||
while meth not in t.__dict__:
|
while meth not in t.__dict__:
|
||||||
t = t.__bases__[0]
|
t = t.__bases__[0]
|
||||||
self.assertEqual(m, t.__dict__[meth])
|
# in some implementations (e.g. PyPy), 'm' can be a regular unbound
|
||||||
|
# method object; the getattr() below obtains its underlying function.
|
||||||
|
self.assertEqual(getattr(m, 'im_func', m), t.__dict__[meth])
|
||||||
d['a'] = deepcopy(a)
|
d['a'] = deepcopy(a)
|
||||||
m(d['a'], b, c)
|
m(d['a'], b, c)
|
||||||
self.assertEqual(d['a'], res)
|
self.assertEqual(d['a'], res)
|
||||||
|
@ -144,7 +153,9 @@ class OperatorsTest(unittest.TestCase):
|
||||||
while meth not in t.__dict__:
|
while meth not in t.__dict__:
|
||||||
t = t.__bases__[0]
|
t = t.__bases__[0]
|
||||||
m = getattr(t, meth)
|
m = getattr(t, meth)
|
||||||
self.assertEqual(m, t.__dict__[meth])
|
# in some implementations (e.g. PyPy), 'm' can be a regular unbound
|
||||||
|
# method object; the getattr() below obtains its underlying function.
|
||||||
|
self.assertEqual(getattr(m, 'im_func', m), t.__dict__[meth])
|
||||||
dictionary['a'] = deepcopy(a)
|
dictionary['a'] = deepcopy(a)
|
||||||
m(dictionary['a'], slice(b, c), d)
|
m(dictionary['a'], slice(b, c), d)
|
||||||
self.assertEqual(dictionary['a'], res)
|
self.assertEqual(dictionary['a'], res)
|
||||||
|
@ -276,6 +287,7 @@ class OperatorsTest(unittest.TestCase):
|
||||||
self.assertEqual(repr(a), "234.5")
|
self.assertEqual(repr(a), "234.5")
|
||||||
self.assertEqual(a.prec, 12)
|
self.assertEqual(a.prec, 12)
|
||||||
|
|
||||||
|
@support.impl_detail("the module 'xxsubtype' is internal")
|
||||||
def test_spam_lists(self):
|
def test_spam_lists(self):
|
||||||
# Testing spamlist operations...
|
# Testing spamlist operations...
|
||||||
import copy, xxsubtype as spam
|
import copy, xxsubtype as spam
|
||||||
|
@ -319,6 +331,7 @@ class OperatorsTest(unittest.TestCase):
|
||||||
a.setstate(42)
|
a.setstate(42)
|
||||||
self.assertEqual(a.getstate(), 42)
|
self.assertEqual(a.getstate(), 42)
|
||||||
|
|
||||||
|
@support.impl_detail("the module 'xxsubtype' is internal")
|
||||||
def test_spam_dicts(self):
|
def test_spam_dicts(self):
|
||||||
# Testing spamdict operations...
|
# Testing spamdict operations...
|
||||||
import copy, xxsubtype as spam
|
import copy, xxsubtype as spam
|
||||||
|
@ -778,8 +791,11 @@ order (MRO) for bases """
|
||||||
try:
|
try:
|
||||||
callable(*args)
|
callable(*args)
|
||||||
except exc as msg:
|
except exc as msg:
|
||||||
|
# the exact msg is generally considered an impl detail
|
||||||
|
if support.check_impl_detail():
|
||||||
if not str(msg).startswith(expected):
|
if not str(msg).startswith(expected):
|
||||||
self.fail("Message %r, expected %r" % (str(msg), expected))
|
self.fail("Message %r, expected %r" %
|
||||||
|
(str(msg), expected))
|
||||||
else:
|
else:
|
||||||
self.fail("Expected %s" % exc)
|
self.fail("Expected %s" % exc)
|
||||||
|
|
||||||
|
@ -967,6 +983,7 @@ order (MRO) for bases """
|
||||||
x.c = Counted()
|
x.c = Counted()
|
||||||
self.assertEqual(Counted.counter, 3)
|
self.assertEqual(Counted.counter, 3)
|
||||||
del x
|
del x
|
||||||
|
support.gc_collect()
|
||||||
self.assertEqual(Counted.counter, 0)
|
self.assertEqual(Counted.counter, 0)
|
||||||
class D(C):
|
class D(C):
|
||||||
pass
|
pass
|
||||||
|
@ -975,6 +992,7 @@ order (MRO) for bases """
|
||||||
x.z = Counted()
|
x.z = Counted()
|
||||||
self.assertEqual(Counted.counter, 2)
|
self.assertEqual(Counted.counter, 2)
|
||||||
del x
|
del x
|
||||||
|
support.gc_collect()
|
||||||
self.assertEqual(Counted.counter, 0)
|
self.assertEqual(Counted.counter, 0)
|
||||||
class E(D):
|
class E(D):
|
||||||
__slots__ = ['e']
|
__slots__ = ['e']
|
||||||
|
@ -984,6 +1002,7 @@ order (MRO) for bases """
|
||||||
x.e = Counted()
|
x.e = Counted()
|
||||||
self.assertEqual(Counted.counter, 3)
|
self.assertEqual(Counted.counter, 3)
|
||||||
del x
|
del x
|
||||||
|
support.gc_collect()
|
||||||
self.assertEqual(Counted.counter, 0)
|
self.assertEqual(Counted.counter, 0)
|
||||||
|
|
||||||
# Test cyclical leaks [SF bug 519621]
|
# Test cyclical leaks [SF bug 519621]
|
||||||
|
@ -994,21 +1013,22 @@ order (MRO) for bases """
|
||||||
s.a = [Counted(), s]
|
s.a = [Counted(), s]
|
||||||
self.assertEqual(Counted.counter, 1)
|
self.assertEqual(Counted.counter, 1)
|
||||||
s = None
|
s = None
|
||||||
import gc
|
support.gc_collect()
|
||||||
gc.collect()
|
|
||||||
self.assertEqual(Counted.counter, 0)
|
self.assertEqual(Counted.counter, 0)
|
||||||
|
|
||||||
# Test lookup leaks [SF bug 572567]
|
# Test lookup leaks [SF bug 572567]
|
||||||
import sys,gc
|
import sys,gc
|
||||||
|
if hasattr(gc, 'get_objects'):
|
||||||
class G(object):
|
class G(object):
|
||||||
def __eq__(self, other):
|
def __cmp__(self, other):
|
||||||
return 1
|
return 0
|
||||||
g = G()
|
g = G()
|
||||||
orig_objects = len(gc.get_objects())
|
orig_objects = len(gc.get_objects())
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
g==g
|
g==g
|
||||||
new_objects = len(gc.get_objects())
|
new_objects = len(gc.get_objects())
|
||||||
self.assertEqual(orig_objects, new_objects)
|
self.assertEqual(orig_objects, new_objects)
|
||||||
|
|
||||||
class H(object):
|
class H(object):
|
||||||
__slots__ = ['a', 'b']
|
__slots__ = ['a', 'b']
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -1262,6 +1282,7 @@ order (MRO) for bases """
|
||||||
else:
|
else:
|
||||||
self.fail("classmethod shouldn't accept keyword args")
|
self.fail("classmethod shouldn't accept keyword args")
|
||||||
|
|
||||||
|
@support.impl_detail("the module 'xxsubtype' is internal")
|
||||||
def test_classmethods_in_c(self):
|
def test_classmethods_in_c(self):
|
||||||
# Testing C-based class methods...
|
# Testing C-based class methods...
|
||||||
import xxsubtype as spam
|
import xxsubtype as spam
|
||||||
|
@ -1293,6 +1314,7 @@ order (MRO) for bases """
|
||||||
self.assertEqual(d.foo(1), (d, 1))
|
self.assertEqual(d.foo(1), (d, 1))
|
||||||
self.assertEqual(D.foo(d, 1), (d, 1))
|
self.assertEqual(D.foo(d, 1), (d, 1))
|
||||||
|
|
||||||
|
@support.impl_detail("the module 'xxsubtype' is internal")
|
||||||
def test_staticmethods_in_c(self):
|
def test_staticmethods_in_c(self):
|
||||||
# Testing C-based static methods...
|
# Testing C-based static methods...
|
||||||
import xxsubtype as spam
|
import xxsubtype as spam
|
||||||
|
@ -1410,6 +1432,14 @@ order (MRO) for bases """
|
||||||
return [self, dict, object]
|
return [self, dict, object]
|
||||||
class X(object, metaclass=_metaclass):
|
class X(object, metaclass=_metaclass):
|
||||||
pass
|
pass
|
||||||
|
# In CPython, the class creation above already raises
|
||||||
|
# TypeError, as a protection against the fact that
|
||||||
|
# instances of X would segfault it. In other Python
|
||||||
|
# implementations it would be ok to let the class X
|
||||||
|
# be created, but instead get a clean TypeError on the
|
||||||
|
# __setitem__ below.
|
||||||
|
x = object.__new__(X)
|
||||||
|
x[5] = 6
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
@ -1614,6 +1644,7 @@ order (MRO) for bases """
|
||||||
r = weakref.ref(c)
|
r = weakref.ref(c)
|
||||||
self.assertEqual(r(), c)
|
self.assertEqual(r(), c)
|
||||||
del c
|
del c
|
||||||
|
support.gc_collect()
|
||||||
self.assertEqual(r(), None)
|
self.assertEqual(r(), None)
|
||||||
del r
|
del r
|
||||||
class NoWeak(object):
|
class NoWeak(object):
|
||||||
|
@ -1631,6 +1662,7 @@ order (MRO) for bases """
|
||||||
r = weakref.ref(yes)
|
r = weakref.ref(yes)
|
||||||
self.assertEqual(r(), yes)
|
self.assertEqual(r(), yes)
|
||||||
del yes
|
del yes
|
||||||
|
support.gc_collect()
|
||||||
self.assertEqual(r(), None)
|
self.assertEqual(r(), None)
|
||||||
del r
|
del r
|
||||||
|
|
||||||
|
@ -1936,6 +1968,9 @@ order (MRO) for bases """
|
||||||
|
|
||||||
# Two essentially featureless objects, just inheriting stuff from
|
# Two essentially featureless objects, just inheriting stuff from
|
||||||
# object.
|
# object.
|
||||||
|
self.assertEqual(dir(NotImplemented), dir(Ellipsis))
|
||||||
|
if support.check_impl_detail():
|
||||||
|
# None differs in PyPy: it has a __nonzero__
|
||||||
self.assertEqual(dir(None), dir(Ellipsis))
|
self.assertEqual(dir(None), dir(Ellipsis))
|
||||||
|
|
||||||
# Nasty test case for proxied objects
|
# Nasty test case for proxied objects
|
||||||
|
@ -2652,7 +2687,7 @@ order (MRO) for bases """
|
||||||
self.fail("shouldn't allow %r.__class__ = %r" % (x, C))
|
self.fail("shouldn't allow %r.__class__ = %r" % (x, C))
|
||||||
try:
|
try:
|
||||||
delattr(x, "__class__")
|
delattr(x, "__class__")
|
||||||
except TypeError:
|
except (TypeError, AttributeError):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.fail("shouldn't allow del %r.__class__" % x)
|
self.fail("shouldn't allow del %r.__class__" % x)
|
||||||
|
@ -2780,6 +2815,16 @@ order (MRO) for bases """
|
||||||
mod.__dict__["spam"] = "eggs"
|
mod.__dict__["spam"] = "eggs"
|
||||||
|
|
||||||
# Exception's __dict__ can be replaced, but not deleted
|
# Exception's __dict__ can be replaced, but not deleted
|
||||||
|
# (at least not any more than regular exception's __dict__ can
|
||||||
|
# be deleted; on CPython it is not the case, whereas on PyPy they
|
||||||
|
# can, just like any other new-style instance's __dict__.)
|
||||||
|
def can_delete_dict(e):
|
||||||
|
try:
|
||||||
|
del e.__dict__
|
||||||
|
except (TypeError, AttributeError):
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
class Exception1(Exception, Base):
|
class Exception1(Exception, Base):
|
||||||
pass
|
pass
|
||||||
class Exception2(Base, Exception):
|
class Exception2(Base, Exception):
|
||||||
|
@ -2788,12 +2833,7 @@ order (MRO) for bases """
|
||||||
e = ExceptionType()
|
e = ExceptionType()
|
||||||
e.__dict__ = {"a": 1}
|
e.__dict__ = {"a": 1}
|
||||||
self.assertEqual(e.a, 1)
|
self.assertEqual(e.a, 1)
|
||||||
try:
|
self.assertEqual(can_delete_dict(e), can_delete_dict(ValueError()))
|
||||||
del e.__dict__
|
|
||||||
except (TypeError, AttributeError):
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
self.fail("%r's __dict__ can be deleted" % e)
|
|
||||||
|
|
||||||
def test_pickles(self):
|
def test_pickles(self):
|
||||||
# Testing pickling and copying new-style classes and objects...
|
# Testing pickling and copying new-style classes and objects...
|
||||||
|
@ -3070,7 +3110,7 @@ order (MRO) for bases """
|
||||||
class B(A):
|
class B(A):
|
||||||
pass
|
pass
|
||||||
del B
|
del B
|
||||||
gc.collect()
|
support.gc_collect()
|
||||||
A.__setitem__ = lambda *a: None # crash
|
A.__setitem__ = lambda *a: None # crash
|
||||||
|
|
||||||
def test_buffer_inheritance(self):
|
def test_buffer_inheritance(self):
|
||||||
|
@ -3154,6 +3194,7 @@ order (MRO) for bases """
|
||||||
c = C()
|
c = C()
|
||||||
self.assertEqual(log, [])
|
self.assertEqual(log, [])
|
||||||
del c
|
del c
|
||||||
|
support.gc_collect()
|
||||||
self.assertEqual(log, [1])
|
self.assertEqual(log, [1])
|
||||||
|
|
||||||
class D(object): pass
|
class D(object): pass
|
||||||
|
@ -3249,7 +3290,7 @@ order (MRO) for bases """
|
||||||
self.assertEqual(hasattr(m, "__name__"), 0)
|
self.assertEqual(hasattr(m, "__name__"), 0)
|
||||||
self.assertEqual(hasattr(m, "__file__"), 0)
|
self.assertEqual(hasattr(m, "__file__"), 0)
|
||||||
self.assertEqual(hasattr(m, "foo"), 0)
|
self.assertEqual(hasattr(m, "foo"), 0)
|
||||||
self.assertEqual(m.__dict__, None)
|
self.assertFalse(m.__dict__) # None or {} are both reasonable answers
|
||||||
m.foo = 1
|
m.foo = 1
|
||||||
self.assertEqual(m.__dict__, {"foo": 1})
|
self.assertEqual(m.__dict__, {"foo": 1})
|
||||||
|
|
||||||
|
@ -3384,15 +3425,21 @@ order (MRO) for bases """
|
||||||
c = C()
|
c = C()
|
||||||
c.attr = 42
|
c.attr = 42
|
||||||
|
|
||||||
# The most interesting thing here is whether this blows up, due to flawed
|
# The most interesting thing here is whether this blows up, due to
|
||||||
# GC tracking logic in typeobject.c's call_finalizer() (a 2.2.1 bug).
|
# flawed GC tracking logic in typeobject.c's call_finalizer() (a 2.2.1
|
||||||
|
# bug).
|
||||||
del c
|
del c
|
||||||
|
|
||||||
# If that didn't blow up, it's also interesting to see whether clearing
|
# If that didn't blow up, it's also interesting to see whether clearing
|
||||||
# the last container slot works: that will attempt to delete c again,
|
# the last container slot works: that will attempt to delete c again,
|
||||||
# which will cause c to get appended back to the container again "during"
|
# which will cause c to get appended back to the container again
|
||||||
# the del.
|
# "during" the del. (On non-CPython implementations, however, __del__
|
||||||
|
# is typically not called again.)
|
||||||
|
support.gc_collect()
|
||||||
|
self.assertEqual(len(C.container), 1)
|
||||||
del C.container[-1]
|
del C.container[-1]
|
||||||
|
if support.check_impl_detail():
|
||||||
|
support.gc_collect()
|
||||||
self.assertEqual(len(C.container), 1)
|
self.assertEqual(len(C.container), 1)
|
||||||
self.assertEqual(C.container[-1].attr, 42)
|
self.assertEqual(C.container[-1].attr, 42)
|
||||||
|
|
||||||
|
@ -3420,6 +3467,7 @@ order (MRO) for bases """
|
||||||
pass
|
pass
|
||||||
class C(A,B) :
|
class C(A,B) :
|
||||||
__slots__=()
|
__slots__=()
|
||||||
|
if support.check_impl_detail():
|
||||||
self.assertEqual(C.__basicsize__, B.__basicsize__)
|
self.assertEqual(C.__basicsize__, B.__basicsize__)
|
||||||
self.assert_(hasattr(C, '__dict__'))
|
self.assert_(hasattr(C, '__dict__'))
|
||||||
self.assert_(hasattr(C, '__weakref__'))
|
self.assert_(hasattr(C, '__weakref__'))
|
||||||
|
@ -3503,7 +3551,7 @@ order (MRO) for bases """
|
||||||
|
|
||||||
try:
|
try:
|
||||||
del D.__bases__
|
del D.__bases__
|
||||||
except TypeError:
|
except (TypeError, AttributeError):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.fail("shouldn't be able to delete .__bases__")
|
self.fail("shouldn't be able to delete .__bases__")
|
||||||
|
@ -3681,6 +3729,7 @@ order (MRO) for bases """
|
||||||
self.assertEqual(E() // C(), "C.__floordiv__")
|
self.assertEqual(E() // C(), "C.__floordiv__")
|
||||||
self.assertEqual(C() // E(), "C.__floordiv__") # This one would fail
|
self.assertEqual(C() // E(), "C.__floordiv__") # This one would fail
|
||||||
|
|
||||||
|
@support.impl_detail("testing an internal kind of method object")
|
||||||
def test_meth_class_get(self):
|
def test_meth_class_get(self):
|
||||||
# Testing __get__ method of METH_CLASS C methods...
|
# Testing __get__ method of METH_CLASS C methods...
|
||||||
# Full coverage of descrobject.c::classmethod_get()
|
# Full coverage of descrobject.c::classmethod_get()
|
||||||
|
@ -3866,7 +3915,7 @@ order (MRO) for bases """
|
||||||
|
|
||||||
self.assertEqual(c.attr, 1)
|
self.assertEqual(c.attr, 1)
|
||||||
# this makes a crash more likely:
|
# this makes a crash more likely:
|
||||||
import gc; gc.collect()
|
support.gc_collect()
|
||||||
self.assertEqual(hasattr(c, 'attr'), False)
|
self.assertEqual(hasattr(c, 'attr'), False)
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
|
@ -3893,8 +3942,14 @@ order (MRO) for bases """
|
||||||
self.assert_(l.__add__ != [5].__add__)
|
self.assert_(l.__add__ != [5].__add__)
|
||||||
self.assert_(l.__add__ != l.__mul__)
|
self.assert_(l.__add__ != l.__mul__)
|
||||||
self.assert_(l.__add__.__name__ == '__add__')
|
self.assert_(l.__add__.__name__ == '__add__')
|
||||||
|
if hasattr(l.__add__, '__self__'):
|
||||||
|
# CPython
|
||||||
self.assert_(l.__add__.__self__ is l)
|
self.assert_(l.__add__.__self__ is l)
|
||||||
self.assert_(l.__add__.__objclass__ is list)
|
self.assert_(l.__add__.__objclass__ is list)
|
||||||
|
else:
|
||||||
|
# Python implementations where [].__add__ is a normal bound method
|
||||||
|
self.assert_(l.__add__.im_self is l)
|
||||||
|
self.assert_(l.__add__.im_class is list)
|
||||||
self.assertEqual(l.__add__.__doc__, list.__add__.__doc__)
|
self.assertEqual(l.__add__.__doc__, list.__add__.__doc__)
|
||||||
try:
|
try:
|
||||||
hash(l.__add__)
|
hash(l.__add__)
|
||||||
|
|
|
@ -31,13 +31,13 @@ import unittest
|
||||||
|
|
||||||
from test import support
|
from test import support
|
||||||
if not hasattr(select, "epoll"):
|
if not hasattr(select, "epoll"):
|
||||||
raise support.TestSkipped("test works only on Linux 2.6")
|
raise unittest.SkipTest("test works only on Linux 2.6")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
select.epoll()
|
select.epoll()
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
if e.errno == errno.ENOSYS:
|
if e.errno == errno.ENOSYS:
|
||||||
raise support.TestSkipped("kernel doesn't support epoll()")
|
raise unittest.SkipTest("kernel doesn't support epoll()")
|
||||||
|
|
||||||
class TestEPoll(unittest.TestCase):
|
class TestEPoll(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,12 @@
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
from test.fork_wait import ForkWait
|
from test.fork_wait import ForkWait
|
||||||
from test.support import TestSkipped, run_unittest, reap_children
|
from test.support import run_unittest, reap_children
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.fork
|
os.fork
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise TestSkipped("os.fork not defined -- skipping test_fork1")
|
raise unittest.SkipTest("os.fork not defined -- skipping test_fork1")
|
||||||
|
|
||||||
class ForkTest(ForkWait):
|
class ForkTest(ForkWait):
|
||||||
def wait_impl(self, cpid):
|
def wait_impl(self, cpid):
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
import unittest
|
import unittest
|
||||||
from test.support import TestSkipped, run_unittest
|
from test.support import run_unittest
|
||||||
import os, struct
|
import os, struct
|
||||||
try:
|
try:
|
||||||
import fcntl, termios
|
import fcntl, termios
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise TestSkipped("No fcntl or termios module")
|
raise unittest.SkipTest("No fcntl or termios module")
|
||||||
if not hasattr(termios,'TIOCGPGRP'):
|
if not hasattr(termios,'TIOCGPGRP'):
|
||||||
raise TestSkipped("termios module doesn't have TIOCGPGRP")
|
raise unittest.SkipTest("termios module doesn't have TIOCGPGRP")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tty = open("/dev/tty", "r")
|
tty = open("/dev/tty", "r")
|
||||||
tty.close()
|
tty.close()
|
||||||
except IOError:
|
except IOError:
|
||||||
raise TestSkipped("Unable to open /dev/tty")
|
raise unittest.SkipTest("Unable to open /dev/tty")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import pty
|
import pty
|
||||||
|
@ -41,7 +41,7 @@ class IoctlTests(unittest.TestCase):
|
||||||
|
|
||||||
def test_ioctl_signed_unsigned_code_param(self):
|
def test_ioctl_signed_unsigned_code_param(self):
|
||||||
if not pty:
|
if not pty:
|
||||||
raise TestSkipped('pty module required')
|
raise unittest.SkipTest('pty module required')
|
||||||
mfd, sfd = pty.openpty()
|
mfd, sfd = pty.openpty()
|
||||||
try:
|
try:
|
||||||
if termios.TIOCSWINSZ < 0:
|
if termios.TIOCSWINSZ < 0:
|
||||||
|
|
|
@ -10,7 +10,7 @@ import unittest
|
||||||
|
|
||||||
from test import support
|
from test import support
|
||||||
if not hasattr(select, "kqueue"):
|
if not hasattr(select, "kqueue"):
|
||||||
raise support.TestSkipped("test works only on BSD")
|
raise unittest.SkipTest("test works only on BSD")
|
||||||
|
|
||||||
class TestKQueue(unittest.TestCase):
|
class TestKQueue(unittest.TestCase):
|
||||||
def test_create_queue(self):
|
def test_create_queue(self):
|
||||||
|
|
|
@ -6,7 +6,7 @@ import stat
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
from test.support import run_unittest, TESTFN, verbose, requires, \
|
from test.support import run_unittest, TESTFN, verbose, requires, \
|
||||||
TestSkipped, unlink
|
unlink
|
||||||
import io # C implementation of io
|
import io # C implementation of io
|
||||||
import _pyio as pyio # Python implementation of io
|
import _pyio as pyio # Python implementation of io
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ class LargeFileTest(unittest.TestCase):
|
||||||
# this is already decided before start running the test suite
|
# this is already decided before start running the test suite
|
||||||
# but we do it anyway for extra protection
|
# but we do it anyway for extra protection
|
||||||
if not hasattr(f, 'truncate'):
|
if not hasattr(f, 'truncate'):
|
||||||
raise TestSkipped("open().truncate() not available on this system")
|
raise unittest.SkipTest("open().truncate() not available on this system")
|
||||||
f.seek(0, 2)
|
f.seek(0, 2)
|
||||||
# else we've lost track of the true size
|
# else we've lost track of the true size
|
||||||
self.assertEqual(f.tell(), size+1)
|
self.assertEqual(f.tell(), size+1)
|
||||||
|
@ -165,7 +165,7 @@ def test_main():
|
||||||
except (IOError, OverflowError):
|
except (IOError, OverflowError):
|
||||||
f.close()
|
f.close()
|
||||||
unlink(TESTFN)
|
unlink(TESTFN)
|
||||||
raise TestSkipped("filesystem does not have largefile support")
|
raise unittest.SkipTest("filesystem does not have largefile support")
|
||||||
else:
|
else:
|
||||||
f.close()
|
f.close()
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from test.support import run_unittest, TestSkipped, verbose
|
from test.support import run_unittest, verbose
|
||||||
import unittest
|
import unittest
|
||||||
import locale
|
import locale
|
||||||
import sys
|
import sys
|
||||||
|
@ -9,7 +9,7 @@ enUS_locale = None
|
||||||
def get_enUS_locale():
|
def get_enUS_locale():
|
||||||
global enUS_locale
|
global enUS_locale
|
||||||
if sys.platform == 'darwin':
|
if sys.platform == 'darwin':
|
||||||
raise TestSkipped("Locale support on MacOSX is minimal")
|
raise unittest.SkipTest("Locale support on MacOSX is minimal")
|
||||||
if sys.platform.startswith("win"):
|
if sys.platform.startswith("win"):
|
||||||
tlocs = ("En", "English")
|
tlocs = ("En", "English")
|
||||||
else:
|
else:
|
||||||
|
@ -22,7 +22,7 @@ def get_enUS_locale():
|
||||||
continue
|
continue
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
raise TestSkipped(
|
raise unittest.SkipTest(
|
||||||
"Test locale not supported (tried %s)" % (', '.join(tlocs)))
|
"Test locale not supported (tried %s)" % (', '.join(tlocs)))
|
||||||
enUS_locale = tloc
|
enUS_locale = tloc
|
||||||
locale.setlocale(locale.LC_NUMERIC, oldlocale)
|
locale.setlocale(locale.LC_NUMERIC, oldlocale)
|
||||||
|
@ -318,10 +318,10 @@ def test_main():
|
||||||
TestCNumberFormatting,
|
TestCNumberFormatting,
|
||||||
TestFrFRNumberFormatting,
|
TestFrFRNumberFormatting,
|
||||||
]
|
]
|
||||||
# TestSkipped can't be raised inside unittests, handle it manually instead
|
# SkipTest can't be raised inside unittests, handle it manually instead
|
||||||
try:
|
try:
|
||||||
get_enUS_locale()
|
get_enUS_locale()
|
||||||
except TestSkipped as e:
|
except unittest.SkipTest as e:
|
||||||
if verbose:
|
if verbose:
|
||||||
print("Some tests will be disabled: %s" % e)
|
print("Some tests will be disabled: %s" % e)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import pickle
|
import pickle
|
||||||
from test.support import verbose, run_unittest, TestSkipped
|
from test.support import verbose, run_unittest
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import xml.dom
|
import xml.dom
|
||||||
|
|
|
@ -23,8 +23,7 @@ import logging
|
||||||
try:
|
try:
|
||||||
import multiprocessing.synchronize
|
import multiprocessing.synchronize
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
from test.test_support import TestSkipped
|
raise unittest.SkipTest(e)
|
||||||
raise TestSkipped(e)
|
|
||||||
|
|
||||||
import multiprocessing.dummy
|
import multiprocessing.dummy
|
||||||
import multiprocessing.connection
|
import multiprocessing.connection
|
||||||
|
@ -1814,7 +1813,7 @@ def test_main(run=None):
|
||||||
lock = multiprocessing.RLock()
|
lock = multiprocessing.RLock()
|
||||||
except OSError:
|
except OSError:
|
||||||
from test.support import TestSkipped
|
from test.support import TestSkipped
|
||||||
raise TestSkipped("OSError raises on RLock creation, see issue 3111!")
|
raise unittest.SkipTest("OSError raises on RLock creation, see issue 3111!")
|
||||||
|
|
||||||
if run is None:
|
if run is None:
|
||||||
from test.support import run_unittest as run
|
from test.support import run_unittest as run
|
||||||
|
|
|
@ -2,7 +2,7 @@ from test import support
|
||||||
import unittest
|
import unittest
|
||||||
import nis
|
import nis
|
||||||
|
|
||||||
raise support.TestSkipped("test_nis hangs on Solaris")
|
raise unittest.SkipTest("test_nis hangs on Solaris")
|
||||||
|
|
||||||
class NisTests(unittest.TestCase):
|
class NisTests(unittest.TestCase):
|
||||||
def test_maps(self):
|
def test_maps(self):
|
||||||
|
@ -12,7 +12,7 @@ class NisTests(unittest.TestCase):
|
||||||
# NIS is probably not active, so this test isn't useful
|
# NIS is probably not active, so this test isn't useful
|
||||||
if support.verbose:
|
if support.verbose:
|
||||||
print("Test Skipped:", msg)
|
print("Test Skipped:", msg)
|
||||||
# Can't raise TestSkipped as regrtest only recognizes the exception
|
# Can't raise SkipTest as regrtest only recognizes the exception
|
||||||
# import time.
|
# import time.
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
# Test to see if openpty works. (But don't worry if it isn't available.)
|
# Test to see if openpty works. (But don't worry if it isn't available.)
|
||||||
|
|
||||||
import os, unittest
|
import os, unittest
|
||||||
from test.support import run_unittest, TestSkipped
|
from test.support import run_unittest
|
||||||
|
|
||||||
if not hasattr(os, "openpty"):
|
if not hasattr(os, "openpty"):
|
||||||
raise TestSkipped("No openpty() available.")
|
raise unittest.SkipTest("No openpty() available.")
|
||||||
|
|
||||||
|
|
||||||
class OpenptyTest(unittest.TestCase):
|
class OpenptyTest(unittest.TestCase):
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from test import support
|
from test import support
|
||||||
support.requires('audio')
|
support.requires('audio')
|
||||||
|
|
||||||
from test.support import findfile, TestSkipped
|
from test.support import findfile
|
||||||
|
|
||||||
import errno
|
import errno
|
||||||
import ossaudiodev
|
import ossaudiodev
|
||||||
|
@ -46,7 +46,7 @@ class OSSAudioDevTests(unittest.TestCase):
|
||||||
except IOError as msg:
|
except IOError as msg:
|
||||||
if msg.args[0] in (errno.EACCES, errno.ENOENT,
|
if msg.args[0] in (errno.EACCES, errno.ENOENT,
|
||||||
errno.ENODEV, errno.EBUSY):
|
errno.ENODEV, errno.EBUSY):
|
||||||
raise TestSkipped(msg)
|
raise unittest.SkipTest(msg)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
# at least check that these methods can be invoked
|
# at least check that these methods can be invoked
|
||||||
|
@ -165,7 +165,7 @@ def test_main():
|
||||||
except (ossaudiodev.error, IOError) as msg:
|
except (ossaudiodev.error, IOError) as msg:
|
||||||
if msg.args[0] in (errno.EACCES, errno.ENOENT,
|
if msg.args[0] in (errno.EACCES, errno.ENOENT,
|
||||||
errno.ENODEV, errno.EBUSY):
|
errno.ENODEV, errno.EBUSY):
|
||||||
raise TestSkipped(msg)
|
raise unittest.SkipTest(msg)
|
||||||
raise
|
raise
|
||||||
dsp.close()
|
dsp.close()
|
||||||
support.run_unittest(__name__)
|
support.run_unittest(__name__)
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
import sys, os, unittest
|
import sys, os, unittest
|
||||||
from test import support
|
from test import support
|
||||||
if not os.path.supports_unicode_filenames:
|
if not os.path.supports_unicode_filenames:
|
||||||
raise support.TestSkipped("test works only on NT+")
|
raise unittest.SkipTest("test works only on NT+")
|
||||||
|
|
||||||
filenames = [
|
filenames = [
|
||||||
'abc',
|
'abc',
|
||||||
|
|
|
@ -2,10 +2,10 @@ import pipes
|
||||||
import os
|
import os
|
||||||
import string
|
import string
|
||||||
import unittest
|
import unittest
|
||||||
from test.support import TESTFN, run_unittest, unlink, TestSkipped
|
from test.support import TESTFN, run_unittest, unlink
|
||||||
|
|
||||||
if os.name != 'posix':
|
if os.name != 'posix':
|
||||||
raise TestSkipped('pipes module only works on posix')
|
raise unittest.SkipTest('pipes module only works on posix')
|
||||||
|
|
||||||
TESTFN2 = TESTFN + "2"
|
TESTFN2 = TESTFN + "2"
|
||||||
|
|
||||||
|
|
|
@ -48,25 +48,73 @@ class PlatformTest(unittest.TestCase):
|
||||||
def test_processor(self):
|
def test_processor(self):
|
||||||
res = platform.processor()
|
res = platform.processor()
|
||||||
|
|
||||||
def test_python_implementation(self):
|
def setUp(self):
|
||||||
res = platform.python_implementation()
|
self.save_version = sys.version
|
||||||
|
self.save_subversion = sys.subversion
|
||||||
|
self.save_platform = sys.platform
|
||||||
|
|
||||||
def test_python_version(self):
|
def tearDown(self):
|
||||||
res1 = platform.python_version()
|
sys.version = self.save_version
|
||||||
res2 = platform.python_version_tuple()
|
sys.subversion = self.save_subversion
|
||||||
self.assertEqual(res1, ".".join(res2))
|
sys.platform = self.save_platform
|
||||||
|
|
||||||
def test_python_branch(self):
|
def test_sys_version(self):
|
||||||
res = platform.python_branch()
|
# Old test.
|
||||||
|
for input, output in (
|
||||||
|
('2.4.3 (#1, Jun 21 2006, 13:54:21) \n[GCC 3.3.4 (pre 3.3.5 20040809)]',
|
||||||
|
('CPython', '2.4.3', '', '', '1', 'Jun 21 2006 13:54:21', 'GCC 3.3.4 (pre 3.3.5 20040809)')),
|
||||||
|
('IronPython 1.0.60816 on .NET 2.0.50727.42',
|
||||||
|
('IronPython', '1.0.60816', '', '', '', '', '.NET 2.0.50727.42')),
|
||||||
|
('IronPython 1.0 (1.0.61005.1977) on .NET 2.0.50727.42',
|
||||||
|
('IronPython', '1.0.0', '', '', '', '', '.NET 2.0.50727.42')),
|
||||||
|
):
|
||||||
|
# branch and revision are not "parsed", but fetched
|
||||||
|
# from sys.subversion. Ignore them
|
||||||
|
(name, version, branch, revision, buildno, builddate, compiler) \
|
||||||
|
= platform._sys_version(input)
|
||||||
|
self.assertEqual(
|
||||||
|
(name, version, '', '', buildno, builddate, compiler), output)
|
||||||
|
|
||||||
def test_python_revision(self):
|
# Tests for python_implementation(), python_version(), python_branch(),
|
||||||
res = platform.python_revision()
|
# python_revision(), python_build(), and python_compiler().
|
||||||
|
sys_versions = {
|
||||||
def test_python_build(self):
|
("2.6.1 (r261:67515, Dec 6 2008, 15:26:00) \n[GCC 4.0.1 (Apple Computer, Inc. build 5370)]",
|
||||||
res = platform.python_build()
|
('CPython', 'tags/r261', '67515'), self.save_platform)
|
||||||
|
:
|
||||||
def test_python_compiler(self):
|
("CPython", "2.6.1", "tags/r261", "67515",
|
||||||
res = platform.python_compiler()
|
('r261:67515', 'Dec 6 2008 15:26:00'),
|
||||||
|
'GCC 4.0.1 (Apple Computer, Inc. build 5370)'),
|
||||||
|
("IronPython 2.0 (2.0.0.0) on .NET 2.0.50727.3053", None, "cli")
|
||||||
|
:
|
||||||
|
("IronPython", "2.0.0", "", "", ("", ""),
|
||||||
|
".NET 2.0.50727.3053"),
|
||||||
|
("2.5 (trunk:6107, Mar 26 2009, 13:02:18) \n[Java HotSpot(TM) Client VM (\"Apple Computer, Inc.\")]",
|
||||||
|
('Jython', 'trunk', '6107'), "java1.5.0_16")
|
||||||
|
:
|
||||||
|
("Jython", "2.5.0", "trunk", "6107",
|
||||||
|
('trunk:6107', 'Mar 26 2009'), "java1.5.0_16"),
|
||||||
|
("2.5.2 (63378, Mar 26 2009, 18:03:29)\n[PyPy 1.0.0]",
|
||||||
|
('PyPy', 'trunk', '63378'), self.save_platform)
|
||||||
|
:
|
||||||
|
("PyPy", "2.5.2", "trunk", "63378", ('63378', 'Mar 26 2009'),
|
||||||
|
"")
|
||||||
|
}
|
||||||
|
for (version_tag, subversion, sys_platform), info in \
|
||||||
|
sys_versions.items():
|
||||||
|
sys.version = version_tag
|
||||||
|
if subversion is None:
|
||||||
|
if hasattr(sys, "subversion"):
|
||||||
|
del sys.subversion
|
||||||
|
else:
|
||||||
|
sys.subversion = subversion
|
||||||
|
if sys_platform is not None:
|
||||||
|
sys.platform = sys_platform
|
||||||
|
self.assertEqual(platform.python_implementation(), info[0])
|
||||||
|
self.assertEqual(platform.python_version(), info[1])
|
||||||
|
self.assertEqual(platform.python_branch(), info[2])
|
||||||
|
self.assertEqual(platform.python_revision(), info[3])
|
||||||
|
self.assertEqual(platform.python_build(), info[4])
|
||||||
|
self.assertEqual(platform.python_compiler(), info[5])
|
||||||
|
|
||||||
def test_system_alias(self):
|
def test_system_alias(self):
|
||||||
res = platform.system_alias(
|
res = platform.system_alias(
|
||||||
|
@ -140,23 +188,6 @@ class PlatformTest(unittest.TestCase):
|
||||||
):
|
):
|
||||||
self.assertEqual(platform._parse_release_file(input), output)
|
self.assertEqual(platform._parse_release_file(input), output)
|
||||||
|
|
||||||
def test_sys_version(self):
|
|
||||||
|
|
||||||
platform._sys_version_cache.clear()
|
|
||||||
for input, output in (
|
|
||||||
('2.4.3 (#1, Jun 21 2006, 13:54:21) \n[GCC 3.3.4 (pre 3.3.5 20040809)]',
|
|
||||||
('CPython', '2.4.3', '', '', '1', 'Jun 21 2006 13:54:21', 'GCC 3.3.4 (pre 3.3.5 20040809)')),
|
|
||||||
('IronPython 1.0.60816 on .NET 2.0.50727.42',
|
|
||||||
('IronPython', '1.0.60816', '', '', '', '', '.NET 2.0.50727.42')),
|
|
||||||
('IronPython 1.0 (1.0.61005.1977) on .NET 2.0.50727.42',
|
|
||||||
('IronPython', '1.0.0', '', '', '', '', '.NET 2.0.50727.42')),
|
|
||||||
):
|
|
||||||
# branch and revision are not "parsed", but fetched
|
|
||||||
# from sys.subversion. Ignore them
|
|
||||||
(name, version, branch, revision, buildno, builddate, compiler) \
|
|
||||||
= platform._sys_version(input)
|
|
||||||
self.assertEqual(
|
|
||||||
(name, version, '', '', buildno, builddate, compiler), output)
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
support.run_unittest(
|
support.run_unittest(
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
# Test case for the os.poll() function
|
# Test case for the os.poll() function
|
||||||
|
|
||||||
import os, select, random, unittest
|
import os, select, random, unittest
|
||||||
from test.support import TestSkipped, TESTFN, run_unittest
|
from test.support import TESTFN, run_unittest
|
||||||
|
|
||||||
try:
|
try:
|
||||||
select.poll
|
select.poll
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise TestSkipped("select.poll not defined -- skipping test_poll")
|
raise unittest.SkipTest("select.poll not defined -- skipping test_poll")
|
||||||
|
|
||||||
|
|
||||||
def find_ready_matching(ready, flag):
|
def find_ready_matching(ready, flag):
|
||||||
|
|
|
@ -5,7 +5,7 @@ from test import support
|
||||||
try:
|
try:
|
||||||
import posix
|
import posix
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise support.TestSkipped("posix is not available")
|
raise unittest.SkipTest("posix is not available")
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
|
@ -225,17 +225,17 @@ class PosixTester(unittest.TestCase):
|
||||||
os.mkdir(base_path)
|
os.mkdir(base_path)
|
||||||
os.chdir(base_path)
|
os.chdir(base_path)
|
||||||
except:
|
except:
|
||||||
# Just returning nothing instead of the TestSkipped exception,
|
# Just returning nothing instead of the SkipTest exception,
|
||||||
# because the test results in Error in that case.
|
# because the test results in Error in that case.
|
||||||
# Is that ok?
|
# Is that ok?
|
||||||
# raise support.TestSkipped, "cannot create directory for testing"
|
# raise unittest.SkipTest("cannot create directory for testing")
|
||||||
return
|
return
|
||||||
|
|
||||||
def _create_and_do_getcwd(dirname, current_path_length = 0):
|
def _create_and_do_getcwd(dirname, current_path_length = 0):
|
||||||
try:
|
try:
|
||||||
os.mkdir(dirname)
|
os.mkdir(dirname)
|
||||||
except:
|
except:
|
||||||
raise support.TestSkipped("mkdir cannot create directory sufficiently deep for getcwd test")
|
raise unittest.SkipTest("mkdir cannot create directory sufficiently deep for getcwd test")
|
||||||
|
|
||||||
os.chdir(dirname)
|
os.chdir(dirname)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -4,7 +4,7 @@ import pty
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import signal
|
import signal
|
||||||
from test.support import verbose, TestSkipped, run_unittest
|
from test.support import verbose, run_unittest
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
TEST_STRING_1 = b"I wish to buy a fish license.\n"
|
TEST_STRING_1 = b"I wish to buy a fish license.\n"
|
||||||
|
@ -69,7 +69,7 @@ class PtyTest(unittest.TestCase):
|
||||||
debug("Got slave_fd '%d'" % slave_fd)
|
debug("Got slave_fd '%d'" % slave_fd)
|
||||||
except OSError:
|
except OSError:
|
||||||
# " An optional feature could not be imported " ... ?
|
# " An optional feature could not be imported " ... ?
|
||||||
raise TestSkipped("Pseudo-terminals (seemingly) not functional.")
|
raise unittest.SkipTest("Pseudo-terminals (seemingly) not functional.")
|
||||||
|
|
||||||
self.assertTrue(os.isatty(slave_fd), 'slave_fd is not a tty')
|
self.assertTrue(os.isatty(slave_fd), 'slave_fd is not a tty')
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import traceback
|
||||||
import sys, os, time, errno
|
import sys, os, time, errno
|
||||||
|
|
||||||
if sys.platform[:3] in ('win', 'os2') or sys.platform == 'riscos':
|
if sys.platform[:3] in ('win', 'os2') or sys.platform == 'riscos':
|
||||||
raise support.TestSkipped("Can't test signal on %s" % \
|
raise unittest.SkipTest("Can't test signal on %s" % \
|
||||||
sys.platform)
|
sys.platform)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ executing have not been removed.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import unittest
|
import unittest
|
||||||
from test.support import TestSkipped, run_unittest, TESTFN
|
from test.support import run_unittest, TESTFN
|
||||||
import builtins
|
import builtins
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -17,7 +17,7 @@ import subprocess
|
||||||
if "site" in sys.modules:
|
if "site" in sys.modules:
|
||||||
import site
|
import site
|
||||||
else:
|
else:
|
||||||
raise TestSkipped("importation of site.py suppressed")
|
raise unittest.SkipTest("importation of site.py suppressed")
|
||||||
|
|
||||||
if not os.path.isdir(site.USER_SITE):
|
if not os.path.isdir(site.USER_SITE):
|
||||||
# need to add user site directory for tests
|
# need to add user site directory for tests
|
||||||
|
|
|
@ -16,7 +16,7 @@ import unittest
|
||||||
import socketserver
|
import socketserver
|
||||||
|
|
||||||
import test.support
|
import test.support
|
||||||
from test.support import reap_children, verbose, TestSkipped
|
from test.support import reap_children, verbose
|
||||||
from test.support import TESTFN as TEST_FILE
|
from test.support import TESTFN as TEST_FILE
|
||||||
|
|
||||||
test.support.requires("network")
|
test.support.requires("network")
|
||||||
|
@ -247,7 +247,7 @@ class SocketServerTest(unittest.TestCase):
|
||||||
def test_main():
|
def test_main():
|
||||||
if imp.lock_held():
|
if imp.lock_held():
|
||||||
# If the import lock is held, the threads will hang
|
# If the import lock is held, the threads will hang
|
||||||
raise TestSkipped("can't run when import lock is held")
|
raise unittest.SkipTest("can't run when import lock is held")
|
||||||
|
|
||||||
test.support.run_unittest(SocketServerTest)
|
test.support.run_unittest(SocketServerTest)
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
from test.support import run_unittest, TestSkipped
|
import unittest
|
||||||
|
from test.support import run_unittest
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import _sqlite3
|
import _sqlite3
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise TestSkipped('no sqlite available')
|
raise unittest.SkipTest('no sqlite available')
|
||||||
from sqlite3.test import (dbapi, types, userfunctions,
|
from sqlite3.test import (dbapi, types, userfunctions,
|
||||||
factory, transactions, hooks, regression,
|
factory, transactions, hooks, regression,
|
||||||
dump)
|
dump)
|
||||||
|
|
|
@ -1161,7 +1161,7 @@ else:
|
||||||
|
|
||||||
def test_main(verbose=False):
|
def test_main(verbose=False):
|
||||||
if skip_expected:
|
if skip_expected:
|
||||||
raise support.TestSkipped("No SSL support")
|
raise unittest.SkipTest("No SSL support")
|
||||||
|
|
||||||
global CERTFILE, SVN_PYTHON_ORG_ROOT_CERT
|
global CERTFILE, SVN_PYTHON_ORG_ROOT_CERT
|
||||||
CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir,
|
CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir,
|
||||||
|
|
|
@ -259,7 +259,7 @@ class test__mkstemp_inner(TC):
|
||||||
def test_file_mode(self):
|
def test_file_mode(self):
|
||||||
# _mkstemp_inner creates files with the proper mode
|
# _mkstemp_inner creates files with the proper mode
|
||||||
if not has_stat:
|
if not has_stat:
|
||||||
return # ugh, can't use TestSkipped.
|
return # ugh, can't use SkipTest.
|
||||||
|
|
||||||
file = self.do_create()
|
file = self.do_create()
|
||||||
mode = stat.S_IMODE(os.stat(file.name).st_mode)
|
mode = stat.S_IMODE(os.stat(file.name).st_mode)
|
||||||
|
@ -274,7 +274,7 @@ class test__mkstemp_inner(TC):
|
||||||
def test_noinherit(self):
|
def test_noinherit(self):
|
||||||
# _mkstemp_inner file handles are not inherited by child processes
|
# _mkstemp_inner file handles are not inherited by child processes
|
||||||
if not has_spawnl:
|
if not has_spawnl:
|
||||||
return # ugh, can't use TestSkipped.
|
return # ugh, can't use SkipTest.
|
||||||
|
|
||||||
if support.verbose:
|
if support.verbose:
|
||||||
v="v"
|
v="v"
|
||||||
|
@ -312,7 +312,7 @@ class test__mkstemp_inner(TC):
|
||||||
def test_textmode(self):
|
def test_textmode(self):
|
||||||
# _mkstemp_inner can create files in text mode
|
# _mkstemp_inner can create files in text mode
|
||||||
if not has_textmode:
|
if not has_textmode:
|
||||||
return # ugh, can't use TestSkipped.
|
return # ugh, can't use SkipTest.
|
||||||
|
|
||||||
self.do_create(bin=0).write(b"blat\n")
|
self.do_create(bin=0).write(b"blat\n")
|
||||||
# XXX should test that the file really is a text file
|
# XXX should test that the file really is a text file
|
||||||
|
@ -476,7 +476,7 @@ class test_mkdtemp(TC):
|
||||||
def test_mode(self):
|
def test_mode(self):
|
||||||
# mkdtemp creates directories with the proper mode
|
# mkdtemp creates directories with the proper mode
|
||||||
if not has_stat:
|
if not has_stat:
|
||||||
return # ugh, can't use TestSkipped.
|
return # ugh, can't use SkipTest.
|
||||||
|
|
||||||
dir = self.do_create()
|
dir = self.do_create()
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
# randrange, and then Python hangs.
|
# randrange, and then Python hangs.
|
||||||
|
|
||||||
import _thread as thread
|
import _thread as thread
|
||||||
from test.support import verbose, TestSkipped, TestFailed
|
from test.support import verbose, TestFailed
|
||||||
|
|
||||||
critical_section = thread.allocate_lock()
|
critical_section = thread.allocate_lock()
|
||||||
done = thread.allocate_lock()
|
done = thread.allocate_lock()
|
||||||
|
@ -56,7 +56,7 @@ def test_main(): # magic name! see above
|
||||||
import imp
|
import imp
|
||||||
if imp.lock_held():
|
if imp.lock_held():
|
||||||
# This triggers on, e.g., from test import autotest.
|
# This triggers on, e.g., from test import autotest.
|
||||||
raise TestSkipped("can't run when import lock is held")
|
raise unittest.SkipTest("can't run when import lock is held")
|
||||||
|
|
||||||
done.acquire()
|
done.acquire()
|
||||||
for N in (20, 50) * 3:
|
for N in (20, 50) * 3:
|
||||||
|
|
|
@ -5,10 +5,10 @@ import _thread as thread
|
||||||
import signal
|
import signal
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from test.support import run_unittest, TestSkipped
|
from test.support import run_unittest
|
||||||
|
|
||||||
if sys.platform[:3] in ('win', 'os2'):
|
if sys.platform[:3] in ('win', 'os2') or sys.platform=='riscos':
|
||||||
raise TestSkipped("Can't test signal on %s" % sys.platform)
|
raise unittest.SkipTest("Can't test signal on %s" % sys.platform)
|
||||||
|
|
||||||
process_pid = os.getpid()
|
process_pid = os.getpid()
|
||||||
signalled_all=thread.allocate_lock()
|
signalled_all=thread.allocate_lock()
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
import tkinter
|
import tkinter
|
||||||
from tkinter.test import runtktests
|
from tkinter.test import runtktests
|
||||||
from test import support
|
from test import support
|
||||||
|
import unittest
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tkinter.Button()
|
tkinter.Button()
|
||||||
except tkinter.TclError as msg:
|
except tkinter.TclError as msg:
|
||||||
# assuming tk is not available
|
# assuming tk is not available
|
||||||
raise support.TestSkipped("tk not available: %s" % msg)
|
raise unittest.SkipTest("tk not available: %s" % msg)
|
||||||
|
|
||||||
def test_main(enable_gui=False):
|
def test_main(enable_gui=False):
|
||||||
if enable_gui:
|
if enable_gui:
|
||||||
|
|
|
@ -2,6 +2,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
from tkinter.test import runtktests
|
from tkinter.test import runtktests
|
||||||
|
import unittest
|
||||||
from _tkinter import TclError
|
from _tkinter import TclError
|
||||||
from test import support
|
from test import support
|
||||||
|
|
||||||
|
@ -9,7 +10,7 @@ try:
|
||||||
ttk.Button()
|
ttk.Button()
|
||||||
except TclError as msg:
|
except TclError as msg:
|
||||||
# assuming ttk is not available
|
# assuming ttk is not available
|
||||||
raise support.TestSkipped("ttk not available: %s" % msg)
|
raise unittest.SkipTest("ttk not available: %s" % msg)
|
||||||
|
|
||||||
def test_main(enable_gui=False):
|
def test_main(enable_gui=False):
|
||||||
if enable_gui:
|
if enable_gui:
|
||||||
|
|
|
@ -5,14 +5,14 @@ import os, glob, time, shutil
|
||||||
import unicodedata
|
import unicodedata
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from test.support import run_unittest, TestSkipped, TESTFN_UNICODE, rmtree
|
from test.support import run_unittest, TESTFN_UNICODE, rmtree
|
||||||
from test.support import TESTFN_ENCODING, TESTFN_UNICODE_UNENCODEABLE
|
from test.support import TESTFN_ENCODING, TESTFN_UNICODE_UNENCODEABLE
|
||||||
try:
|
try:
|
||||||
TESTFN_UNICODE.encode(TESTFN_ENCODING)
|
TESTFN_UNICODE.encode(TESTFN_ENCODING)
|
||||||
except (UnicodeError, TypeError):
|
except (UnicodeError, TypeError):
|
||||||
# Either the file system encoding is None, or the file name
|
# Either the file system encoding is None, or the file name
|
||||||
# cannot be encoded in the file system encoding.
|
# cannot be encoded in the file system encoding.
|
||||||
raise TestSkipped("No Unicode filesystem semantics on this platform")
|
raise unittest.SkipTest("No Unicode filesystem semantics on this platform.")
|
||||||
|
|
||||||
def remove_if_exists(filename):
|
def remove_if_exists(filename):
|
||||||
if os.path.exists(filename):
|
if os.path.exists(filename):
|
||||||
|
|
|
@ -2304,7 +2304,7 @@ class Test_TestSkipping(TestCase):
|
||||||
def test_skipping(self):
|
def test_skipping(self):
|
||||||
class Foo(unittest.TestCase):
|
class Foo(unittest.TestCase):
|
||||||
def test_skip_me(self):
|
def test_skip_me(self):
|
||||||
self.skip("skip")
|
self.skipTest("skip")
|
||||||
events = []
|
events = []
|
||||||
result = LoggingResult(events)
|
result = LoggingResult(events)
|
||||||
test = Foo("test_skip_me")
|
test = Foo("test_skip_me")
|
||||||
|
@ -2315,7 +2315,7 @@ class Test_TestSkipping(TestCase):
|
||||||
# Try letting setUp skip the test now.
|
# Try letting setUp skip the test now.
|
||||||
class Foo(unittest.TestCase):
|
class Foo(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.skip("testing")
|
self.skipTest("testing")
|
||||||
def test_nothing(self): pass
|
def test_nothing(self): pass
|
||||||
events = []
|
events = []
|
||||||
result = LoggingResult(events)
|
result = LoggingResult(events)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import sys
|
||||||
from test import support
|
from test import support
|
||||||
|
|
||||||
if not hasattr(sys.stdin, 'newlines'):
|
if not hasattr(sys.stdin, 'newlines'):
|
||||||
raise support.TestSkipped(
|
raise unittest.SkipTest(
|
||||||
"This Python does not have universal newline support")
|
"This Python does not have universal newline support")
|
||||||
|
|
||||||
FATX = 'x' * (2**14)
|
FATX = 'x' * (2**14)
|
||||||
|
|
|
@ -3,18 +3,19 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
import unittest
|
||||||
from test.fork_wait import ForkWait
|
from test.fork_wait import ForkWait
|
||||||
from test.support import TestSkipped, run_unittest, reap_children
|
from test.support import run_unittest, reap_children
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.fork
|
os.fork
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise TestSkipped("os.fork not defined -- skipping test_wait3")
|
raise unittest.SkipTest("os.fork not defined -- skipping test_wait3")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.wait3
|
os.wait3
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise TestSkipped("os.wait3 not defined -- skipping test_wait3")
|
raise unittest.SkipTest("os.wait3 not defined -- skipping test_wait3")
|
||||||
|
|
||||||
class Wait3Test(ForkWait):
|
class Wait3Test(ForkWait):
|
||||||
def wait_impl(self, cpid):
|
def wait_impl(self, cpid):
|
||||||
|
|
|
@ -4,17 +4,17 @@
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
from test.fork_wait import ForkWait
|
from test.fork_wait import ForkWait
|
||||||
from test.support import TestSkipped, run_unittest, reap_children
|
from test.support import run_unittest, reap_children
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.fork
|
os.fork
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise TestSkipped("os.fork not defined -- skipping test_wait4")
|
raise unittest.SkipTest("os.fork not defined -- skipping test_wait4")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.wait4
|
os.wait4
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise TestSkipped("os.wait4 not defined -- skipping test_wait4")
|
raise unittest.SkipTest("os.wait4 not defined -- skipping test_wait4")
|
||||||
|
|
||||||
class Wait4Test(ForkWait):
|
class Wait4Test(ForkWait):
|
||||||
def wait_impl(self, cpid):
|
def wait_impl(self, cpid):
|
||||||
|
|
|
@ -274,6 +274,8 @@ def format_exc(limit=None, chain=True):
|
||||||
def print_last(limit=None, file=None, chain=True):
|
def print_last(limit=None, file=None, chain=True):
|
||||||
"""This is a shorthand for 'print_exception(sys.last_type,
|
"""This is a shorthand for 'print_exception(sys.last_type,
|
||||||
sys.last_value, sys.last_traceback, limit, file)'."""
|
sys.last_value, sys.last_traceback, limit, file)'."""
|
||||||
|
if not hasattr(sys, "last_type"):
|
||||||
|
raise ValueError("no last exception")
|
||||||
if file is None:
|
if file is None:
|
||||||
file = sys.stderr
|
file = sys.stderr
|
||||||
print_exception(sys.last_type, sys.last_value, sys.last_traceback,
|
print_exception(sys.last_type, sys.last_value, sys.last_traceback,
|
||||||
|
|
|
@ -373,14 +373,14 @@ class TestCase(object):
|
||||||
result.addSkip(self, str(e))
|
result.addSkip(self, str(e))
|
||||||
return
|
return
|
||||||
except Exception:
|
except Exception:
|
||||||
result.addError(self, self._exc_info())
|
result.addError(self, sys.exc_info())
|
||||||
return
|
return
|
||||||
|
|
||||||
success = False
|
success = False
|
||||||
try:
|
try:
|
||||||
testMethod()
|
testMethod()
|
||||||
except self.failureException:
|
except self.failureException:
|
||||||
result.addFailure(self, self._exc_info())
|
result.addFailure(self, sys.exc_info())
|
||||||
except _ExpectedFailure as e:
|
except _ExpectedFailure as e:
|
||||||
result.addExpectedFailure(self, e.exc_info)
|
result.addExpectedFailure(self, e.exc_info)
|
||||||
except _UnexpectedSuccess:
|
except _UnexpectedSuccess:
|
||||||
|
@ -388,14 +388,14 @@ class TestCase(object):
|
||||||
except SkipTest as e:
|
except SkipTest as e:
|
||||||
result.addSkip(self, str(e))
|
result.addSkip(self, str(e))
|
||||||
except Exception:
|
except Exception:
|
||||||
result.addError(self, self._exc_info())
|
result.addError(self, sys.exc_info())
|
||||||
else:
|
else:
|
||||||
success = True
|
success = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.tearDown()
|
self.tearDown()
|
||||||
except Exception:
|
except Exception:
|
||||||
result.addError(self, self._exc_info())
|
result.addError(self, sys.exc_info())
|
||||||
success = False
|
success = False
|
||||||
if success:
|
if success:
|
||||||
result.addSuccess(self)
|
result.addSuccess(self)
|
||||||
|
@ -411,14 +411,7 @@ class TestCase(object):
|
||||||
getattr(self, self._testMethodName)()
|
getattr(self, self._testMethodName)()
|
||||||
self.tearDown()
|
self.tearDown()
|
||||||
|
|
||||||
def _exc_info(self):
|
def skipTest(self, reason):
|
||||||
"""Return a version of sys.exc_info() with the traceback frame
|
|
||||||
minimised; usually the top level of the traceback frame is not
|
|
||||||
needed.
|
|
||||||
"""
|
|
||||||
return sys.exc_info()
|
|
||||||
|
|
||||||
def skip(self, reason):
|
|
||||||
"""Skip this test."""
|
"""Skip this test."""
|
||||||
raise SkipTest(reason)
|
raise SkipTest(reason)
|
||||||
|
|
||||||
|
@ -830,7 +823,8 @@ class _WritelnDecorator(object):
|
||||||
return getattr(self.stream,attr)
|
return getattr(self.stream,attr)
|
||||||
|
|
||||||
def writeln(self, arg=None):
|
def writeln(self, arg=None):
|
||||||
if arg: self.write(arg)
|
if arg:
|
||||||
|
self.write(arg)
|
||||||
self.write('\n') # text-mode streams translate to \r\n if needed
|
self.write('\n') # text-mode streams translate to \r\n if needed
|
||||||
|
|
||||||
|
|
||||||
|
@ -899,7 +893,7 @@ class _TextTestResult(TestResult):
|
||||||
if self.showAll:
|
if self.showAll:
|
||||||
self.stream.writeln("expected failure")
|
self.stream.writeln("expected failure")
|
||||||
elif self.dots:
|
elif self.dots:
|
||||||
self.stream.write(".")
|
self.stream.write("x")
|
||||||
self.stream.flush()
|
self.stream.flush()
|
||||||
|
|
||||||
def addUnexpectedSuccess(self, test):
|
def addUnexpectedSuccess(self, test):
|
||||||
|
@ -907,7 +901,7 @@ class _TextTestResult(TestResult):
|
||||||
if self.showAll:
|
if self.showAll:
|
||||||
self.stream.writeln("unexpected success")
|
self.stream.writeln("unexpected success")
|
||||||
elif self.dots:
|
elif self.dots:
|
||||||
self.stream.write(".")
|
self.stream.write("u")
|
||||||
self.stream.flush()
|
self.stream.flush()
|
||||||
|
|
||||||
def printErrors(self):
|
def printErrors(self):
|
||||||
|
@ -964,7 +958,7 @@ class TextTestRunner(object):
|
||||||
if errored:
|
if errored:
|
||||||
infos.append("errors=%d" % errored)
|
infos.append("errors=%d" % errored)
|
||||||
else:
|
else:
|
||||||
self.stream.writeln("OK")
|
self.stream.write("OK")
|
||||||
if skipped:
|
if skipped:
|
||||||
infos.append("skipped=%d" % skipped)
|
infos.append("skipped=%d" % skipped)
|
||||||
if expectedFails:
|
if expectedFails:
|
||||||
|
@ -973,6 +967,8 @@ class TextTestRunner(object):
|
||||||
infos.append("unexpected successes=%d" % unexpectedSuccesses)
|
infos.append("unexpected successes=%d" % unexpectedSuccesses)
|
||||||
if infos:
|
if infos:
|
||||||
self.stream.writeln(" (%s)" % (", ".join(infos),))
|
self.stream.writeln(" (%s)" % (", ".join(infos),))
|
||||||
|
else:
|
||||||
|
self.stream.write("\n")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue