test_import.py 1.2 KB

123456789101112131415161718192021222324252627282930313233
  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. import sys
  10. if sys.version_info >= (3, 4):
  11. from pathlib import Path
  12. import re
  13. import tokenize
  14. from numpy.testing import assert_
  15. import scipy
  16. class TestFFTPackImport(object):
  17. def test_fftpack_import(self):
  18. base = Path(scipy.__file__).parent
  19. regexp = r"\s*from.+\.fftpack import .*\n"
  20. for path in base.rglob("*.py"):
  21. if base / "fftpack" in path.parents:
  22. continue
  23. # use tokenize to auto-detect encoding on systems where no
  24. # default encoding is defined (e.g. LANG='C')
  25. with tokenize.open(str(path)) as file:
  26. assert_(all(not re.fullmatch(regexp, line)
  27. for line in file),
  28. "{0} contains an import from fftpack".format(path))