test_msvc14.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests for msvc support module (msvc14 unit tests).
  4. """
  5. import os
  6. from distutils.errors import DistutilsPlatformError
  7. import pytest
  8. import sys
  9. @pytest.mark.skipif(sys.platform != "win32",
  10. reason="These tests are only for win32")
  11. class TestMSVC14:
  12. """Python 3.8 "distutils/tests/test_msvccompiler.py" backport"""
  13. def test_no_compiler(self):
  14. import setuptools.msvc as _msvccompiler
  15. # makes sure query_vcvarsall raises
  16. # a DistutilsPlatformError if the compiler
  17. # is not found
  18. def _find_vcvarsall(plat_spec):
  19. return None, None
  20. old_find_vcvarsall = _msvccompiler._msvc14_find_vcvarsall
  21. _msvccompiler._msvc14_find_vcvarsall = _find_vcvarsall
  22. try:
  23. pytest.raises(DistutilsPlatformError,
  24. _msvccompiler._msvc14_get_vc_env,
  25. 'wont find this version')
  26. finally:
  27. _msvccompiler._msvc14_find_vcvarsall = old_find_vcvarsall
  28. def test_get_vc_env_unicode(self):
  29. import setuptools.msvc as _msvccompiler
  30. test_var = 'ṰḖṤṪ┅ṼẨṜ'
  31. test_value = '₃⁴₅'
  32. # Ensure we don't early exit from _get_vc_env
  33. old_distutils_use_sdk = os.environ.pop('DISTUTILS_USE_SDK', None)
  34. os.environ[test_var] = test_value
  35. try:
  36. env = _msvccompiler._msvc14_get_vc_env('x86')
  37. assert test_var.lower() in env
  38. assert test_value == env[test_var.lower()]
  39. finally:
  40. os.environ.pop(test_var)
  41. if old_distutils_use_sdk:
  42. os.environ['DISTUTILS_USE_SDK'] = old_distutils_use_sdk
  43. def test_get_vc2017(self):
  44. import setuptools.msvc as _msvccompiler
  45. # This function cannot be mocked, so pass it if we find VS 2017
  46. # and mark it skipped if we do not.
  47. version, path = _msvccompiler._msvc14_find_vc2017()
  48. if os.environ.get('APPVEYOR_BUILD_WORKER_IMAGE', '') in [
  49. 'Visual Studio 2017'
  50. ]:
  51. assert version
  52. if version:
  53. assert version >= 15
  54. assert os.path.isdir(path)
  55. else:
  56. pytest.skip("VS 2017 is not installed")
  57. def test_get_vc2015(self):
  58. import setuptools.msvc as _msvccompiler
  59. # This function cannot be mocked, so pass it if we find VS 2015
  60. # and mark it skipped if we do not.
  61. version, path = _msvccompiler._msvc14_find_vc2015()
  62. if os.environ.get('APPVEYOR_BUILD_WORKER_IMAGE', '') in [
  63. 'Visual Studio 2015', 'Visual Studio 2017'
  64. ]:
  65. assert version
  66. if version:
  67. assert version >= 14
  68. assert os.path.isdir(path)
  69. else:
  70. pytest.skip("VS 2015 is not installed")