summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_importlib/frozen
Commit message (Collapse)AuthorAgeFilesLines
* [3.13] gh-71339: Use new assertion methods in test_import and test_importlib ↵Serhiy Storchaka2025-04-081-3/+3
| | | | | | | | (GH-129052) (#129123) (cherry picked from commit f7cc7d296c2cbb33d3f0bde4ace82e8569f7dbc3) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-105407: Remove unused imports in tests (#105408)Victor Stinner2023-06-062-5/+0
|
* gh-98040: Remove find_loader, find_module and other deprecated APIs (#98059)Barry Warsaw2023-05-032-122/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Remove deprecated classes from pkgutil * Remove some other PEP 302 obsolescence * Use find_spec instead of load_module * Remove more tests of PEP 302 obsolete APIs * Remove another bunch of tests using obsolete load_modules() * Remove deleted names from __all__ * Remove obsolete footnote * imp is removed * Remove `imp` from generated stdlib names * What's new and blurb * Update zipimport documentation for the removed methods * Fix some Windows tests * Remove any test (or part of a test) that references `find_module()`. * Use assertIsNone() / assertIsNotNone() consistently. * Update Doc/reference/import.rst * We don't need pkgutil._get_spec() any more either * test.test_importlib.fixtures.NullFinder * ...BadLoaderFinder.find_module * ...test_api.InvalidatingNullFinder.find_module * ...test.test_zipimport test of z.find_module * Suppress cross-references to find_loader and find_module * Suppress cross-references to Finder * Suppress cross-references to pkgutil.ImpImporter and pkgutil.ImpLoader --------- Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net> Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
* gh-97850: Remove all known instances of module_repr() (#97876)Barry Warsaw2022-10-051-8/+1
| | | Remove all known instances of module_repr()
* gh-94619: Remove long deprecated methods module_repr() and load_module() ↵Barry Warsaw2022-08-051-8/+0
| | | | | | | | | | | | | | | (#94624) * gh-94619: Remove long deprecated methods module_repr() and load_module() Closes #94619 * Update Misc/NEWS.d/next/Library/2022-07-06-14-57-33.gh-issue-94619.PRqKVX.rst Fix typo Co-authored-by: Brett Cannon <brett@python.org> Co-authored-by: Brett Cannon <brett@python.org>
* bpo-46425: fix direct invocation of `test_importlib` (GH-30682)Nikita Sobolev2022-01-222-4/+2
|
* bpo-21736: Set __file__ on frozen stdlib modules. (gh-28656)Eric Snow2021-10-142-25/+36
| | | | | | | | | | | | | | | | | | | | | | | | Currently frozen modules do not have __file__ set. In their spec, origin is set to "frozen" and they are marked as not having a location. (Similarly, for frozen packages __path__ is set to an empty list.) However, for frozen stdlib modules we are able to extrapolate __file__ as long as we can determine the stdlib directory at runtime. (We now do so since gh-28586.) Having __file__ set is helpful for a number of reasons. Likewise, having a non-empty __path__ means we can import submodules of a frozen package from the filesystem (e.g. we could partially freeze the encodings module). This change sets __file__ (and adds to __path__) for frozen stdlib modules. It uses sys._stdlibdir (from gh-28586) and the frozen module alias information (from gh-28655). All that work is done in FrozenImporter (in Lib/importlib/_bootstrap.py). Also, if a frozen module is imported before importlib is bootstrapped (during interpreter initialization) then we fix up that module and its spec during the importlib bootstrapping step (i.e. imporlib._bootstrap._setup()) to match what gets set by FrozenImporter, including setting the file info (if the stdlib dir is known). To facilitate this, modules imported using PyImport_ImportFrozenModule() have __origname__ set using the frozen module alias info. __origname__ is popped off during importlib bootstrap. (To be clear, even with this change the new code to set __file__ during fixups in imporlib._bootstrap._setup() doesn't actually get triggered yet. This is because sys._stdlibdir hasn't been set yet in interpreter initialization at the point importlib is bootstrapped. However, we do fix up such modules at that point to otherwise match the result of importing through FrozenImporter, just not the __file__ and __path__ parts. Doing so will require changes in the order in which things happen during interpreter initialization. That can be addressed separately. Once it is, the file-related fixup code from this PR will kick in.) Here are things this change does not do: * set __file__ for non-stdlib modules (no way of knowing the parent dir) * set __file__ if the stdlib dir is not known (nor assume the expense of finding it) * relatedly, set __file__ if the stdlib is in a zip file * verify that the filename set to __file__ actually exists (too expensive) * update __path__ for frozen packages that alias a non-package (since there is no package dir) Other things this change skips, but we may do later: * set __file__ on modules imported using PyImport_ImportFrozenModule() * set co_filename when we unmarshal the frozen code object while importing the module (e.g. in FrozenImporter.exec_module()) -- this would allow tracebacks to show source lines * implement FrozenImporter.get_filename() and FrozenImporter.get_source() https://bugs.python.org/issue21736
* bpo-45020: Identify which frozen modules are actually aliases. (gh-28655)Eric Snow2021-10-052-18/+48
| | | | | | | In the list of generated frozen modules at the top of Tools/scripts/freeze_modules.py, you will find that some of the modules have a different name than the module (or .py file) that is actually frozen. Let's call each case an "alias". Aliases do not come into play until we get to the (generated) list of modules in Python/frozen.c. (The tool for freezing modules, Programs/_freeze_module, is only concerned with the source file, not the module it will be used for.) Knowledge of which frozen modules are aliases (and the identity of the original module) normally isn't important. However, this information is valuable when we go to set __file__ on frozen stdlib modules. This change updates Tools/scripts/freeze_modules.py to map aliases to the original module name (or None if not a stdlib module) in Python/frozen.c. We also add a helper function in Python/import.c to look up a frozen module's alias and add the result of that function to the frozen info returned from find_frozen(). https://bugs.python.org/issue45020
* Rearrage the finder tests. (gh-28740)Eric Snow2021-10-051-30/+56
| | | | | This makes the tests a bit cleaner and makes adding more tests a little simpler. https://bugs.python.org/issue45324
* bpo-45324: Capture data in FrozenImporter.find_spec() to use in ↵Eric Snow2021-10-052-23/+60
| | | | | | | | | | | exec_module(). (gh-28633) Before this change we end up duplicating effort and throwing away data in FrozenImporter.find_spec(). Now we do the work once in find_spec() and the only thing we do in FrozenImporter.exec_module() is turn the raw frozen data into a code object and then exec it. We've added _imp.find_frozen(), add an arg to _imp.get_frozen_object(), and updated FrozenImporter. We've also moved some code around to reduce duplication, get a little more consistency in outcomes, and be more efficient. Note that this change is mostly necessary if we want to set __file__ on frozen stdlib modules. (See https://bugs.python.org/issue21736.) https://bugs.python.org/issue45324
* bpo-45020: Add more test cases for frozen modules. (gh-28664)Eric Snow2021-10-011-13/+66
| | | | | I've added a number of test-only modules. Some of those cases are covered by the recently frozen stdlib modules (and some will be once we add encodings back in). However, I figured we'd play it safe by having a set of modules guaranteed to be there during tests. https://bugs.python.org/issue45020
* bpo-45019: Clean up the frozen __hello__ module. (gh-28374)Eric Snow2021-09-151-14/+21
| | | | | Here's one more small cleanup that should have been in PR gh-28319. We eliminate stdout side-effects from importing the frozen __hello__ module, and update tests accordingly. We also move the module's source file into Lib/ from Toos/freeze/flag.py. https://bugs.python.org/issue45019
* bpo-45020: Add -X frozen_modules=[on|off] to explicitly control use of ↵Eric Snow2021-09-142-96/+123
| | | | | | | frozen modules. (gh-28320) Currently we freeze several modules into the runtime. For each of these modules it is essential to bootstrapping the runtime that they be frozen. Any other stdlib module that we later freeze into the runtime is not essential. We can just as well import from the .py file. This PR lets users explicitly choose which should be used, with the new "-X frozen_modules=[on|off]" CLI flag. The default is "off" for now. https://bugs.python.org/issue45020
* bpo-42135: Deprecate implementations of find_module() and find_loader() ↵Brett Cannon2021-04-062-2/+5
| | | | (GH-25169)
* bpo-42137: have ModuleType.__repr__ prefer __spec__ over module_repr() ↵Brett Cannon2021-03-241-8/+0
| | | | | (GH-24953) This is to work towards the removal of the use of module_repr() in Python 3.12 (documented as deprecated since 3.4).
* bpo-26131: Deprecate usage of load_module() (GH-23469)Brett Cannon2020-12-041-8/+12
| | | Raise an ImportWarning when the import system falls back on load_module(). As for implementations of load_module(), raise a DeprecationWarning.
* Issue #23277: Remove unused sys and os importsBerker Peksag2016-04-241-2/+0
| | | | Patch by Jon Dufresne.
* Closes #22002: Merge with 3.4Zachary Ware2014-07-232-12/+8
|\
| * Issue #22002: Make full use of test discovery in test sub-packages.Zachary Ware2014-07-232-12/+8
| | | | | | | | | | | | Adds `load_package_tests` function to test.support, uses it in test_asyncio, test_email, test_json, test_tools, test_importlib and all test_importlib sub-packages to implement test discovery.
* | Issue #21503: Use test_both() consistently in test_importlib.Eric Snow2014-05-162-10/+19
|/
* Issue 19713: Add PEP 451-related deprecations.Eric Snow2014-01-071-8/+34
|
* Implement PEP 451 (ModuleSpec).Eric Snow2013-11-222-10/+114
|
* Issue #16803: test.test_importlib.frozen now runs both frozen and source codeBrett Cannon2013-11-082-31/+33
|
* Issue #16803: Stop having test.test_importlib.abc ABCs inherit fromBrett Cannon2013-10-252-2/+2
| | | | | unittest.TestCase in prep of running tests under frozen and source importlib.
* Issue #17177: stop using imp in test_importlibBrett Cannon2013-06-151-4/+6
|
* Issue #18065: For frozen packages set __path__ to [].Brett Cannon2013-06-011-1/+1
| | | | | | | Previously __path__ was set to [__name__], but that could lead to bad results if someone managed to circumvent the frozen importer and somehow ended up with a finder that thought __name__ was a legit directory/location.
* Issue #15168: Move importlb.test to test.test_importlib.Brett Cannon2012-07-203-0/+181
This should make the Linux distros happy as it is now easier to leave importlib's tests out of their base Python distribution.