|
1 | 1 | import importlib |
| 2 | +import os |
| 3 | +import pathlib |
| 4 | +import subprocess |
| 5 | +import sys |
2 | 6 | import threading |
3 | 7 | from queue import Queue |
4 | 8 |
|
@@ -212,3 +216,45 @@ def _reader(): |
212 | 216 | observed = [results.get() for _ in range(results.qsize())] |
213 | 217 | assert observed, "No rcParams observations were recorded." |
214 | 218 | assert all(value in allowed for value in observed) |
| 219 | + |
| 220 | + |
| 221 | +def _run_in_subprocess(code): |
| 222 | + code = ( |
| 223 | + "import pathlib\n" |
| 224 | + "import sys\n" |
| 225 | + "sys.path.insert(0, str(pathlib.Path.cwd()))\n" + code |
| 226 | + ) |
| 227 | + env = os.environ.copy() |
| 228 | + env["MPLBACKEND"] = "Agg" |
| 229 | + return subprocess.run( |
| 230 | + [sys.executable, "-c", code], |
| 231 | + capture_output=True, |
| 232 | + text=True, |
| 233 | + cwd=str(pathlib.Path(__file__).resolve().parents[2]), |
| 234 | + env=env, |
| 235 | + ) |
| 236 | + |
| 237 | + |
| 238 | +def test_matplotlib_import_before_ultraplot_allows_rc_mutation(): |
| 239 | + """ |
| 240 | + Import order regression test for issue #568. |
| 241 | + """ |
| 242 | + result = _run_in_subprocess( |
| 243 | + "import matplotlib.pyplot as plt\n" |
| 244 | + "import ultraplot as uplt\n" |
| 245 | + "uplt.rc['figure.facecolor'] = 'white'\n" |
| 246 | + ) |
| 247 | + assert result.returncode == 0, result.stderr |
| 248 | + |
| 249 | + |
| 250 | +def test_matplotlib_import_before_ultraplot_allows_custom_fontsize_tokens(): |
| 251 | + """ |
| 252 | + Ensure patched fontsize validators are active regardless of import order. |
| 253 | + """ |
| 254 | + result = _run_in_subprocess( |
| 255 | + "import matplotlib.pyplot as plt\n" |
| 256 | + "import ultraplot as uplt\n" |
| 257 | + "for key in ('axes.titlesize', 'figure.titlesize', 'legend.fontsize', 'xtick.labelsize'):\n" |
| 258 | + " uplt.rc[key] = 'med-large'\n" |
| 259 | + ) |
| 260 | + assert result.returncode == 0, result.stderr |
0 commit comments