cpython: c22ec7a45114 (original) (raw)
Mercurial > cpython
changeset 101292:c22ec7a45114
Fixes #19711: Add tests for reloading namespace packages. [#19711]
Eric Snow ericsnowcurrently@gmail.com | |
---|---|
date | Tue, 10 May 2016 15:29:05 -0600 |
parents | 909099686e6e |
children | 3c75707045f5 |
files | Lib/test/test_importlib/test_namespace_pkgs.py Misc/NEWS |
diffstat | 2 files changed, 35 insertions(+), 1 deletions(-)[+] [-] Lib/test/test_importlib/test_namespace_pkgs.py 34 Misc/NEWS 2 |
line wrap: on
line diff
--- a/Lib/test/test_importlib/test_namespace_pkgs.py +++ b/Lib/test/test_importlib/test_namespace_pkgs.py @@ -1,4 +1,5 @@ import contextlib +import importlib import os import sys import unittest @@ -67,6 +68,7 @@ class NamespacePackageTest(unittest.Test # TODO: will we ever want to pass exc_info to exit? self.ctx.exit(None, None, None) + class SingleNamespacePackage(NamespacePackageTest): paths = ['portion1'] @@ -83,7 +85,7 @@ class SingleNamespacePackage(NamespacePa self.assertEqual(repr(foo), "<module 'foo' (namespace)>") -class DynamicPatheNamespacePackage(NamespacePackageTest): +class DynamicPathNamespacePackage(NamespacePackageTest): paths = ['portion1'] def test_dynamic_path(self): @@ -285,5 +287,35 @@ class ModuleAndNamespacePackageInSameDir self.assertEqual(a_test.attr, 'in module') +class ReloadTests(NamespacePackageTest):
- def test_simple_package(self):
import foo.one[](#l1.34)
foo = importlib.reload(foo)[](#l1.35)
self.assertEqual(foo.one.attr, 'portion1 foo one')[](#l1.36)
- def test_cant_import_other(self):
import foo[](#l1.39)
with self.assertRaises(ImportError):[](#l1.40)
import foo.two[](#l1.41)
foo = importlib.reload(foo)[](#l1.42)
with self.assertRaises(ImportError):[](#l1.43)
import foo.two[](#l1.44)
- def test_dynamic_path(self):
import foo.one[](#l1.47)
with self.assertRaises(ImportError):[](#l1.48)
import foo.two[](#l1.49)
# Now modify sys.path and reload.[](#l1.51)
sys.path.append(os.path.join(self.root, 'portion2'))[](#l1.52)
foo = importlib.reload(foo)[](#l1.53)
# And make sure foo.two is now importable[](#l1.55)
import foo.two[](#l1.56)
self.assertEqual(foo.two.attr, 'portion2 foo two')[](#l1.57)
+ + if name == "main": unittest.main()
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -52,6 +52,8 @@ Core and Builtins
- 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. +- Issue #19711: Add tests for reloading namespace packages. +
- 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 holding the GIL.