Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9b027d4

Browse files
authored
gh-92169: Use warnings_helper.import_deprecated() to import deprecated modules uniformly in tests (GH-92170)
1 parent c1767fc commit 9b027d4

File tree

10 files changed

+33
-41
lines changed

10 files changed

+33
-41
lines changed

Lib/test/test_asynchat.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from test import support
44
from test.support import socket_helper
55
from test.support import threading_helper
6+
from test.support import warnings_helper
67

78
import errno
89
import socket
@@ -12,11 +13,9 @@
1213
import unittest
1314
import unittest.mock
1415

15-
import warnings
16-
with warnings.catch_warnings():
17-
warnings.simplefilter('ignore', DeprecationWarning)
18-
import asynchat
19-
import asyncore
16+
17+
asynchat = warnings_helper.import_deprecated('asynchat')
18+
asyncore = warnings_helper.import_deprecated('asyncore')
2019

2120
support.requires_working_socket(module=True)
2221

Lib/test/test_asyncore.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020

2121
support.requires_working_socket(module=True)
2222

23-
import warnings
24-
with warnings.catch_warnings():
25-
warnings.simplefilter('ignore', DeprecationWarning)
26-
import asyncore
23+
asyncore = warnings_helper.import_deprecated('asyncore')
2724

2825

2926
HAS_UNIX_SOCKETS = hasattr(socket, 'AF_UNIX')

Lib/test/test_ftplib.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@
2323
from test.support import warnings_helper
2424
from test.support.socket_helper import HOST, HOSTv6
2525

26-
import warnings
27-
with warnings.catch_warnings():
28-
warnings.simplefilter('ignore', DeprecationWarning)
29-
import asyncore
30-
import asynchat
26+
27+
asynchat = warnings_helper.import_deprecated('asynchat')
28+
asyncore = warnings_helper.import_deprecated('asyncore')
29+
3130

3231
support.requires_working_socket(module=True)
3332

Lib/test/test_imp.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
from test.support import import_helper
99
from test.support import os_helper
1010
from test.support import script_helper
11+
from test.support import warnings_helper
1112
import unittest
1213
import warnings
13-
with warnings.catch_warnings():
14-
warnings.simplefilter('ignore', DeprecationWarning)
15-
import imp
14+
imp = warnings_helper.import_deprecated('imp')
1615
import _imp
1716

1817

Lib/test/test_logging.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@
6060
from socketserver import (ThreadingUDPServer, DatagramRequestHandler,
6161
ThreadingTCPServer, StreamRequestHandler)
6262

63-
with warnings.catch_warnings():
64-
warnings.simplefilter('ignore', DeprecationWarning)
65-
import asyncore
66-
import smtpd
63+
64+
asyncore = warnings_helper.import_deprecated('asyncore')
65+
smtpd = warnings_helper.import_deprecated('smtpd')
66+
6767

6868
try:
6969
import win32evtlog, win32evtlogutil, pywintypes

Lib/test/test_poplib.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
from test.support import hashlib_helper
1616
from test.support import socket_helper
1717
from test.support import threading_helper
18+
from test.support import warnings_helper
19+
20+
21+
asynchat = warnings_helper.import_deprecated('asynchat')
22+
asyncore = warnings_helper.import_deprecated('asyncore')
1823

19-
import warnings
20-
with warnings.catch_warnings():
21-
warnings.simplefilter('ignore', DeprecationWarning)
22-
import asynchat
23-
import asyncore
2424

2525
test_support.requires_working_socket(module=True)
2626

Lib/test/test_smtpd.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
import socket
77
import io
88

9-
import warnings
10-
with warnings.catch_warnings():
11-
warnings.simplefilter('ignore', DeprecationWarning)
12-
import smtpd
13-
import asyncore
9+
10+
smtpd = warnings_helper.import_deprecated('smtpd')
11+
asyncore = warnings_helper.import_deprecated('asyncore')
1412

1513

1614
class DummyServer(smtpd.SMTPServer):

Lib/test/test_smtplib.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
from test.support import hashlib_helper
2222
from test.support import socket_helper
2323
from test.support import threading_helper
24+
from test.support import warnings_helper
2425
from unittest.mock import Mock
2526

26-
import warnings
27-
with warnings.catch_warnings():
28-
warnings.simplefilter('ignore', DeprecationWarning)
29-
import asyncore
30-
import smtpd
27+
28+
asyncore = warnings_helper.import_deprecated('asyncore')
29+
smtpd = warnings_helper.import_deprecated('smtpd')
30+
3131

3232
support.requires_working_socket(module=True)
3333

Lib/test/test_ssl.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import socket
1313
import select
1414
import time
15-
import datetime
1615
import enum
1716
import gc
1817
import os
@@ -30,10 +29,9 @@
3029
except ImportError:
3130
ctypes = None
3231

33-
import warnings
34-
with warnings.catch_warnings():
35-
warnings.simplefilter('ignore', DeprecationWarning)
36-
import asyncore
32+
33+
asyncore = warnings_helper.import_deprecated('asyncore')
34+
3735

3836
ssl = import_helper.import_module("ssl")
3937
import _ssl
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Use ``warnings_helper.import_deprecated()`` to import deprecated modules
2+
uniformly in tests. Patch by Hugo van Kemenade.

0 commit comments

Comments
 (0)