Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed
wants to merge 6 commits into from
Closed

Conversation

Windsooon
Copy link
Contributor

@Windsooon Windsooon commented Apr 18, 2019

Actually, there are some tests for extend_path already (see https://github.com/python/cpython/blob/master/Lib/test/test_pkgutil.py#L235). I add some tests for it anyway. However, I didn't test every line of the code in the extend_path function.

https://bugs.python.org/issue14817

@nanjekyejoannah
Copy link
Contributor

cc @ericvsmith

@arhadthedev arhadthedev changed the title bpo-14817: add tests to extend_path gh-59022: add tests to extend_path Feb 5, 2023
@arhadthedev
Copy link
Member

Would anybody mind to review and possibly merge this PR?

@arhadthedev
Copy link
Member

@vsajip, @brettcannon, could you review and possibly merge this PR, please? (as the ones who committed into Lib/test/test_pkgutil.py more than once last ten years and still active)

@brettcannon
Copy link
Member

I'm rather swamped right now, so it might be a while (especially since I want to deprecate the entire pkgutil module eventually 😁).

@brettcannon brettcannon self-requested a review April 12, 2023 18:31
Copy link
Member

@brettcannon brettcannon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests have some misleading names and they are not cleaning up after themselves appropriately.

@@ -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
Copy link
Member

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.

name = 'foo'
self.assertEqual('path', pkgutil.extend_path(path, name))

def test_parent_package_raise_key_error(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_parent_package_raise_key_error(self):
def test_parent_package_raises_key_error(self):

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's nothing here making sure KeyError is raised, so the name of the test is confusing.

name = 'foo.bar'
self.assertEqual(['path'], pkgutil.extend_path(path, name))

def test_parent_package_raise_attr_error(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name doesn't match what seems to be tested.


def test_extend_path_files(self):
# create foo/bar.py
self.dirname = tempfile.mkdtemp()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no cleanup of the temporary directory.

Comment on lines +518 to +519
f = open(os.path.join(package_path, 'bar.py'), "w")
f.close()
Copy link
Member

Choose a reason for hiding this comment

The 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.

f = open(os.path.join(package_path, 'bar.py'), "w")
f.close()
# Search valid or invalid module
import foo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will leave sys.modules dirty from this test. Use the helper functions in test.support to make sure this method cleans up after itself.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@erlend-aasland erlend-aasland added the pending The issue will be closed if no feedback is provided label Feb 9, 2024
@nineteendo
Copy link
Contributor

Do we close this or do we remove the pending label? It's been almost 100 days.

@ericvsmith
Copy link
Member

Closing due to inactivity.

@AA-Turner AA-Turner removed the pending The issue will be closed if no feedback is provided label Apr 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting changes skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.