summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_importlib
Commit message (Collapse)AuthorAgeFilesLines
* [3.11] gh-109593: Fix reentrancy issue in multiprocessing resource_tracker ↵Miss Islington (bot)2023-09-261-0/+2
| | | | | | | | | | | | (GH-109629) (#109897) gh-109593: Fix reentrancy issue in multiprocessing resource_tracker (GH-109629) --------- (cherry picked from commit 0eb98837b60bc58e57ad3e2b35c6b0e9ab634678) Co-authored-by: Antoine Pitrou <antoine@python.org> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
* [3.11] gh-106300: Improve `assertRaises(Exception)` usages in tests ↵Serhiy Storchaka2023-07-081-1/+1
| | | | | | | (GH-106302). (GH-106545) (cherry picked from commit 6e6a4cd52332017b10c8d88fbbbfe015948093f4) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* [3.11] Fix test_importlib.test_side_effect_import() (GH-104840) (#104843)Miss Islington (bot)2023-05-251-1/+2
| | | | | | | | | | | Fix test_importlib.test_side_effect_import() (GH-104840) Wait until the thread spawn by the import completes to avoid dangling threads. With this fix, the following command no longer fails: ./python -m test --fail-env-changed test_importlib -m test_side_effect_import -F -j20 (cherry picked from commit 426950993f6a39cdf3f6a3333ac8b518833c7e61) Co-authored-by: Victor Stinner <vstinner@python.org>
* [3.11] gh-103247: clear the module cache in a test in ↵Miss Islington (bot)2023-05-101-9/+10
| | | | | | | | test_importlib/extensions/test_loader.py (GH-104226) (#104345) gh-103247: clear the module cache in a test in test_importlib/extensions/test_loader.py (GH-104226) (cherry picked from commit 22f3425c3d3d896be0917d80d55e8abb08d99b18) Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
* [3.11] GH-102700: allow built-in modules to be submodules (GH-103162) ↵Miss Islington (bot)2023-04-061-17/+0
| | | | | | | | (GH-103322) GH-102700: allow built-in modules to be submodules (GH-103162) (cherry picked from commit 5d08c3ff7d89ca11556f18663a372f6c12435504) Co-authored-by: Brett Cannon <brett@python.org>
* [3.11] gh-98706: Sync with importlib_metadata 4.13.0. (GH-98875)Jason R. Coombs2022-11-053-45/+68
| | | These changes are already applied to main but have been selected from importlib_metadata 4.x for their bug fixes.
* gh-95971: Turn @writes_bytecode_files to skip when not running (GH-95972)Miss Islington (bot)2022-10-151-1/+1
| | | | | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> (cherry picked from commit 07b5c4699e64eb30c3bdcb1275c167e675d37423) Co-authored-by: Jeong YunWon <69878+youknowone@users.noreply.github.com>
* [3.11] Update the magic number in test_util.py (GH-95714) (#95716)Miss Islington (bot)2022-08-051-1/+1
| | | Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* gh-94217: Skip import tests when _testcapi is a builtin (GH-94218)Miss Islington (bot)2022-06-242-1/+13
| | | | | (cherry picked from commit 0a40025b803a8dc1d604538e317992827ab96625) Co-authored-by: Christian Heimes <christian@python.org>
* gh-93461: Invalidate sys.path_importer_cache entries with relative paths ↵Miss Islington (bot)2022-06-132-3/+14
| | | | | | | (GH-93653) (cherry picked from commit 09243b898a13f3f61e275c1031143d1225e70916) Co-authored-by: Christian Heimes <christian@python.org>
* test_threaded_import: Fix unittest.main spelling (GH-93114)Miss Islington (bot)2022-05-251-1/+1
| | | | | (cherry picked from commit 19710145b496b5e5341630d80be9c400aa792bd1) Co-authored-by: Florian Bruhin <me@the-compiler.org>
* bpo-45046: Support context managers in unittest (GH-28045)Miss Islington (bot)2022-05-082-20/+6
| | | | | | | | Add methods enterContext() and enterClassContext() in TestCase. Add method enterAsyncContext() in IsolatedAsyncioTestCase. Add function enterModuleContext(). (cherry picked from commit 086c6b1b0fe8d47ebd15512d7bdcb64c60a360f0) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-91298: Refine traversable (apply changes from importlib_resources 5.7.1) ↵Jason R. Coombs2022-04-171-1/+1
| | | | | | | (#91623) * bpo-47142: Refine traversable (apply changes from importlib_resources 5.7.1) * Replace changelog referencing github issue.
* bpo-46126: Restore docstrings in importlib.metadata tests. (#32288)Jason R. Coombs2022-04-172-24/+44
|
* bpo-40280: Detect missing threading on WASM platforms (GH-32352)Christian Heimes2022-04-072-1/+6
| | | Co-authored-by: Brett Cannon <brett@python.org>
* bpo-40280: Skip socket, fork, subprocess tests on Emscripten (GH-31986)Christian Heimes2022-03-222-0/+9
| | | | | | | | | | | - Add requires_fork and requires_subprocess to more tests - Skip extension import tests if dlopen is not available - Don't assume that _testcapi is a shared extension - Skip a lot of socket tests that don't work on Emscripten - Skip mmap tests, mmap emulation is incomplete - venv does not work yet - Cannot get libc from executable The "entire" test suite is now passing on Emscripten with EMSDK from git head (91 suites are skipped).
* bpo-47004: Sync with importlib_metadata 4.11.3. (#31854)Jason R. Coombs2022-03-131-0/+10
|
* bpo-46246: add missing __slots__ to importlib.metadata.DeprecatedList (GH-30452)Arie Bovenberg2022-02-111-0/+5
| | | | | | | Confirmed with @jaraco that this indeed needs a fix. A question that came up while I was digging into the code: I think `SelectableGroups` could similarly use `__slots__ = ()`, since its purpose seems only for convenience around `dict`, not to have attributes of its own. Automerge-Triggered-By: GH:jaraco
* bpo-46616: Ensures test_importlib.test_windows cleans up registry keys after ↵Steve Dower2022-02-021-3/+14
| | | | completion (GH-31086)
* bpo-46474: Apply changes from importlib_metadata 4.10.0 (GH-30802)Jason R. Coombs2022-01-231-16/+1
|
* bpo-46425: Partially revert "bpo-46425: fix direct invocation of ↵Jason R. Coombs2022-01-2310-40/+22
| | | | | `test_importlib` (GH-30682)" (GH-30799) This reverts commit 57316c52bae5d6420f5067f3891ec328deb97305 for files pertaining to importlib.metadata and importlib.resources.
* bpo-46425: fix direct invocation of `test_importlib` (GH-30682)Nikita Sobolev2022-01-2239-61/+74
|
* bpo-46118: Move importlib.resources to its own package. (#30176)Jason R. Coombs2021-12-311-1/+1
| | | | | * bpo-46118: Move importlib.resources to its own package. * Expand compatibility shims with documentation and explicit imports.
* bpo-46125: Refactor tests to test traversable API directly. Includes changes ↵Jason R. Coombs2021-12-196-189/+129
| | | | from importlib_resources 5.4.0. (GH-30189)
* bpo-44893: Implement EntryPoint as simple class with attributes. (GH-30150)Jason R. Coombs2021-12-165-42/+90
| | | | | * bpo-44893: Implement EntryPoint as simple class and deprecate tuple access in favor of attribute access. Syncs with importlib_metadata 4.8.1. * Apply refactorings found in importlib_metadata 4.8.2.
* bpo-46105: Honor spec when generating requirement specs with urls and ↵Jason R. Coombs2021-12-161-0/+2
| | | | extras. (GH-30151)
* bpo-45514: Deprecate importlib resources legacy functions. (GH-29036)Jason R. Coombs2021-11-246-81/+144
| | | | | | | | | | | * bpo-45514: Apply changes from importlib_resources@a3ef4128c6 * Mark legacy functions as deprecated in the docs and link to the migration docs in importlib_resources docs. * Apply changes from importlib_resources@329ae9d5f2c. * Indicate importlib.resources as a module. Co-authored-by: Filipe Laíns <lains@riseup.net>
* bpo-45703: Invalidate _NamespacePath cache on importlib.invalidate_ca… ↵Miro Hrončok2021-11-231-0/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (GH-29384) Consider the following directory structure: . └── PATH1 └── namespace └── sub1 └── __init__.py And both PATH1 and PATH2 in sys path: $ PYTHONPATH=PATH1:PATH2 python3.11 >>> import namespace >>> import namespace.sub1 >>> namespace.__path__ _NamespacePath(['.../PATH1/namespace']) >>> ... While this interpreter still runs, PATH2/namespace/sub2 is created: . ├── PATH1 │ └── namespace │ └── sub1 │ └── __init__.py └── PATH2 └── namespace └── sub2 └── __init__.py The newly created module cannot be imported: >>> ... >>> namespace.__path__ _NamespacePath(['.../PATH1/namespace']) >>> import namespace.sub2 Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named 'namespace.sub2' Calling importlib.invalidate_caches() now newly allows to import it: >>> import importlib >>> importlib.invalidate_caches() >>> namespace.__path__ _NamespacePath(['.../PATH1/namespace']) >>> import namespace.sub2 >>> namespace.__path__ _NamespacePath(['.../PATH1/namespace', '.../PATH2/namespace']) This was not previously possible.
* bpo-35673: Add a public alias for namespace package __loader__ attribute ↵Barry Warsaw2021-10-201-0/+7
| | | | | | | | (#29049) Rename namespace package __loader__ class to be public. Make the old name, i.e. _NamespaceLoader, an alias for the public name, for backward compatibility.
* 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
* [codemod] Fix non-matching bracket pairs (GH-28473)Mohamad Mansour2021-09-211-1/+1
| | | | | Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* bpo-45229: Remove test_main in many tests (GH-28405)Serhiy Storchaka2021-09-192-19/+12
| | | | | | | | | Instead of explicitly enumerate test classes for run_unittest() use the unittest ability to discover tests. This also makes these tests discoverable and runnable with unittest. load_tests() can be used for dynamic generating tests and adding doctests. setUpModule(), tearDownModule() and addModuleCleanup() can be used for running code before and after all module tests.
* 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-44784: Apply changes from importlib_metadata 4.6.3 (GH-27508)Jason R. Coombs2021-07-311-6/+12
| | | | | Addressing issues with tests under error on warnings. Automerge-Triggered-By: GH:jaraco
* bpo-44771: Apply changes from importlib_resources 5.2.1 (GH-27436)Jason R. Coombs2021-07-3010-187/+363
| | | | | | | * bpo-44771: Apply changes from importlib_resources@3b24bd6307 * Add blurb * Exclude namespacedata01 from eol conversion.
* bpo-44451: Reset DeprecationWarning filters in ↵Miro Hrončok2021-06-181-0/+1
| | | | | | | | | | | | | | | | | test_importlib.test_entry_points_by_index (GH-26784) This avoids the following error if DeprecationWarnings are ignored. ====================================================================== ERROR: test_entry_points_by_index (test.test_importlib.test_metadata_api.APITests) Prior versions of Distribution.entry_points would return a ---------------------------------------------------------------------- Traceback (most recent call last): File "/builddir/build/BUILD/Python-3.10.0b3/Lib/test/test_importlib/test_metadata_api.py", line 145, in test_entry_points_by_index expected = next(iter(caught)) StopIteration ---------------------------------------------------------------------- Ran 1402 tests in 2.125s FAILED (errors=1, skipped=18, expected failures=1)
* bpo-44246: Restore compatibility in entry_points (GH-26468)Jason R. Coombs2021-05-311-0/+16
| | | | | | | * bpo-44246: Entry points performance improvements. From importlib_metadata 4.3.1. * bpo-44246: Sync with importlib_metadata 4.4
* bpo-44246: Entry points performance improvements. (GH-26467)Jason R. Coombs2021-05-311-0/+4
| | | From importlib_metadata 4.3.1.
* bpo-38693: Prefer f-strings in importlib.resources (importlib_resources ↵Jason R. Coombs2021-05-262-3/+3
| | | | | 5.0.6). (GH-26387) Automerge-Triggered-By: GH:jaraco
* bpo-43643: Sync with python/importlib_resources@c17a610aad. (GH-26284)Jason R. Coombs2021-05-211-0/+6
| | | | * bpo-43643: Sync with python/importlib_resources@c17a610aad. * Sync with python/importlib_resources@89fd5e961a.
* bpo-43926: Cleaner metadata with PEP 566 JSON support. (GH-25565)Jason R. Coombs2021-05-023-3/+37
| | | | | | | | | * bpo-43926: Cleaner metadata with PEP 566 JSON support. * Add blurb * Add versionchanged and versionadded declarations for changes to metadata. * Use descriptor for PEP 566
* bpo-43864: Silence deprecation warning in test_importlib.test_module_found ↵Shreyan Avigyan2021-04-271-2/+6
| | | | and test_importlib.test_module_not_found (GH-25656)
* bpo-43780: Sync with importlib_metadata 3.10 (GH-25297)Jason R. Coombs2021-04-242-0/+14
| | | | | | | * bpo-43780: Sync with importlib_metadata 3.10. * Add blurb * Apply changes from importlib_metadata 3.10.1.
* Silence find_module() DeprecationWarning on Windows tests (GH-25563)Brett Cannon2021-04-231-1/+4
|
* bpo-43105: Importlib now resolves relative paths when creating module spec ↵Steve Dower2021-04-072-4/+60
| | | | objects from file locations (GH-25121)