Issue 8392: unit tests rather light on testing import(..., level) (original) (raw)

Created on 2010-04-14 00:03 by skip.montanaro, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
ti.diff skip.montanaro,2010-04-14 12:52
issue8392.diff vdupras,2010-07-23 11:13
Messages (11)
msg103102 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) 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) * (Python triager) 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) * (Python triager) 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) * (Python committer) 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) * (Python committer) 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) (Python triager) 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) * (Python committer) 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) (Python triager) 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) * (Python committer) 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) (Python triager) 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) * (Python committer) Date: 2010-07-23 14:48
Fixed in r83091.
History
Date User Action Args
2022-04-11 14:56:59 admin set github: 52639
2010-07-23 14:48:24 brett.cannon set messages: +
2010-07-23 14:11:34 vdupras set messages: +
2010-07-23 14:04:58 brett.cannon set status: open -> closedresolution: acceptedmessages: +
2010-07-23 11:13:37 vdupras set files: + issue8392.diffmessages: +
2010-07-23 10:23:39 brett.cannon set messages: +
2010-07-23 10:14:53 vdupras set nosy: + vduprasmessages: +
2010-05-20 20:40:12 skip.montanaro set nosy: - skip.montanaro
2010-04-14 21:37:21 ncoghlan set messages: +
2010-04-14 21:20:46 eric.araujo set nosy: + eric.araujo, brett.cannon, ncoghlanmessages: + keywords: + needs reviewtype: behavior
2010-04-14 12:56:04 skip.montanaro set assignee: skip.montanaro -> messages: +
2010-04-14 12:52:42 skip.montanaro set files: + ti.diffkeywords: + patchmessages: +
2010-04-14 00:03:30 skip.montanaro create