Context manager to create a style sheet in a temporary directory.
(style_name, settings=None)
| 17 | |
| 18 | @contextmanager |
| 19 | def 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 | |
| 40 | def test_invalid_rc_warning_includes_filename(caplog): |
no test coverage detected
searching dependent graphs…