Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit79a0a33

Browse files
committed
TST: Add unit test to catch recurrences of#20822,#20855
1 parentb071f39 commit79a0a33

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎lib/matplotlib/tests/test_getattr.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
fromimportlibimportimport_module
2+
frompkgutilimportwalk_packages
3+
4+
importmatplotlib
5+
importpytest
6+
7+
# Get the names of all matplotlib submodules, except for the unit tests.
8+
module_names= [m.nameforminwalk_packages(path=matplotlib.__path__,
9+
prefix=f'{matplotlib.__name__}.')
10+
ifnotm.name.startswith(__package__)]
11+
12+
13+
@pytest.mark.parametrize('module_name',module_names)
14+
@pytest.mark.filterwarnings('ignore::DeprecationWarning')
15+
deftest_getattr(module_name):
16+
"""
17+
Test that __getattr__ methods raise AttributeError for unknown keys.
18+
See #20822, #20855.
19+
"""
20+
try:
21+
module=import_module(module_name)
22+
except (ImportError,RuntimeError)ase:
23+
# Skip modules that cannot be imported due to missing dependencies
24+
pytest.skip(f'Cannot import{module_name} due to{e}')
25+
26+
key='THIS_SYMBOL_SHOULD_NOT_EXIST'
27+
ifhasattr(module,key):
28+
delattr(module,key)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp