MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / temp_style

Function temp_style

lib/matplotlib/tests/test_style.py:19–37  ·  view source on GitHub ↗

Context manager to create a style sheet in a temporary directory.

(style_name, settings=None)

Source from the content-addressed store, hash-verified

17
18@contextmanager
19def temp_style(style_name, settings=None):
20 """Context manager to create a style sheet in a temporary directory."""
21 if not settings:
22 settings = DUMMY_SETTINGS
23 temp_file = f'{style_name}.mplstyle'
24 orig_library_paths = style.USER_LIBRARY_PATHS
25 try:
26 with TemporaryDirectory() as tmpdir:
27 # Write style settings to file in the tmpdir.
28 Path(tmpdir, temp_file).write_text(
29 "\n".join(f"{k}: {v}" for k, v in settings.items()),
30 encoding="utf-8")
31 # Add tmpdir to style path and reload so we can access this style.
32 style.USER_LIBRARY_PATHS.append(tmpdir)
33 style.reload_library()
34 yield
35 finally:
36 style.USER_LIBRARY_PATHS = orig_library_paths
37 style.reload_library()
38
39
40def test_invalid_rc_warning_includes_filename(caplog):

Calls 2

PathClass · 0.85
joinMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…