mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-59022: Added tests for pkgutil.extend_path
(#59022) (GH-121673)
This adds tests for the documented behaviour of `pkgutil.extend_path` regarding different argument types as well as for `*.pkg` files.
This commit is contained in:
parent
263c7e611b
commit
8f2532168b
3 changed files with 41 additions and 4 deletions
|
@ -522,7 +522,43 @@ class ExtendPathTests(unittest.TestCase):
|
|||
del sys.modules['foo.bar']
|
||||
del sys.modules['foo.baz']
|
||||
|
||||
# XXX: test .pkg files
|
||||
|
||||
def test_extend_path_argument_types(self):
|
||||
pkgname = 'foo'
|
||||
dirname_0 = self.create_init(pkgname)
|
||||
|
||||
# If the input path is not a list it is returned unchanged
|
||||
self.assertEqual('notalist', pkgutil.extend_path('notalist', 'foo'))
|
||||
self.assertEqual(('not', 'a', 'list'), pkgutil.extend_path(('not', 'a', 'list'), 'foo'))
|
||||
self.assertEqual(123, pkgutil.extend_path(123, 'foo'))
|
||||
self.assertEqual(None, pkgutil.extend_path(None, 'foo'))
|
||||
|
||||
# Cleanup
|
||||
shutil.rmtree(dirname_0)
|
||||
del sys.path[0]
|
||||
|
||||
|
||||
def test_extend_path_pkg_files(self):
|
||||
pkgname = 'foo'
|
||||
dirname_0 = self.create_init(pkgname)
|
||||
|
||||
with open(os.path.join(dirname_0, 'bar.pkg'), 'w') as pkg_file:
|
||||
pkg_file.write('\n'.join([
|
||||
'baz',
|
||||
'/foo/bar/baz',
|
||||
'',
|
||||
'#comment'
|
||||
]))
|
||||
|
||||
extended_paths = pkgutil.extend_path(sys.path, 'bar')
|
||||
|
||||
self.assertEqual(extended_paths[:-2], sys.path)
|
||||
self.assertEqual(extended_paths[-2], 'baz')
|
||||
self.assertEqual(extended_paths[-1], '/foo/bar/baz')
|
||||
|
||||
# Cleanup
|
||||
shutil.rmtree(dirname_0)
|
||||
del sys.path[0]
|
||||
|
||||
|
||||
class NestedNamespacePackageTest(unittest.TestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue