test_backend_webagg.py 938 B

1234567891011121314151617181920212223242526272829303132
  1. import os
  2. import sys
  3. import pytest
  4. import matplotlib.backends.backend_webagg_core
  5. from matplotlib.testing import subprocess_run_for_testing
  6. @pytest.mark.parametrize("backend", ["webagg", "nbagg"])
  7. def test_webagg_fallback(backend):
  8. pytest.importorskip("tornado")
  9. if backend == "nbagg":
  10. pytest.importorskip("IPython")
  11. env = dict(os.environ)
  12. if sys.platform != "win32":
  13. env["DISPLAY"] = ""
  14. env["MPLBACKEND"] = backend
  15. test_code = (
  16. "import os;"
  17. + f"assert os.environ['MPLBACKEND'] == '{backend}';"
  18. + "import matplotlib.pyplot as plt; "
  19. + "print(plt.get_backend());"
  20. f"assert '{backend}' == plt.get_backend().lower();"
  21. )
  22. subprocess_run_for_testing([sys.executable, "-c", test_code], env=env, check=True)
  23. def test_webagg_core_no_toolbar():
  24. fm = matplotlib.backends.backend_webagg_core.FigureManagerWebAgg
  25. assert fm._toolbar2_class is None