Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e641df

Browse files
committed
Close #19439: execute embedding tests on Windows
Patch by Zachary Ware
1 parent f4cb48a commit 4e641df

5 files changed

Lines changed: 250 additions & 32 deletions

File tree

Lib/test/test_capi.py

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import sys
1010
import time
1111
import unittest
12-
import textwrap
1312
from test import support
1413
try:
1514
import _posixsubprocess
@@ -219,15 +218,17 @@ def test(self):
219218
self.assertEqual(_testcapi.argparsing("Hello", "World"), 1)
220219

221220

222-
@unittest.skipIf(
223-
sys.platform.startswith('win'),
224-
"interpreter embedding tests aren't built under Windows")
225221
class EmbeddingTests(unittest.TestCase):
226-
# XXX only tested under Unix checkouts
227-
228222
def setUp(self):
229223
basepath = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
230-
self.test_exe = exe = os.path.join(basepath, "Modules", "_testembed")
224+
exename = "_testembed"
225+
if sys.platform.startswith("win"):
226+
ext = ("_d" if "_d" in sys.executable else "") + ".exe"
227+
exename += ext
228+
exepath = os.path.dirname(sys.executable)
229+
else:
230+
exepath = os.path.join(basepath, "Modules")
231+
self.test_exe = exe = os.path.join(exepath, exename)
231232
if not os.path.exists(exe):
232233
self.skipTest("%r doesn't exist" % exe)
233234
# This is needed otherwise we get a fatal error:
@@ -260,38 +261,51 @@ def test_subinterps(self):
260261
print(out)
261262
print(err)
262263

264+
@staticmethod
265+
def _get_default_pipe_encoding():
266+
rp, wp = os.pipe()
267+
try:
268+
with os.fdopen(wp, 'w') as w:
269+
default_pipe_encoding = w.encoding
270+
finally:
271+
os.close(rp)
272+
return default_pipe_encoding
273+
263274
def test_forced_io_encoding(self):
264275
# Checks forced configuration of embedded interpreter IO streams
265276
out, err = self.run_embedded_interpreter("forced_io_encoding")
266277
if support.verbose:
267278
print()
268279
print(out)
269280
print(err)
270-
expected_output = textwrap.dedent("""\
271-
--- Use defaults ---
272-
Expected encoding: default
273-
Expected errors: default
274-
stdin: {0.__stdin__.encoding}:strict
275-
stdout: {0.__stdout__.encoding}:strict
276-
stderr: {0.__stderr__.encoding}:backslashreplace
277-
--- Set errors only ---
278-
Expected encoding: default
279-
Expected errors: surrogateescape
280-
stdin: {0.__stdin__.encoding}:surrogateescape
281-
stdout: {0.__stdout__.encoding}:surrogateescape
282-
stderr: {0.__stderr__.encoding}:backslashreplace
283-
--- Set encoding only ---
284-
Expected encoding: latin-1
285-
Expected errors: default
286-
stdin: latin-1:strict
287-
stdout: latin-1:strict
288-
stderr: latin-1:backslashreplace
289-
--- Set encoding and errors ---
290-
Expected encoding: latin-1
291-
Expected errors: surrogateescape
292-
stdin: latin-1:surrogateescape
293-
stdout: latin-1:surrogateescape
294-
stderr: latin-1:backslashreplace""").format(sys)
281+
expected_stdin_encoding = sys.__stdin__.encoding
282+
expected_pipe_encoding = self._get_default_pipe_encoding()
283+
expected_output = os.linesep.join([
284+
"--- Use defaults ---",
285+
"Expected encoding: default",
286+
"Expected errors: default",
287+
"stdin: {0}:strict",
288+
"stdout: {1}:strict",
289+
"stderr: {1}:backslashreplace",
290+
"--- Set errors only ---",
291+
"Expected encoding: default",
292+
"Expected errors: surrogateescape",
293+
"stdin: {0}:surrogateescape",
294+
"stdout: {1}:surrogateescape",
295+
"stderr: {1}:backslashreplace",
296+
"--- Set encoding only ---",
297+
"Expected encoding: latin-1",
298+
"Expected errors: default",
299+
"stdin: latin-1:strict",
300+
"stdout: latin-1:strict",
301+
"stderr: latin-1:backslashreplace",
302+
"--- Set encoding and errors ---",
303+
"Expected encoding: latin-1",
304+
"Expected errors: surrogateescape",
305+
"stdin: latin-1:surrogateescape",
306+
"stdout: latin-1:surrogateescape",
307+
"stderr: latin-1:backslashreplace"]).format(expected_stdin_encoding,
308+
expected_pipe_encoding)
295309
# This is useful if we ever trip over odd platform behaviour
296310
self.maxDiff = None
297311
self.assertEqual(out.strip(), expected_output)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ Library
153153
Tests
154154
-----
155155

