diff options
author | Eric V. Smith <eric@trueblade.com> | 2012-05-25 15:25:27 (GMT) |
---|---|---|
committer | Eric V. Smith <eric@trueblade.com> | 2012-05-25 15:25:27 (GMT) |
commit | f879e32cc5bde58efe42ce5260de1a21e25dae73 (patch) | |
tree | 2a44cf4e392abcccab750c27cd8e845d2e7f46d1 /Lib/test/test_namespace_pkgs.py | |
parent | 739ae5692ebc7daaf1297d8e775e552bdb05f3fe (diff) | |
download | cpython-f879e32cc5bde58efe42ce5260de1a21e25dae73.zip cpython-f879e32cc5bde58efe42ce5260de1a21e25dae73.tar.gz cpython-f879e32cc5bde58efe42ce5260de1a21e25dae73.tar.bz2 |
Added test for namespace package dynamic path updates.
Diffstat (limited to 'Lib/test/test_namespace_pkgs.py')
-rw-r--r-- | Lib/test/test_namespace_pkgs.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Lib/test/test_namespace_pkgs.py b/Lib/test/test_namespace_pkgs.py index 176ddd3..02b5528 100644 --- a/Lib/test/test_namespace_pkgs.py +++ b/Lib/test/test_namespace_pkgs.py @@ -206,6 +206,51 @@ class LegacySupport(NamespacePackageTest): self.assertNotIn('namespace', str(foo.__loader__).lower()) +class DynamicPathCalculation(NamespacePackageTest): + paths = ['project1', 'project2'] + + def test_project3_fails(self): + import parent.child.one + self.assertEqual(len(parent.__path__), 2) + self.assertEqual(len(parent.child.__path__), 2) + import parent.child.two + self.assertEqual(len(parent.__path__), 2) + self.assertEqual(len(parent.child.__path__), 2) + + self.assertEqual(parent.child.one.attr, 'parent child one') + self.assertEqual(parent.child.two.attr, 'parent child two') + + with self.assertRaises(ImportError): + import parent.child.three + + self.assertEqual(len(parent.__path__), 2) + self.assertEqual(len(parent.child.__path__), 2) + + def test_project3_succeeds(self): + import parent.child.one + self.assertEqual(len(parent.__path__), 2) + self.assertEqual(len(parent.child.__path__), 2) + import parent.child.two + self.assertEqual(len(parent.__path__), 2) + self.assertEqual(len(parent.child.__path__), 2) + + self.assertEqual(parent.child.one.attr, 'parent child one') + self.assertEqual(parent.child.two.attr, 'parent child two') + + with self.assertRaises(ImportError): + import parent.child.three + + # now add project3 + sys.path.append(os.path.join(self.root, 'project3')) + import parent.child.three + + # the paths dynamically get longer, to include the new directories + self.assertEqual(len(parent.__path__), 3) + self.assertEqual(len(parent.child.__path__), 3) + + self.assertEqual(parent.child.three.attr, 'parent child three') + + class ZipWithMissingDirectory(NamespacePackageTest): paths = ['missing_directory.zip'] |