-
-
Notifications
You must be signed in to change notification settings - Fork 21
fix: do not force matplotlib Agg backend on import #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0930968
956ab2c
424cd9d
cba69d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| __version__ = "1.2.2" | ||
| __version__ = "1.2.3" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Copyright (c) 2026. Jose M. Requena-Plens | ||
|
|
||
| """ | ||
| Tests ensuring the package does not hijack the global matplotlib backend. | ||
|
|
||
| Importing pyoctaveband must not force a specific (e.g. non-interactive) | ||
| backend, so the package can be used during interactive exploration | ||
| (IPython, Jupyter). See issue #52. | ||
| """ | ||
|
|
||
| import os | ||
| import subprocess | ||
| import sys | ||
|
|
||
|
|
||
| def test_import_does_not_override_matplotlib_backend() -> None: | ||
| """Importing pyoctaveband must preserve the user's chosen backend.""" | ||
| code = ( | ||
| "import matplotlib\n" | ||
| # Pick an explicit, always-available backend the user might have set. | ||
| "matplotlib.use('svg')\n" | ||
| "before = matplotlib.get_backend()\n" | ||
| "import pyoctaveband\n" | ||
| "after = matplotlib.get_backend()\n" | ||
| "assert before == after, f'backend changed: {before!r} -> {after!r}'\n" | ||
| ) | ||
| # Propagate the parent's sys.path so the subprocess can import the package | ||
| # even when it is only on sys.path (e.g. pytest without an installed build). | ||
| env = os.environ.copy() | ||
| env["PYTHONPATH"] = os.pathsep.join(sys.path) | ||
| result = subprocess.run( | ||
| [sys.executable, "-c", code], | ||
| capture_output=True, | ||
| text=True, | ||
| env=env, | ||
| timeout=30, | ||
| ) | ||
| assert result.returncode == 0, result.stderr | ||
|
Comment on lines
+12
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The subprocess is executed without propagating the current To ensure the test is robust across different test runners and environments, pass the parent process's import os
import subprocess
import sys
def test_import_does_not_override_matplotlib_backend() -> None:
"""Importing pyoctaveband must preserve the user's chosen backend."""
code = (
"import matplotlib\n"
# Pick an explicit, always-available backend the user might have set.
"matplotlib.use('svg')\n"
"before = matplotlib.get_backend()\n"
"import pyoctaveband\n"
"after = matplotlib.get_backend()\n"
"assert before == after, f'backend changed: {before!r} -> {after!r}'\n"
)
env = os.environ.copy()
env["PYTHONPATH"] = os.path.pathsep.join(sys.path)
result = subprocess.run(
[sys.executable, "-c", code],
capture_output=True,
text=True,
env=env,
)
assert result.returncode == 0, result.stderr |
||
Uh oh!
There was an error while loading. Please reload this page.