test_basic.py 1.0 KB

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