Commit graph

45 commits

Author SHA1 Message Date
Serhiy Storchaka
f7cc7d296c
gh-71339: Use new assertion methods in test_import and test_importlib (GH-129052) 2025-01-21 11:24:19 +02:00
Tomas R.
bd3baa8b1a
gh-121604: Make sure all deprecated items in importlib raise DeprecationWarning (#128007)
Co-authored-by: rashansmith <smith.rashan@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Brett Cannon <brett@python.org>
2025-01-14 16:48:46 -08:00
Alex Waygood
c5c21fee7a
gh-125519: Improve traceback if importlib.reload() is called with a non-module object (#125520) 2024-10-21 07:53:21 +01:00
Victor Stinner
05df063ad8
gh-120417: Fix "imported but unused" linter warnings (#120461)
Add __all__ to the following modules:
importlib.machinery, importlib.util and xml.sax.

Add also "# noqa: F401" in collections.abc,
subprocess and xml.sax.

* Sort __all__; remove collections.abc.__all__; remove private names

* Add tests
2024-06-14 20:39:50 +02:00
Victor Stinner
ae319e4b43
gh-105407: Remove unused imports in tests (#105408) 2023-06-06 22:50:43 +02:00
Barry Warsaw
326997829d
gh-98040: Remove find_loader, find_module and other deprecated APIs (#98059)
* 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>
2023-05-03 04:55:22 -07:00
Victor Stinner
3ceb4b8d3a
gh-84623: Remove unused imports in tests (#93772) 2022-06-13 16:56:03 +02:00
Christian Heimes
09243b898a
gh-93461: Invalidate sys.path_importer_cache entries with relative paths (GH-93653) 2022-06-10 23:56:26 +02:00
Filipe Laíns
c7d699969c
gh-92265: set meta_path and path_hooks correctly in test_reload_namespace_changed (GH-92275)
Previously, we were blocking the frozen imports and forcing the source
version to be used, but we did not fix up sys.meta_path or
sys.path_hooks, causing the frozen importers to leak into the source
version of the test.
2022-05-16 16:05:47 -07:00
Nikita Sobolev
57316c52ba
bpo-46425: fix direct invocation of test_importlib (GH-30682) 2022-01-22 18:05:05 +02:00
Brett Cannon
57c6cb5100
bpo-42135: Deprecate implementations of find_module() and find_loader() (GH-25169) 2021-04-06 08:56:57 -07:00
Inada Naoki
c8e5eb904e
bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25181)
* Fix test_shutil
* Fix test_imp
* Fix test_import
* Fix test_importlib
2021-04-05 13:11:23 +09:00
Brett Cannon
a7ff6df60c
bpo-42134: Raise ImportWarning when calling find_module() in the import system (GH-25044) 2021-03-30 08:43:03 -07:00
Brett Cannon
2de5097ba4
bpo-26131: Deprecate usage of load_module() (GH-23469)
Raise an ImportWarning when the import system falls back on load_module(). As for implementations of load_module(), raise a DeprecationWarning.
2020-12-04 15:39:21 -08:00
Hai Shi
c7decc27d5
bpo-40275: Use new test.support helper submodules in tests (GH-21727) 2020-08-04 17:53:12 +02:00
Benjamin Peterson
0bc17ea2f5
Fix typo in test_api.py. (GH-16119) 2019-09-13 18:27:59 +01:00
Brett Cannon
9e2be60634
bpo-33169: Remove values of None from sys.path_importer_cache when invalidating caches (GH-6402)
An entry of None in sys.path_importer_cache represents a negative/missing finder for a path, so clearing it out makes sense.
2018-04-06 16:10:18 -07:00
Barry Warsaw
bbbcf8693b
bpo-32303 - Consistency fixes for namespace loaders (#5481)
* Make sure ``__spec__.loader`` matches ``__loader__`` for namespace packages.
* Make sure ``__spec__.origin` matches ``__file__`` for namespace packages.

https://bugs.python.org/issue32303
https://bugs.python.org/issue32305
2018-02-02 15:15:58 -05:00
Garvit Khatri
94987826e8 bpo-29851: Have importlib.reload() raise ImportError if the module's spec is not found (GH-972) 2017-05-24 15:19:50 -07:00
Eric Snow
228ab1ff6b Issue #21099: Switch applicable importlib tests to use PEP 451 API. 2016-05-10 16:21:03 -06:00
Eric Snow
3497c0bf95 Issue #21503: Use test_both() consistently in test_importlib. 2014-05-16 11:40:40 -06:00
Eric Snow
2f46a0e8be Issue #21499: Ignore __builtins__ in several test_importlib.test_api tests. 2014-05-13 12:15:42 -06:00
Eric Snow
6029e08691 Issue 19944: Fix importlib.find_spec() so it imports parents as needed.
The function is also moved to importlib.util.
2014-01-25 15:32:46 -07:00
Eric Snow
1500d49c22 Issue 19713: Add PEP 451-related deprecations. 2014-01-06 20:49:04 -07:00
Eric Snow
d749c7ae68 Issue #19927: Add __eq__ to path-based loaders in importlib. 2014-01-04 15:06:49 -07:00
Eric Snow
c1e7c747f9 Issue 19851: Fix a regression in reloading submodules. 2013-12-09 19:59:10 -07:00
Eric Snow
b523f8433a Implement PEP 451 (ModuleSpec). 2013-11-22 09:05:39 -07:00
Eric Snow
4ae17f50ed Issue #19413: Disregard duplicate namespace portions during reload tests. 2013-10-31 23:44:31 -06:00
Eric Snow
cdf601281f Issue #19413: Restore pre-3.3 reload() semantics of re-finding modules. 2013-10-31 22:22:15 -06:00
Brett Cannon
40b22d0661 Issue #16803: test.test_importlib.test_api now runs under frozen and
source.
2013-10-18 10:45:59 -04:00
Eric Snow
8e4554027b Closes issue #18698: ensure importlib.reload() returns the module out of sys.modules. 2013-08-14 18:11:09 -06:00
Brett Cannon
ef888024d8 Issue #17177: stop using imp in test_importlib 2013-06-15 18:39:21 -04:00
Brett Cannon
3fe35e6503 Issue #18193: Add importlib.reload(), documenting (but not
implementing in code) the deprecation of imp.reload().

Thanks to Berker Peksag for the patch.
2013-06-14 15:04:26 -04:00
Brett Cannon
4c14b5de1c #17115,17116: Have modules initialize the __package__ and __loader__
attributes to None.

The long-term goal is for people to be able to rely on these
attributes existing and checking for None to see if they have been
set. Since import itself sets these attributes when a loader does not
the only instances when the attributes are None are from someone
overloading __import__() and not using a loader or someone creating a
module from scratch.

This patch also unifies module initialization. Before you could have
different attributes with default values depending on how the module
object was created. Now the only way to not get the same default set
of attributes is to circumvent initialization by calling
ModuleType.__new__() directly.
2013-05-04 13:56:58 -04:00
Brett Cannon
327992330e Issue #17099: Have importlib.find_loader() raise ValueError when
__loader__ is not set on a module. This brings the exception in line
with when __loader__ is None (which is equivalent to not having the
attribute defined).
2013-03-13 11:09:08 -07:00
Brett Cannon
c0b631c0c4 merge w/ 3.3 2013-02-03 16:16:44 -05:00
Brett Cannon
7a34f02f9e Way too many places create modules temporarily that never set
__loader__ for this test to succeed without a major changes. It also
doesn't test the original issue of modules imported by Py_Initialize()
having __loader__ set (the rest of the test covers that).
2013-02-03 16:16:07 -05:00
Brett Cannon
df80914a1e merge 2013-02-03 11:38:16 -05:00
Brett Cannon
9de80ac127 pyexpat/xml.parsers.expat create their errors and model modules from
scratch. This means they do not set __loader__ by default. This is
acceptable under importlib/PEP 302 definitions, so relax the test that
was trying to apply this universally.
2013-02-03 11:37:13 -05:00
Brett Cannon
85ae3566d1 Merge w/ 3.3 more fixes thanks to issue #17098 2013-02-01 16:36:29 -05:00
Brett Cannon
da9cf0eef8 Issue #17098: Be more stringent of setting __loader__ on early imported
modules. Also made test more rigorous.
2013-02-01 15:31:49 -05:00
Brett Cannon
f41fa4f3a0 merge with 3.3 2013-02-01 14:51:43 -05:00
Brett Cannon
e7387b4708 Add a test for fix of issue #17098 2013-02-01 14:43:59 -05:00
Brett Cannon
f4dc9204cc Issue #15502: Finish bringing importlib.abc in line with the current
state of the import system. Also make importlib.invalidate_caches()
work with sys.meta_path instead of sys.path_importer_cache to
completely separate the path-based import system from the overall
import system.

Patch by Eric Snow.
2012-08-10 12:21:12 -04:00
Brett Cannon
45a5e3afe5 Issue #15168: Move importlb.test to test.test_importlib.
This should make the Linux distros happy as it is now easier to leave
importlib's tests out of their base Python distribution.
2012-07-20 14:48:53 -04:00
Renamed from Lib/importlib/test/test_api.py (Browse further)