test_mingw32ccompiler.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import shutil
  2. import subprocess
  3. import sys
  4. import pytest
  5. from numpy.distutils import mingw32ccompiler
  6. @pytest.mark.skipif(sys.platform != 'win32', reason='win32 only test')
  7. def test_build_import():
  8. '''Test the mingw32ccompiler.build_import_library, which builds a
  9. `python.a` from the MSVC `python.lib`
  10. '''
  11. # make sure `nm.exe` exists and supports the current python version. This
  12. # can get mixed up when the PATH has a 64-bit nm but the python is 32-bit
  13. try:
  14. out = subprocess.check_output(['nm.exe', '--help'])
  15. except FileNotFoundError:
  16. pytest.skip("'nm.exe' not on path, is mingw installed?")
  17. supported = out[out.find(b'supported targets:'):]
  18. if sys.maxsize < 2**32:
  19. if b'pe-i386' not in supported:
  20. raise ValueError("'nm.exe' found but it does not support 32-bit "
  21. "dlls when using 32-bit python. Supported "
  22. "formats: '%s'" % supported)
  23. elif b'pe-x86-64' not in supported:
  24. raise ValueError("'nm.exe' found but it does not support 64-bit "
  25. "dlls when using 64-bit python. Supported "
  26. "formats: '%s'" % supported)
  27. # Hide the import library to force a build
  28. has_import_lib, fullpath = mingw32ccompiler._check_for_import_lib()
  29. if has_import_lib:
  30. shutil.move(fullpath, fullpath + '.bak')
  31. try:
  32. # Whew, now we can actually test the function
  33. mingw32ccompiler.build_import_library()
  34. finally:
  35. if has_import_lib:
  36. shutil.move(fullpath + '.bak', fullpath)