156+
- Issue #19439: interpreter embedding tests are now executed on Windows
157+
(Patch by Zachary Ware)
158+
156159
- Issue #19085: Added basic tests for all tkinter widget options.
157160

158161
- Issue 19384: Fix test_py_compile for root user, patch by Claudiu Popa.

PCbuild/_testembed.vcxproj

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Debug|x64">
9+
<Configuration>Debug</Configuration>
10+
<Platform>x64</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Release|Win32">
13+
<Configuration>Release</Configuration>
14+
<Platform>Win32</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<ProjectGuid>{6DAC66D9-E703-4624-BE03-49112AB5AA62}</ProjectGuid>
23+
<Keyword>Win32Proj</Keyword>
24+
<RootNamespace>_testembed</RootNamespace>
25+
</PropertyGroup>
26+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
27+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
28+
<ConfigurationType>Application</ConfigurationType>
29+
<UseDebugLibraries>true</UseDebugLibraries>
30+
<CharacterSet>Unicode</CharacterSet>
31+
</PropertyGroup>
32+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
33+
<ConfigurationType>Application</ConfigurationType>
34+
<UseDebugLibraries>true</UseDebugLibraries>
35+
<CharacterSet>Unicode</CharacterSet>
36+
</PropertyGroup>
37+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
38+
<ConfigurationType>Application</ConfigurationType>
39+
<UseDebugLibraries>false</UseDebugLibraries>
40+
<WholeProgramOptimization>true</WholeProgramOptimization>
41+
<CharacterSet>Unicode</CharacterSet>
42+
</PropertyGroup>
43+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
44+
<ConfigurationType>Application</ConfigurationType>
45+
<UseDebugLibraries>false</UseDebugLibraries>
46+
<WholeProgramOptimization>true</WholeProgramOptimization>
47+
<CharacterSet>Unicode</CharacterSet>
48+
</PropertyGroup>
49+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
50+
<ImportGroup Label="ExtensionSettings">
51+
</ImportGroup>
52+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
53+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
54+
<Import Project="pyproject.props" />
55+
<Import Project="debug.props" />
56+
</ImportGroup>
57+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
58+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
59+
<Import Project="pyproject.props" />
60+
<Import Project="debug.props" />
61+
<Import Project="x64.props" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
<Import Project="pyproject.props" />
66+
</ImportGroup>
67+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
68+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
69+
<Import Project="pyproject.props" />
70+
<Import Project="x64.props" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74+
<LinkIncremental>false</LinkIncremental>
75+
</PropertyGroup>
76+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
77+
<LinkIncremental>false</LinkIncremental>
78+
</PropertyGroup>
79+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
80+
<LinkIncremental>false</LinkIncremental>
81+
</PropertyGroup>
82+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
83+
<LinkIncremental>false</LinkIncremental>
84+
</PropertyGroup>
85+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
86+
<ClCompile>
87+
<PrecompiledHeader>
88+
</PrecompiledHeader>
89+
<WarningLevel>Level3</WarningLevel>
90+
<Optimization>Disabled</Optimization>
91+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
92+
</ClCompile>
93+
<Link>
94+
<SubSystem>Console</SubSystem>
95+
<GenerateDebugInformation>true</GenerateDebugInformation>
96+
</Link>
97+
</ItemDefinitionGroup>
98+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
99+
<ClCompile>
100+
<PrecompiledHeader>
101+
</PrecompiledHeader>
102+
<WarningLevel>Level3</WarningLevel>
103+
<Optimization>Disabled</Optimization>
104+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
105+
</ClCompile>
106+
<Link>
107+
<SubSystem>Console</SubSystem>
108+
<GenerateDebugInformation>true</GenerateDebugInformation>
109+
</Link>
110+
</ItemDefinitionGroup>
111+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
112+
<ClCompile>
113+
<WarningLevel>Level3</WarningLevel>
114+
<PrecompiledHeader>
115+
</PrecompiledHeader>
116+
<Optimization>MaxSpeed</Optimization>
117+
<FunctionLevelLinking>true</FunctionLevelLinking>
118+
<IntrinsicFunctions>true</IntrinsicFunctions>
119+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
120+
</ClCompile>
121+
<Link>
122+
<SubSystem>Console</SubSystem>
123+
<GenerateDebugInformation>true</GenerateDebugInformation>
124+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
125+
<OptimizeReferences>true</OptimizeReferences>
126+
</Link>
127+
</ItemDefinitionGroup>
128+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
129+
<ClCompile>
130+
<WarningLevel>Level3</WarningLevel>
131+
<PrecompiledHeader>
132+
</PrecompiledHeader>
133+
<Optimization>MaxSpeed</Optimization>
134+
<FunctionLevelLinking>true</FunctionLevelLinking>
135+
<IntrinsicFunctions>true</IntrinsicFunctions>
136+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
137+
</ClCompile>
138+
<Link>
139+
<SubSystem>Console</SubSystem>
140+
<GenerateDebugInformation>true</GenerateDebugInformation>
141+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
142+
<OptimizeReferences>true</OptimizeReferences>
143+
</Link>
144+
</ItemDefinitionGroup>
145+
<ItemGroup>
146+
<ClCompile Include="..\Modules\_testembed.c" />
147+
</ItemGroup>
148+
<ItemGroup>
149+
<ProjectReference Include="pythoncore.vcxproj">
150+
<Project>{cf7ac3d1-e2df-41d2-bea6-1e2556cdea26}</Project>
151+
<Private>true</Private>
152+
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
153+
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
154+
<LinkLibraryDependencies>true</LinkLibraryDependencies>
155+
<UseLibraryDependencyInputs>false</UseLibraryDependencyInputs>
156+
</ProjectReference>
157+
</ItemGroup>
158+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
159+
<ImportGroup Label="ExtensionTargets">
160+
</ImportGroup>
161+
</Project>

