import unittest from test import audiotests import io import struct import sys from test.support import warnings_helper sunau = warnings_helper.import_deprecated("sunau") audioop = warnings_helper.import_deprecated("audioop") class SunauTest(audiotests.AudioWriteTests, audiotests.AudioTestsWithSourceFile): module = sunau class SunauPCM8Test(SunauTest, unittest.TestCase): sndfilename = 'pluck-pcm8.au' sndfilenframes = 3307 nchannels = 2 sampwidth = 1 framerate = 11025 nframes = 48 comptype = 'NONE' compname = 'not compressed' frames = bytes.fromhex("""\ 02FF 4B00 3104 8008 CB06 4803 BF01 03FE B8FA B4F3 29EB 1AE6 \ EDE4 C6E2 0EE0 EFE0 57E2 FBE8 13EF D8F7 97FB F5FC 08FB DFFB \ 11FA 3EFB BCFC 66FF CF04 4309 C10E 5112 EE17 8216 7F14 8012 \ 490E 520D EF0F CE0F E40C 630A 080A 2B0B 510E 8B11 B60E 440A \ """)
import copy import os import sys import test.support import unittest from test.support import os_helper from test.support import warnings_helper mailcap = warnings_helper.import_deprecated('mailcap') # Location of mailcap file MAILCAPFILE = test.support.findfile("mailcap.txt") # Dict to act as mock mailcap entry for this test # The keys and values should match the contents of MAILCAPFILE MAILCAPDICT = { 'application/x-movie': [{'compose': 'moviemaker %s', 'x11-bitmap': '"/usr/lib/Zmail/bitmaps/movie.xbm"', 'description': '"Movie"', 'view': 'movieplayer %s', 'lineno': 4}], 'application/*': [{'copiousoutput': '', 'view': 'echo "This is \\"%t\\" but is 50 \\% Greek to me" \\; cat %s', 'lineno': 5}], 'audio/basic': [{'edit': 'audiocompose %s', 'compose': 'audiocompose %s',
from test.support.os_helper import temp_dir from test.support.script_helper import assert_python_failure from test.support.warnings_helper import import_deprecated import unittest import sys cgitb = import_deprecated("cgitb") class TestCgitb(unittest.TestCase): def test_fonts(self): text = "Hello Robbie!" self.assertEqual(cgitb.small(text), "<small>{}</small>".format(text)) self.assertEqual(cgitb.strong(text), "<strong>{}</strong>".format(text)) self.assertEqual(cgitb.grey(text), '<font color="#909090">{}</font>'.format(text)) def test_blanks(self): self.assertEqual(cgitb.small(""), "") self.assertEqual(cgitb.strong(""), "") self.assertEqual(cgitb.grey(""), "") def test_html(self): try: raise ValueError("Hello World") except ValueError as err: # If the html was templated we could do a bit more here. # At least check that we get details on what we just raised. html = cgitb.html(sys.exc_info()) self.assertIn("ValueError", html) self.assertIn(str(err), html)
from test import support from test.support import import_helper, warnings_helper import warnings support.requires('audio') from test.support import findfile with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) ossaudiodev = import_helper.import_module('ossaudiodev') audioop = warnings_helper.import_deprecated('audioop') sunau = warnings_helper.import_deprecated('sunau') import errno import sys import time import unittest # Arggh, AFMT_S16_NE not defined on all platforms -- seems to be a # fairly recent addition to OSS. try: from ossaudiodev import AFMT_S16_NE except ImportError: if sys.byteorder == "little": AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE def read_sound_file(path): with open(path, 'rb') as fp:
import pickle import unittest from test.support import findfile from test.support import warnings_helper sndhdr = warnings_helper.import_deprecated("sndhdr") class TestFormats(unittest.TestCase): def test_data(self): for filename, expected in ( ('sndhdr.8svx', ('8svx', 0, 1, 0, 8)), ('sndhdr.aifc', ('aifc', 44100, 2, 5, 16)), ('sndhdr.aiff', ('aiff', 44100, 2, 5, 16)), ('sndhdr.au', ('au', 44100, 2, 5.0, 16)), ('sndhdr.hcom', ('hcom', 22050.0, 1, -1, 8)), ('sndhdr.sndt', ('sndt', 44100, 1, 5, 8)), ('sndhdr.voc', ('voc', 0, 1, -1, 8)), ('sndhdr.wav', ('wav', 44100, 2, 5, 16)), ): filename = findfile(filename, subdir="sndhdrdata") what = sndhdr.what(filename) self.assertNotEqual(what, None, filename) self.assertSequenceEqual(what, expected) self.assertEqual(what.filetype, expected[0]) self.assertEqual(what.framerate, expected[1]) self.assertEqual(what.nchannels, expected[2]) self.assertEqual(what.nframes, expected[3]) self.assertEqual(what.sampwidth, expected[4]) def test_pickleable(self):
import unittest import textwrap from test import support, mock_socket from test.support import socket_helper from test.support import warnings_helper import socket import io smtpd = warnings_helper.import_deprecated('smtpd') asyncore = warnings_helper.import_deprecated('asyncore') class DummyServer(smtpd.SMTPServer): def __init__(self, *args, **kwargs): smtpd.SMTPServer.__init__(self, *args, **kwargs) self.messages = [] if self._decode_data: self.return_status = 'return status' else: self.return_status = b'return status' def process_message(self, peer, mailfrom, rcpttos, data, **kw): self.messages.append((peer, mailfrom, rcpttos, data)) if data == self.return_status: return '250 Okish' if 'mail_options' in kw and 'SMTPUTF8' in kw['mail_options']: return '250 SMTPUTF8 message okish' class DummyDispatcherBroken(Exception): pass
import socket import selectors import threading import contextlib from test import support from test.support import socket_helper, warnings_helper import unittest support.requires_working_socket(module=True) telnetlib = warnings_helper.import_deprecated('telnetlib') HOST = socket_helper.HOST def server(evt, serv): serv.listen() evt.set() try: conn, addr = serv.accept() conn.close() except TimeoutError: pass finally: serv.close() class GeneralTests(unittest.TestCase): def setUp(self): self.evt = threading.Event()
import time import unittest try: import ssl except ImportError: ssl = None from unittest import TestCase, skipUnless from test import support from test.support import threading_helper from test.support import socket_helper from test.support import warnings_helper from test.support.socket_helper import HOST, HOSTv6 asynchat = warnings_helper.import_deprecated('asynchat') asyncore = warnings_helper.import_deprecated('asyncore') support.requires_working_socket(module=True) TIMEOUT = support.LOOPBACK_TIMEOUT DEFAULT_ENCODING = 'utf-8' # the dummy data returned by server over the data channel when # RETR, LIST, NLST, MLSD commands are issued RETR_DATA = 'abcde12345\r\n' * 1000 + 'non-ascii char \xAE\r\n' LIST_DATA = 'foo\r\nbar\r\n non-ascii char \xAE\r\n' NLST_DATA = 'foo\r\nbar\r\n non-ascii char \xAE\r\n' MLSD_DATA = ("type=cdir;perm=el;unique==keVO1+ZF4; test\r\n" "type=pdir;perm=e;unique==keVO1+d?3; ..\r\n" "type=OS.unix=slink:/foobar;perm=;unique==keVO1+4G4; foobar\r\n"
import os import string import unittest import shutil from test.support import reap_children, unix_shell from test.support.os_helper import TESTFN, unlink from test.support.warnings_helper import import_deprecated pipes = import_deprecated("pipes") if os.name != 'posix': raise unittest.SkipTest('pipes module only works on posix') if not (unix_shell and os.path.exists(unix_shell)): raise unittest.SkipTest('pipes module requires a shell') TESTFN2 = TESTFN + "2" # tr a-z A-Z is not portable, so make the ranges explicit s_command = 'tr %s %s' % (string.ascii_lowercase, string.ascii_uppercase) class SimplePipeTests(unittest.TestCase): def tearDown(self): for f in (TESTFN, TESTFN2): unlink(f) def testSimplePipe1(self): if shutil.which('tr') is None: self.skipTest('tr is not available') t = pipes.Template()
import io import os import pathlib import unittest import warnings from test.support import findfile, warnings_helper from test.support.os_helper import TESTFN, unlink imghdr = warnings_helper.import_deprecated("imghdr") TEST_FILES = ( ('python.png', 'png'), ('python.gif', 'gif'), ('python.bmp', 'bmp'), ('python.ppm', 'ppm'), ('python.pgm', 'pgm'), ('python.pbm', 'pbm'), ('python.jpg', 'jpeg'), ('python-raw.jpg', 'jpeg'), # raw JPEG without JFIF/EXIF markers ('python.ras', 'rast'), ('python.sgi', 'rgb'), ('python.tiff', 'tiff'), ('python.xbm', 'xbm'), ('python.webp', 'webp'), ('python.exr', 'exr'), ) class UnseekableIO(io.FileIO): def tell(self): raise io.UnsupportedOperation
from test.support import findfile from test.support.os_helper import TESTFN, unlink from test.support.warnings_helper import check_no_resource_warning, import_deprecated import unittest from unittest import mock from test import audiotests import io import sys import struct aifc = import_deprecated("aifc") audioop = import_deprecated("audioop") class AifcTest(audiotests.AudioWriteTests, audiotests.AudioTestsWithSourceFile): module = aifc close_fd = True test_unseekable_read = None class AifcPCM8Test(AifcTest, unittest.TestCase): sndfilename = 'pluck-pcm8.aiff' sndfilenframes = 3307 nchannels = 2 sampwidth = 1 framerate = 11025 nframes = 48 comptype = b'NONE' compname = b'not compressed' frames = bytes.fromhex("""\
import sys import unittest from test.support import check_sanitizer, warnings_helper try: if check_sanitizer(address=True, memory=True): raise unittest.SkipTest( "The crypt module SEGFAULTs on ASAN/MSAN builds") crypt = warnings_helper.import_deprecated("crypt") IMPORT_ERROR = None except ImportError as ex: if sys.platform != 'win32': raise unittest.SkipTest(str(ex)) crypt = None IMPORT_ERROR = str(ex) @unittest.skipUnless(sys.platform == 'win32', 'This should only run on windows') @unittest.skipIf(crypt, 'import succeeded') class TestWhyCryptDidNotImport(unittest.TestCase): def test_import_failure_message(self): self.assertIn('not supported', IMPORT_ERROR) @unittest.skipUnless(crypt, 'crypt module is required') class CryptTestCase(unittest.TestCase): def test_crypt(self): cr = crypt.crypt('mypassword') cr2 = crypt.crypt('mypassword', cr) self.assertEqual(cr2, cr)
import importlib import importlib.util import os import os.path import py_compile import sys from test import support from test.support import import_helper from test.support import os_helper from test.support import script_helper from test.support import warnings_helper import unittest import warnings imp = warnings_helper.import_deprecated('imp') import _imp OS_PATH_NAME = os.path.__name__ def requires_load_dynamic(meth): """Decorator to skip a test if not running under CPython or lacking imp.load_dynamic().""" meth = support.cpython_only(meth) return unittest.skipIf( getattr(imp, 'load_dynamic', None) is None, 'imp.load_dynamic() required')(meth) class LockTests(unittest.TestCase): """Very basic test of import lock functions.""" def verify_lock_state(self, expected):
""" Tests for uu module. Nick Mathewson """ import unittest from test.support import os_helper, warnings_helper uu = warnings_helper.import_deprecated("uu") import os import stat import sys import io plaintext = b"The symbols on top of your keyboard are !@#$%^&*()_+|~\n" encodedtext = b"""\ M5&AE('-Y;6)O;',@;VX@=&]P(&]F('EO=7(@:V5Y8F]A<F0@87)E("% (R0E *7B8J*"E?*WQ^"@ """ # Stolen from io.py class FakeIO(io.TextIOWrapper): """Text I/O implementation using an in-memory buffer. Can be a used as a drop-in replacement for sys.stdin and sys.stdout. """ # XXX This is really slow, but fully functional
import unittest from test.support import warnings_helper xdrlib = warnings_helper.import_deprecated("xdrlib") class XDRTest(unittest.TestCase): def test_xdr(self): p = xdrlib.Packer() s = b'hello world' a = [b'what', b'is', b'hapnin', b'doctor'] p.pack_int(42) p.pack_int(-17) p.pack_uint(9) p.pack_bool(True) p.pack_bool(False) p.pack_uhyper(45) p.pack_float(1.9) p.pack_double(1.9) p.pack_string(s) p.pack_list(range(5), p.pack_uint) p.pack_array(a, p.pack_string) # now verify data = p.get_buffer() up = xdrlib.Unpacker(data) self.assertEqual(up.get_position(), 0)