summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_nntplib.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-11-03 19:31:38 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-11-03 19:31:38 (GMT)
commit43767638a9590689fd8bcd1fcedd15bbe4660856 (patch)
tree8e96e92a7d1e7af2a20aaa15c9383e0d570acacc /Lib/test/test_nntplib.py
parent7a07cc90c73b5a5587536c2f3fc5c2909b59be39 (diff)
downloadcpython-43767638a9590689fd8bcd1fcedd15bbe4660856.zip
cpython-43767638a9590689fd8bcd1fcedd15bbe4660856.tar.gz
cpython-43767638a9590689fd8bcd1fcedd15bbe4660856.tar.bz2
Issue #18702: All skipped tests now reported as skipped.
Diffstat (limited to 'Lib/test/test_nntplib.py')
-rw-r--r--Lib/test/test_nntplib.py74
1 files changed, 38 insertions, 36 deletions
diff --git a/Lib/test/test_nntplib.py b/Lib/test/test_nntplib.py
index d00c9db..71a4ec0 100644
--- a/Lib/test/test_nntplib.py
+++ b/Lib/test/test_nntplib.py
@@ -6,10 +6,12 @@ import unittest
import functools
import contextlib
from test import support
-from nntplib import NNTP, GroupInfo, _have_ssl
+from nntplib import NNTP, GroupInfo
import nntplib
-if _have_ssl:
+try:
import ssl
+except ImportError:
+ ssl = None
TIMEOUT = 30
@@ -199,23 +201,23 @@ class NetworkedNNTPTestsMixin:
resp, caps = self.server.capabilities()
_check_caps(caps)
- if _have_ssl:
- def test_starttls(self):
- file = self.server.file
- sock = self.server.sock
- try:
- self.server.starttls()
- except nntplib.NNTPPermanentError:
- self.skipTest("STARTTLS not supported by server.")
- else:
- # Check that the socket and internal pseudo-file really were
- # changed.
- self.assertNotEqual(file, self.server.file)
- self.assertNotEqual(sock, self.server.sock)
- # Check that the new socket really is an SSL one
- self.assertIsInstance(self.server.sock, ssl.SSLSocket)
- # Check that trying starttls when it's already active fails.
- self.assertRaises(ValueError, self.server.starttls)
+ @unittest.skipUnless(ssl, 'requires SSL support')
+ def test_starttls(self):
+ file = self.server.file
+ sock = self.server.sock
+ try:
+ self.server.starttls()
+ except nntplib.NNTPPermanentError:
+ self.skipTest("STARTTLS not supported by server.")
+ else:
+ # Check that the socket and internal pseudo-file really were
+ # changed.
+ self.assertNotEqual(file, self.server.file)
+ self.assertNotEqual(sock, self.server.sock)
+ # Check that the new socket really is an SSL one
+ self.assertIsInstance(self.server.sock, ssl.SSLSocket)
+ # Check that trying starttls when it's already active fails.
+ self.assertRaises(ValueError, self.server.starttls)
def test_zlogin(self):
# This test must be the penultimate because further commands will be
@@ -300,25 +302,24 @@ class NetworkedNNTPTests(NetworkedNNTPTestsMixin, unittest.TestCase):
if cls.server is not None:
cls.server.quit()
+@unittest.skipUnless(ssl, 'requires SSL support')
+class NetworkedNNTP_SSLTests(NetworkedNNTPTests):
-if _have_ssl:
- 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
- # 400 connections per day are accepted from each IP address."
+ # Technical limits for this public NNTP server (see http://www.aioe.org):
+ # "Only two concurrent connections per IP address are allowed and
+ # 400 connections per day are accepted from each IP address."
- NNTP_HOST = 'nntp.aioe.org'
- GROUP_NAME = 'comp.lang.python'
- GROUP_PAT = 'comp.lang.*'
+ NNTP_HOST = 'nntp.aioe.org'
+ GROUP_NAME = 'comp.lang.python'
+ GROUP_PAT = 'comp.lang.*'
- NNTP_CLASS = nntplib.NNTP_SSL
+ NNTP_CLASS = getattr(nntplib, 'NNTP_SSL', None)
- # Disabled as it produces too much data
- test_list = None
+ # Disabled as it produces too much data
+ test_list = None
- # Disabled as the connection will already be encrypted.
- test_starttls = None
+ # Disabled as the connection will already be encrypted.
+ test_starttls = None
#
@@ -1407,12 +1408,13 @@ class MiscTests(unittest.TestCase):
gives(2000, 6, 23, "000623", "000000")
gives(2010, 6, 5, "100605", "000000")
+ @unittest.skipUnless(ssl, 'requires SSL support')
+ def test_ssl_support(self):
+ self.assertTrue(hasattr(nntplib, 'NNTP_SSL'))
def test_main():
tests = [MiscTests, NNTPv1Tests, NNTPv2Tests, CapsAfterLoginNNTPv2Tests,
- SendReaderNNTPv2Tests, NetworkedNNTPTests]
- if _have_ssl:
- tests.append(NetworkedNNTP_SSLTests)
+ SendReaderNNTPv2Tests, NetworkedNNTPTests, NetworkedNNTP_SSLTests]
support.run_unittest(*tests)