msg103102 - (view) |
Author: Skip Montanaro (skip.montanaro) *  |
Date: 2010-04-14 00:03 |
At work we are in the process of migrating from Python 2.4 to 2.6. One bit of Boost.Python code needs to use PyImport_ImportModuleLevel which references the __import__ docs. That describes the use of the level arg. I then went around looking for examples and didn't find much, certainly not in the Lib/test directory. I only saw a couple examples which used level and they both use level=0, so don't test relative imports or level=-1. I don't know that I have enough knowledge of how this stuff is supposed to work, but will give it a shot. |
|
|
msg103124 - (view) |
Author: Skip Montanaro (skip.montanaro) *  |
Date: 2010-04-14 12:52 |
The attached diff adds a PackageTest class which exercises both "from . import blah" and its __import__() equivalent. The diff is against the release26-maint branch but I suspect it will apply cleanly to trunk and probably py3k. |
|
|
msg103125 - (view) |
Author: Skip Montanaro (skip.montanaro) *  |
Date: 2010-04-14 12:56 |
Unassigning so someone else can pick it up and review to see if this makes sense. |
|
|
msg103147 - (view) |
Author: Éric Araujo (eric.araujo) *  |
Date: 2010-04-14 21:20 |
Adding Brett and Nick to nosy, per Misc/maintainers.rst (Disclaimer: I’m new to issue triaging, tell me if I do something wrong.) Regards |
|
|
msg103150 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2010-04-14 21:37 |
Yep, this is the right sort of thing to kick in our direction. There's a reasonable amount of implicit testing of import's level argument through the relative import tests in test_import and test_runpy, but some explicit tests of direct invocation can't hurt. As Skip says, the test suite can serve as useful example code, although I couldn't recommend that it *all* be treated that way - we do some pretty weird stuff at times in an effort to stress the code under test or to isolate test cases from each other. |
|
|
msg111263 - (view) |
Author: Virgil Dupras (vdupras)  |
Date: 2010-07-23 10:14 |
If I understand the patch correctly, this patch basically add a test for relative imports. I'm pretty sure this is already testes in importlib.test. Brett, am I right? If yes, there's no point in applying this patch. |
|
|
msg111265 - (view) |
Author: Brett Cannon (brett.cannon) *  |
Date: 2010-07-23 10:23 |
Yes, importlib has tests for relative import, but those are only run against importlib and not __import__. Adding Skip's tests and seeing how they differ from what importlib.test.import_.test_relative_imports would be good. |
|
|
msg111276 - (view) |
Author: Virgil Dupras (vdupras)  |
Date: 2010-07-23 11:13 |
Because importlib is already well tested and that it already has the machinery to test __import__ instead of the importlib code, I suggest that we re-use importlib's relative tests instead. Attached is a patch that does this. I made sure that __import__ was actually called. |
|
|
msg111323 - (view) |
Author: Brett Cannon (brett.cannon) *  |
Date: 2010-07-23 14:04 |
Committed in r83090. Tweaked the patch from Virgil slightly so that it sets the flag used by importlib to delineate whether to use __import__ back to its original setting after running the tests. |
|
|
msg111325 - (view) |
Author: Virgil Dupras (vdupras)  |
Date: 2010-07-23 14:11 |
Brett, I think there's a problem with the tweak you made to the patch. There was already a testcase called RelativeImportTests and you've hidden it (that I why I called it ImportlibRelativeImportTests initially). |
|
|
msg111339 - (view) |
Author: Brett Cannon (brett.cannon) *  |
Date: 2010-07-23 14:48 |
Fixed in r83091. |
|
|