bpo-40275: Move TransientResource to test_urllib2net by vstinner · Pull Request #20812 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions Doc/library/test.rst
35 changes: 0 additions & 35 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
raise ImportError('support must be imported from the test package')

import contextlib
import errno
import functools
import os
import re
Expand Down Expand Up @@ -49,7 +48,6 @@
"is_resource_enabled", "requires", "requires_freebsd_version",
"requires_linux_version", "requires_mac_ver",
"check_syntax_error",
"TransientResource", "time_out", "socket_peer_reset", "ioerror_peer_reset",
"BasicTestRunner", "run_unittest", "run_doctest",
"requires_gzip", "requires_bz2", "requires_lzma",
"bigmemtest", "bigaddrspacetest", "cpython_only", "get_attribute",
Expand Down Expand Up @@ -551,39 +549,6 @@ def check_valid_file(fn):
raise TestFailed('invalid resource %r' % fn)


class TransientResource(object):

"""Raise ResourceDenied if an exception is raised while the context manager
is in effect that matches the specified exception and attributes."""

def __init__(self, exc, **kwargs):
self.exc = exc
self.attrs = kwargs

def __enter__(self):
return self

def __exit__(self, type_=None, value=None, traceback=None):
"""If type_ is a subclass of self.exc and value has attributes matching
self.attrs, raise ResourceDenied. Otherwise let the exception
propagate (if any)."""
if type_ is not None and issubclass(self.exc, type_):
for attr, attr_value in self.attrs.items():
if not hasattr(value, attr):
break
if getattr(value, attr) != attr_value:
break
else:
raise ResourceDenied("an optional resource is not available")

# Context managers that raise ResourceDenied when various issues
# with the Internet connection manifest themselves as exceptions.
# XXX deprecate these and use transient_internet() instead
time_out = TransientResource(OSError, errno=errno.ETIMEDOUT)
socket_peer_reset = TransientResource(OSError, errno=errno.ECONNRESET)
ioerror_peer_reset = TransientResource(OSError, errno=errno.ECONNRESET)


@contextlib.contextmanager
def captured_output(stream_name):
"""Return a context manager used by captured_stdout/stdin/stderr
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,6 @@ def test_print_warning(self):
# findfile
# check_warnings
# EnvironmentVarGuard
# TransientResource
# transient_internet
# run_with_locale
# set_memlimit
Expand Down
40 changes: 37 additions & 3 deletions Lib/test/test_urllib2net.py