test_import.py 1.1 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. from pathlib import Path
  10. import re
  11. import tokenize
  12. import pytest
  13. from numpy.testing import assert_
  14. import scipy
  15. class TestFFTPackImport:
  16. @pytest.mark.slow
  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. f"{path} contains an import from fftpack")