diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-11-18 17:29:23 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-11-18 17:29:23 (GMT) |
commit | de609186fc85b8cfcdc689cb7d5b4319d0e51e35 (patch) | |
tree | 0a5e219b68a690440271234b39daeef34e98386d /Lib/test/test_nntplib.py | |
parent | 6a0b5c414cacbf04fd73fc598720a4fc20ec4fc9 (diff) | |
download | cpython-de609186fc85b8cfcdc689cb7d5b4319d0e51e35.zip cpython-de609186fc85b8cfcdc689cb7d5b4319d0e51e35.tar.gz cpython-de609186fc85b8cfcdc689cb7d5b4319d0e51e35.tar.bz2 |
Wrap all test_nntplib methods accessing a remote server in a transient_internet()
exception catcher. Wrapping the initial connection routine is not sufficient
as network timeouts can then occur as part of NNTP commands.
Diffstat (limited to 'Lib/test/test_nntplib.py')
-rw-r--r-- | Lib/test/test_nntplib.py | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/Lib/test/test_nntplib.py b/Lib/test/test_nntplib.py index 97179cf..13bb505 100644 --- a/Lib/test/test_nntplib.py +++ b/Lib/test/test_nntplib.py @@ -2,7 +2,9 @@ import io import datetime import textwrap import unittest +import functools import contextlib +import collections from test import support from nntplib import NNTP, GroupInfo, _have_ssl import nntplib @@ -228,6 +230,28 @@ class NetworkedNNTPTestsMixin: self.server.quit() cls.server = None + @classmethod + def wrap_methods(cls): + # Wrap all methods in a transient_internet() exception catcher + # XXX put a generic version in test.support? + def wrap_meth(meth): + @functools.wraps(meth) + def wrapped(self): + with support.transient_internet(self.NNTP_HOST): + meth(self) + return wrapped + for name in dir(cls): + if not name.startswith('test_'): + continue + meth = getattr(cls, name) + if not isinstance(meth, collections.Callable): + continue + # Need to use a closure so that meth remains bound to its current + # value + setattr(cls, name, wrap_meth(meth)) + +NetworkedNNTPTestsMixin.wrap_methods() + class NetworkedNNTPTests(NetworkedNNTPTestsMixin, unittest.TestCase): # This server supports STARTTLS (gmane doesn't) @@ -235,11 +259,13 @@ class NetworkedNNTPTests(NetworkedNNTPTestsMixin, unittest.TestCase): GROUP_NAME = 'fr.comp.lang.python' GROUP_PAT = 'fr.comp.lang.*' + NNTP_CLASS = NNTP + @classmethod def setUpClass(cls): support.requires("network") with support.transient_internet(cls.NNTP_HOST): - cls.server = NNTP(cls.NNTP_HOST, timeout=TIMEOUT, usenetrc=False) + cls.server = cls.NNTP_CLASS(cls.NNTP_HOST, timeout=TIMEOUT, usenetrc=False) @classmethod def tearDownClass(cls): @@ -248,7 +274,7 @@ class NetworkedNNTPTests(NetworkedNNTPTestsMixin, unittest.TestCase): if _have_ssl: - class NetworkedNNTP_SSLTests(NetworkedNNTPTestsMixin, unittest.TestCase): + class NetworkedNNTP_SSLTests(NetworkedNNTPTests): # Technical limits for this public NNTP server (see http://www.aioe.org): # "Only two concurrent connections per IP address are allowed and @@ -258,17 +284,7 @@ if _have_ssl: GROUP_NAME = 'comp.lang.python' GROUP_PAT = 'comp.lang.*' - @classmethod - def setUpClass(cls): - support.requires("network") - with support.transient_internet(cls.NNTP_HOST): - cls.server = nntplib.NNTP_SSL(cls.NNTP_HOST, timeout=TIMEOUT, - usenetrc=False) - - @classmethod - def tearDownClass(cls): - if cls.server is not None: - cls.server.quit() + NNTP_CLASS = nntplib.NNTP_SSL # Disabled as it produces too much data test_list = None |