mirror of https://github.com/python/cpython
Fixes #19711: Add tests for reloading namespace packages.
This commit is contained in:
parent
c499f30286
commit
d65018b17c
|
@ -1,4 +1,5 @@
|
||||||
import contextlib
|
import contextlib
|
||||||
|
import importlib
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -67,6 +68,7 @@ class NamespacePackageTest(unittest.TestCase):
|
||||||
# TODO: will we ever want to pass exc_info to __exit__?
|
# TODO: will we ever want to pass exc_info to __exit__?
|
||||||
self.ctx.__exit__(None, None, None)
|
self.ctx.__exit__(None, None, None)
|
||||||
|
|
||||||
|
|
||||||
class SingleNamespacePackage(NamespacePackageTest):
|
class SingleNamespacePackage(NamespacePackageTest):
|
||||||
paths = ['portion1']
|
paths = ['portion1']
|
||||||
|
|
||||||
|
@ -83,7 +85,7 @@ class SingleNamespacePackage(NamespacePackageTest):
|
||||||
self.assertEqual(repr(foo), "<module 'foo' (namespace)>")
|
self.assertEqual(repr(foo), "<module 'foo' (namespace)>")
|
||||||
|
|
||||||
|
|
||||||
class DynamicPatheNamespacePackage(NamespacePackageTest):
|
class DynamicPathNamespacePackage(NamespacePackageTest):
|
||||||
paths = ['portion1']
|
paths = ['portion1']
|
||||||
|
|
||||||
def test_dynamic_path(self):
|
def test_dynamic_path(self):
|
||||||
|
@ -285,5 +287,35 @@ class ModuleAndNamespacePackageInSameDir(NamespacePackageTest):
|
||||||
self.assertEqual(a_test.attr, 'in module')
|
self.assertEqual(a_test.attr, 'in module')
|
||||||
|
|
||||||
|
|
||||||
|
class ReloadTests(NamespacePackageTest):
|
||||||
|
paths = ['portion1']
|
||||||
|
|
||||||
|
def test_simple_package(self):
|
||||||
|
import foo.one
|
||||||
|
foo = importlib.reload(foo)
|
||||||
|
self.assertEqual(foo.one.attr, 'portion1 foo one')
|
||||||
|
|
||||||
|
def test_cant_import_other(self):
|
||||||
|
import foo
|
||||||
|
with self.assertRaises(ImportError):
|
||||||
|
import foo.two
|
||||||
|
foo = importlib.reload(foo)
|
||||||
|
with self.assertRaises(ImportError):
|
||||||
|
import foo.two
|
||||||
|
|
||||||
|
def test_dynamic_path(self):
|
||||||
|
import foo.one
|
||||||
|
with self.assertRaises(ImportError):
|
||||||
|
import foo.two
|
||||||
|
|
||||||
|
# Now modify sys.path and reload.
|
||||||
|
sys.path.append(os.path.join(self.root, 'portion2'))
|
||||||
|
foo = importlib.reload(foo)
|
||||||
|
|
||||||
|
# And make sure foo.two is now importable
|
||||||
|
import foo.two
|
||||||
|
self.assertEqual(foo.two.attr, 'portion2 foo two')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -52,6 +52,8 @@ Core and Builtins
|
||||||
- Issue #26581: If coding cookie is specified multiple times on a line in
|
- Issue #26581: If coding cookie is specified multiple times on a line in
|
||||||
Python source code file, only the first one is taken to account.
|
Python source code file, only the first one is taken to account.
|
||||||
|
|
||||||
|
- Issue #19711: Add tests for reloading namespace packages.
|
||||||
|
|
||||||
- Issue #26563: Debug hooks on Python memory allocators now raise a fatal
|
- Issue #26563: Debug hooks on Python memory allocators now raise a fatal
|
||||||
error if functions of the :c:func:`PyMem_Malloc` family are called without
|
error if functions of the :c:func:`PyMem_Malloc` family are called without
|
||||||
holding the GIL.
|
holding the GIL.
|
||||||
|
|
Loading…
Reference in New Issue