Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Unified Diff: Lib/test/support.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/test/regrtest.py ('k') | Lib/test/test_ast.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/test/support.py Tue Jul 26 09:37:46 2011 +0300
+++ b/Lib/test/support.py Mon Jul 25 09:47:18 2011 -0400
@@ -24,15 +24,9 @@
import logging.handlers
try:
- import _thread, threading
+ import _thread
except ImportError:
_thread = None
- threading = None
-try:
- import multiprocessing.process
-except ImportError:
- multiprocessing = None
-
try:
import zlib
@@ -46,7 +40,7 @@
"is_resource_enabled", "requires", "requires_linux_version",
"requires_mac_ver", "find_unused_port", "bind_port",
"IPV6_ENABLED", "is_jython", "TESTFN", "HOST", "SAVEDCWD", "temp_cwd",
- "findfile", "create_empty_file", "sortdict", "check_syntax_error", "open_urlresource",
+ "findfile", "sortdict", "check_syntax_error", "open_urlresource",
"check_warnings", "CleanImport", "EnvironmentVarGuard", "TransientResource",
"captured_stdout", "captured_stdin", "captured_stderr", "time_out",
"socket_peer_reset", "ioerror_peer_reset", "run_with_locale", 'temp_umask',
@@ -55,7 +49,7 @@
"threading_cleanup", "reap_children", "cpython_only", "check_impl_detail",
"get_attribute", "swap_item", "swap_attr", "requires_IEEE_754",
"TestHandler", "Matcher", "can_symlink", "skip_unless_symlink",
- "import_fresh_module", "requires_zlib", "PIPE_MAX_SIZE", "failfast",
+ "import_fresh_module", "requires_zlib", "PIPE_MAX_SIZE"
]
class Error(Exception):
@@ -170,7 +164,7 @@
attribute = getattr(obj, name)
except AttributeError:
raise unittest.SkipTest("module %s has no attribute %s" % (
- repr(obj), name))
+ obj.__name__, name))
else:
return attribute
@@ -179,7 +173,6 @@
max_memuse = 0 # Disable bigmem tests (they will still be run with
# small sizes, to make sure they work.)
real_max_memuse = 0
-failfast = False
# _original_stdout is meant to hold stdout at the time regrtest began.
# This may be "the real" stdout, or IDLE's emulation of stdout, or whatever.
@@ -296,7 +289,7 @@
return
if not is_resource_enabled(resource):
if msg is None:
- msg = "Use of the %r resource not enabled" % resource
+ msg = "Use of the `%s' resource not enabled" % resource
raise ResourceDenied(msg)
def requires_linux_version(*min_version):
@@ -578,15 +571,14 @@
rmtree(name)
-if hasattr(os, "umask"):
- @contextlib.contextmanager
- def temp_umask(umask):
- """Context manager that temporarily sets the process umask."""
- oldmask = os.umask(umask)
- try:
- yield
- finally:
- os.umask(oldmask)
+@contextlib.contextmanager
+def temp_umask(umask):
+ """Context manager that temporarily sets the process umask."""
+ oldmask = os.umask(umask)
+ try:
+ yield
+ finally:
+ os.umask(oldmask)
def findfile(file, here=__file__, subdir=None):
@@ -604,11 +596,6 @@
if os.path.exists(fn): return fn
return file
-def create_empty_file(filename):
- """Create an empty file. If the file already exists, truncate it."""
- fd = os.open(filename, os.O_WRONLY | os.O_CREAT | os.O_TRUNC)
- os.close(fd)
-
def sortdict(dict):
"Like repr(dict), but in sorted order."
items = sorted(dict.items())
@@ -673,7 +660,7 @@
f = check_valid_file(fn)
if f is not None:
return f
- raise TestFailed('invalid resource %r' % fn)
+ raise TestFailed('invalid resource "%s"' % fn)
class WarningsRecorder(object):
@@ -917,14 +904,13 @@
('ETIMEDOUT', 110),
]
default_gai_errnos = [
- ('EAI_AGAIN', -3),
('EAI_NONAME', -2),
('EAI_NODATA', -5),
# Encountered when trying to resolve IPv6-only hostnames
('WSANO_DATA', 11004),
]
- denied = ResourceDenied("Resource %r is not available" % resource_name)
+ denied = ResourceDenied("Resource '%s' is not available" % resource_name)
captured_errnos = errnos
gai_errnos = []
if not captured_errnos:
@@ -1013,16 +999,6 @@
gc.collect()
gc.collect()
-@contextlib.contextmanager
-def disable_gc():
- have_gc = gc.isenabled()
- gc.disable()
- try:
- yield
- finally:
- if have_gc:
- gc.enable()
-
def python_is_optimized():
"""Find if Python was built with optimizations."""
@@ -1031,7 +1007,7 @@
for opt in cflags.split():
if opt.startswith('-O'):
final_opt = opt
- return final_opt != '' and final_opt != '-O0'
+ return final_opt and final_opt != '-O0'
#=======================================================================
@@ -1271,8 +1247,7 @@
def _run_suite(suite):
"""Run tests from a unittest.TestSuite-derived class."""
if verbose:
- runner = unittest.TextTestRunner(sys.stdout, verbosity=2,
- failfast=failfast)
+ runner = unittest.TextTestRunner(sys.stdout, verbosity=2)
else:
runner = BasicTestRunner()
@@ -1323,9 +1298,16 @@
else:
verbosity = None
- f, t = doctest.testmod(module, verbose=verbosity)
- if f:
- raise TestFailed("%d of %d doctests failed" % (f, t))
+ # Direct doctest output (normally just errors) to real stdout; doctest
+ # output shouldn't be compared by regrtest.
+ save_stdout = sys.stdout
+ sys.stdout = get_original_stdout()
+ try:
+ f, t = doctest.testmod(module, verbose=verbosity)
+ if f:
+ raise TestFailed("%d of %d doctests failed" % (f, t))
+ finally:
+ sys.stdout = save_stdout
if verbose:
print('doctest (%s) ... %d tests with zero failures' %
(module.__name__, t))
@@ -1367,20 +1349,19 @@
def threading_setup():
if _thread:
- return _thread._count(), threading._dangling.copy()
+ return _thread._count(),
else:
- return 1, ()
+ return 1,
-def threading_cleanup(*original_values):
+def threading_cleanup(nb_threads):
if not _thread:
return
_MAX_COUNT = 10
for count in range(_MAX_COUNT):
- values = _thread._count(), threading._dangling
- if values == original_values:
+ n = _thread._count()
+ if n == nb_threads:
break
time.sleep(0.1)
- gc_collect()
# XXX print a warning in case of failure?
def reap_threads(func):
« no previous file with comments | « Lib/test/regrtest.py ('k') | Lib/test/test_ast.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+