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

Commitbd7d627

Browse files
committed
TST: macosx savefig respects rcParam setting
1 parentd2ebb93 commitbd7d627

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

‎lib/matplotlib/tests/test_backend_macosx.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
importos
2+
importtempfile
3+
14
importpytest
25

6+
importmatplotlibasmpl
37
importmatplotlib.pyplotasplt
4-
5-
6-
pytest.importorskip("matplotlib.backends.backend_macosx",
7-
reason="These are mac only tests")
8+
try:
9+
frommatplotlib.backendsimport_macosx
10+
exceptImportError:
11+
pytest.skip("These are mac only tests",allow_module_level=True)
812

913

1014
@pytest.mark.backend('macosx')
@@ -18,3 +22,32 @@ def test_cached_renderer():
1822
fig=plt.figure(2)
1923
fig.draw_without_rendering()
2024
assertfig._cachedRendererisnotNone
25+
26+
27+
@pytest.mark.backend('macosx')
28+
deftest_savefig_rcparam():
29+
# Store the save file so we can overwrite it and
30+
# then put back the real one after this
31+
old_save_file_func=_macosx.choose_save_file
32+
33+
defnew_choose_save_file(title,directory,filename):
34+
# Replacement function instead of opening a GUI window
35+
# Make a new directory for testing the update of the rcParams
36+
os.makedirs(f"{directory}/test")
37+
returnf"{directory}/test/{filename}"
38+
39+
_macosx.choose_save_file=new_choose_save_file
40+
fig=plt.figure()
41+
withtempfile.TemporaryDirectory()astemp_dir, \
42+
mpl.rc_context({"savefig.directory":temp_dir}):
43+
fig.canvas.toolbar.save_figure()
44+
# Check the saved location got created
45+
save_file=f"{temp_dir}/test/{fig.canvas.get_default_filename()}"
46+
assertos.path.exists(save_file)
47+
48+
# Check the savefig.directory rcParam got updated because
49+
# we added a subdirectory "test"
50+
assertmpl.rcParams["savefig.directory"]==f"{temp_dir}/test"
51+
52+
# Replace the original function
53+
_macosx.choose_save_file=old_save_file_func

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp