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

Skip to content

Commit c9a1bfe

Browse files
committed
Move test___all__ over to unittest.main() and use ModuleNotFoundError
1 parent 603dcf2 commit c9a1bfe

5 files changed

Lines changed: 21 additions & 24 deletions

File tree

Lib/test/regrtest.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@
146146

147147
try:
148148
import threading
149-
except ImportError:
149+
except ModuleNotFoundError:
150150
threading = None
151151
try:
152152
import multiprocessing.process
153-
except ImportError:
153+
except ModuleNotFoundError:
154154
multiprocessing = None
155155

156156

@@ -180,7 +180,7 @@
180180
if sys.platform == 'darwin':
181181
try:
182182
import resource
183-
except ImportError:
183+
except ModuleNotFoundError:
184184
pass
185185
else:
186186
soft, hard = resource.getrlimit(resource.RLIMIT_STACK)
@@ -571,7 +571,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
571571
if findleaks:
572572
try:
573573
import gc
574-
except ImportError:
574+
except ModuleNotFoundError:
575575
print('No GC available, disabling findleaks.')
576576
findleaks = False
577577
else:
@@ -692,7 +692,7 @@ def test_forever(tests=list(selected)):
692692
if use_mp:
693693
try:
694694
from threading import Thread
695-
except ImportError:
695+
except ModuleNotFoundError:
696696
print("Multiprocess option requires thread support")
697697
sys.exit(2)
698698
from queue import Queue
@@ -1396,7 +1396,7 @@ def dash_R(the_module, test, indirect_test, huntrleaks):
13961396
pic = sys.path_importer_cache.copy()
13971397
try:
13981398
import zipimport
1399-
except ImportError:
1399+
except ModuleNotFoundError:
14001400
zdc = None # Run unmodified on platforms without zipimport support
14011401
else:
14021402
zdc = zipimport._zip_directory_cache.copy()
@@ -1473,7 +1473,7 @@ def dash_R_cleanup(fs, ps, pic, zdc, abcs):
14731473
sys.path_importer_cache.update(pic)
14741474
try:
14751475
import zipimport
1476-
except ImportError:
1476+
except ModuleNotFoundError:
14771477
pass # Run unmodified on platforms without zipimport support
14781478
else:
14791479
zipimport._zip_directory_cache.clear()
@@ -1510,7 +1510,7 @@ def dash_R_cleanup(fs, ps, pic, zdc, abcs):
15101510
doctest.master = None
15111511
try:
15121512
import ctypes
1513-
except ImportError:
1513+
except ModuleNotFoundError:
15141514
# Don't worry about resetting the cache if ctypes is not supported
15151515
pass
15161516
else:

Lib/test/support.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,27 @@
2929

3030
try:
3131
import _thread, threading
32-
except ImportError:
32+
except ModuleNotFoundError:
3333
_thread = None
3434
threading = None
3535
try:
3636
import multiprocessing.process
37-
except ImportError:
37+
except ModuleNotFoundError:
3838
multiprocessing = None
3939

4040
try:
4141
import zlib
42-
except ImportError:
42+
except ModuleNotFoundError:
4343
zlib = None
4444

4545
try:
4646
import bz2
47-
except ImportError:
47+
except ModuleNotFoundError:
4848
bz2 = None
4949

5050
try:
5151
import lzma
52-
except ImportError:
52+
except ModuleNotFoundError:
5353
lzma = None
5454

5555
__all__ = [
@@ -116,7 +116,7 @@ def import_module(name, deprecated=False, *, required_on=()):
116116
with _ignore_deprecated_imports(deprecated):
117117
try:
118118
return importlib.import_module(name)
119-
except ImportError as msg:
119+
except ModuleNotFoundError as msg:
120120
if sys.platform.startswith(tuple(required_on)):
121121
raise
122122
raise unittest.SkipTest(str(msg))
@@ -188,7 +188,7 @@ def import_fresh_module(name, fresh=(), blocked=(), deprecated=False):
188188
if not _save_and_block_module(blocked_name, orig_modules):
189189
names_to_remove.append(blocked_name)
190190
fresh_module = importlib.import_module(name)
191-
except ImportError:
191+
except ModuleNotFoundError:
192192
fresh_module = None
193193
finally:
194194
for orig_name, module in orig_modules.items():

Lib/test/test___all__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_all(self):
7575
try:
7676
import rlcompleter
7777
import locale
78-
except ImportError:
78+
except ModuleNotFoundError:
7979
pass
8080
else:
8181
locale.setlocale(locale.LC_CTYPE, 'C')
@@ -113,8 +113,5 @@ def test_all(self):
113113
print('Following modules failed to be imported:', failed_imports)
114114

115115

116-
def test_main():
117-
support.run_unittest(AllTest)
118-
119116
if __name__ == "__main__":
120-
test_main()
117+
unittest.main()

Lib/xmlrpc/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def export_add(self, x, y):
116116
import traceback
117117
try:
118118
import fcntl
119-
except ImportError:
119+
except ModuleNotFoundError:
120120
fcntl = None
121121

122122
def resolve_dotted_attribute(obj, attr, allow_dotted_names=True):

Lib/zipfile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@
1818
try:
1919
import zlib # We may need its compression method
2020
crc32 = zlib.crc32
21-
except ImportError:
21+
except ModuleNotFoundError:
2222
zlib = None
2323
crc32 = binascii.crc32
2424

2525
try:
2626
import bz2 # We may need its compression method
27-
except ImportError:
27+
except ModuleNotFoundError:
2828
bz2 = None
2929

3030
try:
3131
import lzma # We may need its compression method
32-
except ImportError:
32+
except ModuleNotFoundError:
3333
lzma = None
3434

3535
__all__ = ["BadZipFile", "BadZipfile", "error",

0 commit comments

Comments
 (0)