summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_smtplib.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-04-27 23:55:59 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-04-27 23:55:59 (GMT)
commit6a10281d3359de890519c23d0318742018c843a3 (patch)
tree71fdda13733f42f287602b72b60260cdc9afa6ba /Lib/test/test_smtplib.py
parentc73a05f775013980a2a0de1c2a65b8542ee0bfa6 (diff)
downloadcpython-6a10281d3359de890519c23d0318742018c843a3.zip
cpython-6a10281d3359de890519c23d0318742018c843a3.tar.gz
cpython-6a10281d3359de890519c23d0318742018c843a3.tar.bz2
Issue #7449, last part (11): fix many tests if thread support is disabled
* Use try/except ImportError or test_support.import_module() to import thread and threading modules * Add @unittest.skipUnless(threading, ...) to testcases using threads
Diffstat (limited to 'Lib/test/test_smtplib.py')
-rw-r--r--Lib/test/test_smtplib.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py
index 9a492f6..977a152 100644
--- a/Lib/test/test_smtplib.py
+++ b/Lib/test/test_smtplib.py
@@ -1,7 +1,6 @@
import asyncore
import email.utils
import socket
-import threading
import smtpd
import smtplib
import StringIO
@@ -9,9 +8,14 @@ import sys
import time
import select
-from unittest import TestCase
+import unittest
from test import test_support
+try:
+ import threading
+except ImportError:
+ threading = None
+
HOST = test_support.HOST
def server(evt, buf, serv):
@@ -36,7 +40,8 @@ def server(evt, buf, serv):
serv.close()
evt.set()
-class GeneralTests(TestCase):
+@unittest.skipUnless(threading, 'Threading required for this test.')
+class GeneralTests(unittest.TestCase):
def setUp(self):
self._threads = test_support.threading_setup()
@@ -138,7 +143,8 @@ MSG_END = '------------ END MESSAGE ------------\n'
# test server times out, causing the test to fail.
# Test behavior of smtpd.DebuggingServer
-class DebuggingServerTests(TestCase):
+@unittest.skipUnless(threading, 'Threading required for this test.')
+class DebuggingServerTests(unittest.TestCase):
def setUp(self):
# temporarily replace sys.stdout to capture DebuggingServer output
@@ -233,7 +239,7 @@ class DebuggingServerTests(TestCase):
self.assertEqual(self.output.getvalue(), mexpect)
-class NonConnectingTests(TestCase):
+class NonConnectingTests(unittest.TestCase):
def testNotConnected(self):
# Test various operations on an unconnected SMTP object that
@@ -254,7 +260,8 @@ class NonConnectingTests(TestCase):
# test response of client to a non-successful HELO message
-class BadHELOServerTests(TestCase):
+@unittest.skipUnless(threading, 'Threading required for this test.')
+class BadHELOServerTests(unittest.TestCase):
def setUp(self):
self.old_stdout = sys.stdout
@@ -378,7 +385,8 @@ class SimSMTPServer(smtpd.SMTPServer):
# Test various SMTP & ESMTP commands/behaviors that require a simulated server
# (i.e., something with more features than DebuggingServer)
-class SMTPSimTests(TestCase):
+@unittest.skipUnless(threading, 'Threading required for this test.')
+class SMTPSimTests(unittest.TestCase):
def setUp(self):
self._threads = test_support.threading_setup()