10000 Add test_lazy_import for pickle, mimetypes, base64, csv, pprint and s… · python/cpython@34e39ab · GitHub
[go: up one dir, main page]

Skip to content

Commit 34e39ab

Browse files
committed
Add test_lazy_import for pickle, mimetypes, base64, csv, pprint and socket modules
1 parent 875e0bd commit 34e39ab

File tree

7 files changed

+44
-5
lines changed

7 files changed

+44
-5
lines changed

Lib/test/test_base64.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@
33
import binascii
44
import os
55
from array import array
6+
from test.support import cpython_only
67
from test.support import os_helper
78
from test.support import script_helper
9+
from test.support.import_helper import ensure_lazy_imports
10+
11+
12+
class LazyImportTest(unittest.TestCase):
13+
@cpython_only
14+
def test_lazy_import(self):
15+
ensure_lazy_imports("base64", {"re"})
816

917

1018
class LegacyBase64TestCase(unittest.TestCase):

Lib/test/test_csv.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import gc
1111
import pickle
1212
from test import support
13-
from test.support import import_helper, check_disallow_instantiation
13+
from test.support import cpython_only, import_helper, check_disallow_instantiation
14+
from test.support.import_helper import ensure_lazy_imports
1415
from itertools import permutations
1516
from textwrap import dedent
1617
from collections import OrderedDict
@@ -1565,6 +1566,10 @@ class MiscTestCase(unittest.TestCase):
15651566
def test__all__(self):
15661567
support.check__all__(self, csv, ('csv', '_csv'))
15671568

1569+
@cpython_only
1570+
def test_lazy_import(self):
1571+
ensure_lazy_imports("csv", {"re"})
1572+
15681573
def test_subclassable(self):
15691574
# issue 44089
15701575
class Foo(csv.Error): ...

Lib/test/test_mimetypes.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import unittest.mock
77
from platform import win32_edition
88
from test import support
9-
from test.support import os_helper
9+
from test.support import cpython_only, os_helper
10+
from test.support.import_helper import ensure_lazy_imports
1011
from test.support.script_helper import run_python_until_end
1112

1213
try:
@@ -409,6 +410,10 @@ class MiscTestCase(unittest.TestCase):
409410
def test__all__(self):
410411
support.check__all__(self, mimetypes)
411412

413+
@cpython_only
414+
def test_lazy_import(self):
415+
ensure_lazy_imports("mimetypes", {"os", "posixpath", "urllib.parse"})
416+
412417

413418
class CommandLineTest(unittest.TestCase):
414419
def test_parse_args(self):

Lib/test/test_pathlib/test_pathlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_is_notimplemented(self):
8181
self.assertTrue(isinstance(pathlib.UnsupportedOperation(), NotImplementedError))
8282

8383

84-
class TestImportTime(unittest.TestCase):
84+
class LazyImportTest(unittest.TestCase):
8585
@cpython_only
8686
def test_lazy_import(self):
8787
import_helper.ensure_lazy_imports("pathlib", {"shutil"})

Lib/test/test_pickle.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
import doctest
1616
import unittest
1717
from test import support
18-
from test.support import import_helper, os_helper
18+
from test.support import cpython_only, import_helper, os_helper
19+
from test.support.import_helper import ensure_lazy_imports
1920

2021
from test.pickletester import AbstractHookTests
2122
from test.pickletester import AbstractUnpickleTests
@@ -36,6 +37,12 @@
3637
has_c_implementation = False
3738

3839

40+
class LazyImportTest(unittest.TestCase):
41+
@cpython_only
42+
def test_lazy_import(self):
43+
ensure_lazy_imports("pickle", {"re"})
44+
45+
3946
class PyPickleTests(AbstractPickleModuleTests, unittest.TestCase):
4047
dump = staticmethod(pickle._dump)
4148
dumps = staticmethod(pickle._dumps)

Lib/test/test_pprint.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import types
1212
import unittest
1313

14+
from test.support import cpython_only
15+
from test.support.import_helper import ensure_lazy_imports
16+
1417
# list, tuple and dict subclasses that do or don't overwrite __repr__
1518
class list2(list):
1619
pass
@@ -129,6 +132,10 @@ def setUp(self):
129132
self.b = list(range(200))
130133
self.a[-12] = self.b
131134

135+
@cpython_only
136+
def test_lazy_import(self):
137+
ensure_lazy_imports("pprint", {"dataclasses", "re"})
138+
132139
def test_init(self):
133140
pp = pprint.PrettyPrinter()
134141
pp = pprint.PrettyPrinter(indent=4, width=40, depth=5,

Lib/test/test_socket.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
from unittest import mock
33
from test import support
44
from test.support import (
5-
is_apple, os_helper, refleak_helper, socket_helper, threading_helper
5 A23C +
cpython_only, is_apple, os_helper, refleak_helper, socket_helper, threading_helper
66
)
7+
from test.support.import_helper import ensure_lazy_imports
78
import _thread as thread
89
import array
910
import contextlib
@@ -257,6 +258,12 @@ def downgrade_malformed_data_warning():
257258
# Size in bytes of the int type
258259
SIZEOF_INT = array.array("i").itemsize
259260

261+
class TestLazyImport(unittest.TestCase):
262+
@cpython_only
263+
def test_lazy_import(self):
264+
ensure_lazy_imports("socket", {"array", "selectors"})
265+
266+
260267
class SocketTCPTest(unittest.TestCase):
261268

262269
def setUp(self):

0 commit comments

Comments
 (0)
0