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