Skip to content

Commit 20126c8

Browse files
committed
Add unit tests for msvc14+
Python 3.8 "distutils/tests/test_msvccompiler.py" backport
1 parent c22bc36 commit 20126c8

File tree

4 files changed

+94
-3
lines changed

4 files changed

+94
-3
lines changed

appveyor.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ environment:
77
CODECOV_ENV: APPVEYOR_JOB_NAME
88

99
matrix:
10+
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
11+
APPVEYOR_JOB_NAME: "python35-x64-vs2015"
12+
PYTHON: "C:\\Python35-x64"
13+
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
14+
APPVEYOR_JOB_NAME: "python35-x64-vs2017"
15+
PYTHON: "C:\\Python35-x64"
1016
- APPVEYOR_JOB_NAME: "python36-x64"
1117
PYTHON: "C:\\Python36-x64"
1218
- APPVEYOR_JOB_NAME: "python27-x64"

setuptools/msvc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,11 @@ def msvc9_query_vcvarsall(ver, arch='x86', *args, **kwargs):
146146
def _msvc14_find_vc2015():
147147
"""Python 3.8 "distutils/_msvccompiler.py" backport"""
148148
try:
149-
key = winreg.OpenKeyEx(
149+
key = winreg.OpenKey(
150150
winreg.HKEY_LOCAL_MACHINE,
151151
r"Software\Microsoft\VisualStudio\SxS\VC7",
152-
access=winreg.KEY_READ | winreg.KEY_WOW64_32KEY
152+
0,
153+
winreg.KEY_READ | winreg.KEY_WOW64_32KEY
153154
)
154155
except OSError:
155156
return None, None

setuptools/tests/test_msvc14.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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")

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ list_dependencies_command = {[helpers]pip} freeze --all
2020
setenv=COVERAGE_FILE={toxworkdir}/.coverage.{envname}
2121
# TODO: The passed environment variables came from copying other tox.ini files
2222
# These should probably be individually annotated to explain what needs them.
23-
passenv=APPDATA HOMEDRIVE HOMEPATH windir APPVEYOR APPVEYOR_* CI CODECOV_* TRAVIS TRAVIS_* NETWORK_REQUIRED
23+
passenv=APPDATA HOMEDRIVE HOMEPATH windir Program* CommonProgram* VS* APPVEYOR APPVEYOR_* CI CODECOV_* TRAVIS TRAVIS_* NETWORK_REQUIRED
2424
commands=pytest --cov-config={toxinidir}/tox.ini --cov-report= {posargs}
2525
usedevelop=True
2626

0 commit comments

Comments
 (0)