-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-59022: add tests to extend_path #12871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0a20b16
6a0db9f
61d3986
ee762ab
ef7b10d
ff565e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -489,6 +489,61 @@ def test_mixed_namespace(self): | |||||
# XXX: test .pkg files | ||||||
|
||||||
|
||||||
class ExtendPathBaseTests(unittest.TestCase): | ||||||
def test_input_type_invalid(self): | ||||||
# path should be list instead of string | ||||||
path = 'path' | ||||||
name = 'foo' | ||||||
self.assertEqual('path', pkgutil.extend_path(path, name)) | ||||||
|
||||||
def test_parent_package_raise_key_error(self): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's nothing here making sure |
||||||
path = ['path'] | ||||||
# sys.modules['foo'] raise KeyError | ||||||
name = 'foo.bar' | ||||||
self.assertEqual(['path'], pkgutil.extend_path(path, name)) | ||||||
|
||||||
def test_parent_package_raise_attr_error(self): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name doesn't match what seems to be tested. |
||||||
path = ['path'] | ||||||
# module 'datetime' has no attribute '__path__' | ||||||
name = 'datetime.date' | ||||||
self.assertEqual(['path'], pkgutil.extend_path(path, name)) | ||||||
|
||||||
def test_extend_path_files(self): | ||||||
# create foo/bar.py | ||||||
self.dirname = tempfile.mkdtemp() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no cleanup of the temporary directory. |
||||||
sys.path.insert(0, self.dirname) | ||||||
package_name = "foo" | ||||||
package_path = os.path.join(self.dirname, package_name) | ||||||
os.mkdir(package_path) | ||||||
f = open(os.path.join(package_path, 'bar.py'), "w") | ||||||
f.close() | ||||||
Comment on lines
+518
to
+519
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a context manager and write a comment in the file as to the purpose of the file existing. |
||||||
# Search valid or invalid module | ||||||
import foo | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will leave |
||||||
path = [foo.__path__] | ||||||
name = 'foo' | ||||||
self.assertEqual([path[0], package_path], pkgutil.extend_path(path, name)) | ||||||
name = 'other' | ||||||
self.assertEqual(path, pkgutil.extend_path(path, name)) | ||||||
del sys.path[0] | ||||||
|
||||||
def test_extend_pkg_files(self): | ||||||
self.dirname = tempfile.mkdtemp() | ||||||
sys.path.insert(0, self.dirname) | ||||||
package_name = "foo" | ||||||
package_path = os.path.join(self.dirname, package_name) | ||||||
sys.path.insert(1, package_path) | ||||||
os.mkdir(package_path) | ||||||
f = open(os.path.join(package_path, 'bar.pkg'), "w") | ||||||
f.write('foo\nbar\n#other\n') | ||||||
f.close() | ||||||
# Search valid or invalid module | ||||||
import foo | ||||||
path = [foo.__path__] | ||||||
self.assertEqual([path[0], 'foo', 'bar'], pkgutil.extend_path(path, 'bar')) | ||||||
del sys.path[0] | ||||||
del sys.path[1] | ||||||
|
||||||
|
||||||
class NestedNamespacePackageTest(unittest.TestCase): | ||||||
|
||||||
def setUp(self): | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add tests for :class:`pkgutil.extend_path`. Patch by Windson Yang. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments should be complete sentences.