PCbuild/_testembed.vcxproj.filters

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="..\Modules\_testembed.c">
19+
<Filter>Source Files</Filter>
20+
</ClCompile>
21+
</ItemGroup>
22+
</Project>

PCbuild/pcbuild.sln

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_sha3", "_sha3.vcxproj", "{
7878
EndProject
7979
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_overlapped", "_overlapped.vcxproj", "{EB6E69DD-04BF-4543-9B92-49FAABCEAC2E}"
8080
EndProject
81+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_testembed", "_testembed.vcxproj", "{6DAC66D9-E703-4624-BE03-49112AB5AA62}"
82+
EndProject
8183
Global
8284
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8385
Debug|Win32 = Debug|Win32
@@ -631,6 +633,22 @@ Global
631633
{254A0C05-6696-4B08-8CB2-EF7D533AEE01}.Release|Win32.Build.0 = Release|Win32
632634
{254A0C05-6696-4B08-8CB2-EF7D533AEE01}.Release|x64.ActiveCfg = Release|x64
633635
{254A0C05-6696-4B08-8CB2-EF7D533AEE01}.Release|x64.Build.0 = Release|x64
636+
{6DAC66D9-E703-4624-BE03-49112AB5AA62}.Debug|Win32.ActiveCfg = Debug|Win32
637+
{6DAC66D9-E703-4624-BE03-49112AB5AA62}.Debug|Win32.Build.0 = Debug|Win32
638+
{6DAC66D9-E703-4624-BE03-49112AB5AA62}.Debug|x64.ActiveCfg = Debug|x64
639+
{6DAC66D9-E703-4624-BE03-49112AB5AA62}.Debug|x64.Build.0 = Debug|x64
640+
{6DAC66D9-E703-4624-BE03-49112AB5AA62}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32
641+
{6DAC66D9-E703-4624-BE03-49112AB5AA62}.PGInstrument|Win32.Build.0 = PGInstrument|Win32
642+
{6DAC66D9-E703-4624-BE03-49112AB5AA62}.PGInstrument|x64.ActiveCfg = PGInstrument|x64
643+
{6DAC66D9-E703-4624-BE03-49112AB5AA62}.PGInstrument|x64.Build.0 = PGInstrument|x64
644+
{6DAC66D9-E703-4624-BE03-49112AB5AA62}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32
645+
{6DAC66D9-E703-4624-BE03-49112AB5AA62}.PGUpdate|Win32.Build.0 = PGUpdate|Win32
646+
{6DAC66D9-E703-4624-BE03-49112AB5AA62}.PGUpdate|x64.ActiveCfg = PGUpdate|x64
647+
{6DAC66D9-E703-4624-BE03-49112AB5AA62}.PGUpdate|x64.Build.0 = PGUpdate|x64
648+
{6DAC66D9-E703-4624-BE03-49112AB5AA62}.Release|Win32.ActiveCfg = Release|Win32
649+
{6DAC66D9-E703-4624-BE03-49112AB5AA62}.Release|Win32.Build.0 = Release|Win32
650+
{6DAC66D9-E703-4624-BE03-49112AB5AA62}.Release|x64.ActiveCfg = Release|x64
651+
{6DAC66D9-E703-4624-BE03-49112AB5AA62}.Release|x64.Build.0 = Release|x64
634652
{EB6E69DD-04BF-4543-9B92-49FAABCEAC2E}.Debug|Win32.ActiveCfg = Debug|Win32
635653
{EB6E69DD-04BF-4543-9B92-49FAABCEAC2E}.Debug|Win32.Build.0 = Debug|Win32
636654
{EB6E69DD-04BF-4543-9B92-49FAABCEAC2E}.Debug|x64.ActiveCfg = Debug|x64

0 commit comments

Comments
 (0)