mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Issue #13959: Have
importlib.abc.FileLoader.load_module()/get_filename() and importlib.machinery.ExtensionFileLoader.load_module() have their single argument be optional as the loader's constructor has all the ncessary information. This allows for the deprecation of imp.load_source()/load_compile()/load_package().
This commit is contained in:
parent
0c59b039b8
commit
c049952de7
9 changed files with 2485 additions and 2392 deletions
|
|
@ -1,11 +1,12 @@
|
|||
import imp
|
||||
import importlib
|
||||
import os
|
||||
import os.path
|
||||
import shutil
|
||||
import sys
|
||||
import unittest
|
||||
from test import support
|
||||
import importlib
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
class LockTests(unittest.TestCase):
|
||||
|
||||
|
|
@ -154,18 +155,24 @@ class ImportTests(unittest.TestCase):
|
|||
mod = imp.load_module(temp_mod_name, file, filename, info)
|
||||
self.assertEqual(mod.a, 1)
|
||||
|
||||
mod = imp.load_source(temp_mod_name, temp_mod_name + '.py')
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore')
|
||||
mod = imp.load_source(temp_mod_name, temp_mod_name + '.py')
|
||||
self.assertEqual(mod.a, 1)
|
||||
|
||||
mod = imp.load_compiled(
|
||||
temp_mod_name, imp.cache_from_source(temp_mod_name + '.py'))
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore')
|
||||
mod = imp.load_compiled(
|
||||
temp_mod_name, imp.cache_from_source(temp_mod_name + '.py'))
|
||||
self.assertEqual(mod.a, 1)
|
||||
|
||||
if not os.path.exists(test_package_name):
|
||||
os.mkdir(test_package_name)
|
||||
with open(init_file_name, 'w') as file:
|
||||
file.write('b = 2\n')
|
||||
package = imp.load_package(test_package_name, test_package_name)
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore')
|
||||
package = imp.load_package(test_package_name, test_package_name)
|
||||
self.assertEqual(package.b, 2)
|
||||
finally:
|
||||
del sys.path[0]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue