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
Patch to add a get_data function to pkgutil #46691
Comments
This patch adds a new get_data function to the pkgutil module, allowing The patch includes documentation and tests (I created a new test_pkgutil All tests pass on Windows against svn rev 61679 (except test_tcl, which |
Hi Paul. AFAICT, this doesn't look like it will actually work for |
I'm not sure I understand. It uses pkgutil.get_loader, which returns a Can you supply a testcase that fails? (BTW, this is a patch for the |
Oops, my bad. I'm thinking of an entirely unrelated get_loader() Your patch is calling load_module() even if the module is already in Sorry again for the mixup. |
Is that true? loader.load_module(pkg) should return sys.modules[pkg] The load_module() method has a few responsibilities that it must
I've added a test for this, but I'm not 100% sure it's right. It |
reload() is implemented by calling the PEP-302 load_module() method |
To clarify the intent of the section of PEP-302 Paul quoted: the So it's the same module object, but with brand new contents (this is why |
Nick, thanks I now see the issue. I'll work up a test to check for this |
An easy way to test it: just change your load_module() to raise an |
But that's not a valid loader. I'm still struggling here. I see what you're trying to get at, but I To test the problem you're suggesting (that the code calls load_module Obviously, I can fix the get_data code - that's not even remotely hard. |
Why does it need to be a valid loader? It's a mock, not a real |
It has to be a valid loader, as I see no reason to support loaders that |
But I'm getting a failure on that test, and the other one, too: $ ./python Lib/test/test_pkgutil.py
test_alreadyloaded (__main__.PkgutilTests) ... FAIL
test_getdata_filesys (__main__.PkgutilTests) ... FAIL
test_getdata_pep302 (__main__.PkgutilTests) ... ok ====================================================================== Traceback (most recent call last):
File "Lib/test/test_pkgutil.py", line 45, in test_alreadyloaded
self.assertEqual(foo.loads, 1)
AssertionError: 2 != 1 ====================================================================== Traceback (most recent call last):
File "Lib/test/test_pkgutil.py", line 30, in test_getdata_filesys
self.assert_('PkgutilTests' in this_file)
AssertionError Ran 3 tests in 0.017s FAILED (failures=2) I'm rebuilding my entire 2.6 checkout to double-check there's not |
Thanks for the update. Something's seriously screwy here. I am getting |
By the way, for comparison, I'm running the test (under Windows) using Here's my output:
---------------------------------------------------------------------- OK |
Ah, no. I see your command line. I get the same failure as you in that |
OK, I found it. There were 2 problems, the double-loading one, and a Here's a fixed patch. Thanks, Phillip, for persevering! |
I should be able to review/commit this for the next alpha (looking into |
Thanks, |
Commited as rev 62350 |
Test file added in rev 62351 (forgot to svn add it the first time around) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: