test_import.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. """Test possibility of patching fftpack with pyfftw.
  2. No module source outside of scipy.fftpack should contain an import of
  3. the form `from scipy.fftpack import ...`, so that a simple replacement
  4. of scipy.fftpack by the corresponding fftw interface completely swaps
  5. the two FFT implementations.
  6. Because this simply inspects source files, we only need to run the test
  7. on one version of Python.
  8. """
  9. from pathlib import Path
  10. import re
  11. import tokenize
  12. from numpy.testing import assert_
  13. import scipy
  14. class TestFFTPackImport:
  15. def test_fftpack_import(self):
  16. base = Path(scipy.__file__).parent
  17. regexp = r"\s*from.+\.fftpack import .*\n"
  18. for path in base.rglob("*.py"):
  19. if base / "fftpack" in path.parents:
  20. continue
  21. # use tokenize to auto-detect encoding on systems where no
  22. # default encoding is defined (e.g., LANG='C')
  23. with tokenize.open(str(path)) as file:
  24. assert_(all(not re.fullmatch(regexp, line)
  25. for line in file),
  26. "{0} contains an import from fftpack".format(path))