test_matplotlib.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import os
  2. import subprocess
  3. import sys
  4. import pytest
  5. import matplotlib
  6. @pytest.mark.skipif(
  7. os.name == "nt", reason="chmod() doesn't work as is on Windows")
  8. @pytest.mark.skipif(os.name != "nt" and os.geteuid() == 0,
  9. reason="chmod() doesn't work as root")
  10. def test_tmpconfigdir_warning(tmpdir):
  11. """Test that a warning is emitted if a temporary configdir must be used."""
  12. mode = os.stat(tmpdir).st_mode
  13. try:
  14. os.chmod(tmpdir, 0)
  15. proc = subprocess.run(
  16. [sys.executable, "-c", "import matplotlib"],
  17. env={**os.environ, "MPLCONFIGDIR": str(tmpdir)},
  18. stderr=subprocess.PIPE, universal_newlines=True, check=True)
  19. assert "set the MPLCONFIGDIR" in proc.stderr
  20. finally:
  21. os.chmod(tmpdir, mode)
  22. def test_use_doc_standard_backends():
  23. """
  24. Test that the standard backends mentioned in the docstring of
  25. matplotlib.use() are the same as in matplotlib.rcsetup.
  26. """
  27. def parse(key):
  28. backends = []
  29. for line in matplotlib.use.__doc__.split(key)[1].split('\n'):
  30. if not line.strip():
  31. break
  32. backends += [e.strip() for e in line.split(',') if e]
  33. return backends
  34. assert (set(parse('- interactive backends:\n')) ==
  35. set(matplotlib.rcsetup.interactive_bk))
  36. assert (set(parse('- non-interactive backends:\n')) ==
  37. set(matplotlib.rcsetup.non_interactive_bk))