test_basic.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import builtins
  2. import os
  3. import subprocess
  4. import sys
  5. import textwrap
  6. import matplotlib
  7. def test_simple():
  8. assert 1 + 1 == 2
  9. def test_override_builtins():
  10. import pylab
  11. ok_to_override = {
  12. '__name__',
  13. '__doc__',
  14. '__package__',
  15. '__loader__',
  16. '__spec__',
  17. 'any',
  18. 'all',
  19. 'sum',
  20. 'divmod'
  21. }
  22. overridden = False
  23. for key in dir(pylab):
  24. if key in dir(builtins):
  25. if (getattr(pylab, key) != getattr(builtins, key) and
  26. key not in ok_to_override):
  27. print("'%s' was overridden in globals()." % key)
  28. overridden = True
  29. assert not overridden
  30. def test_lazy_imports():
  31. source = textwrap.dedent("""
  32. import sys
  33. import matplotlib.figure
  34. import matplotlib.backend_bases
  35. import matplotlib.pyplot
  36. assert 'matplotlib._png' not in sys.modules
  37. assert 'matplotlib._tri' not in sys.modules
  38. assert 'matplotlib._qhull' not in sys.modules
  39. assert 'matplotlib._contour' not in sys.modules
  40. assert 'urllib.request' not in sys.modules
  41. """)
  42. subprocess.check_call(
  43. [sys.executable, '-c', source],
  44. env={**os.environ, "MPLBACKEND": "", "MATPLOTLIBRC": os.devnull})