X Tutup
Skip to content
This repository was archived by the owner on Jul 22, 2023. It is now read-only.

Commit 5b2f3d4

Browse files
committed
Merge branch 'master' into soft-shutdown
2 parents aa63f0b + 4d1442d commit 5b2f3d4

29 files changed

+691
-61
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ install:
4646

4747
script:
4848
- python -m pytest
49-
- $RUN_TESTS src/embed_tests/bin/$EMBED_TESTS_PATH/Python.EmbeddingTest.dll
49+
- $RUN_TESTS src/embed_tests/bin/$EMBED_TESTS_PATH/Python.EmbeddingTest.dll --labels=All
5050
# does not work on Linux, because NuGet package for 2.3 is Windows only
5151
# - "if [[ $TRAVIS_PYTHON_VERSION == '3.5' && $PERF_TESTS_PATH != '' ]]; then mono $NUNIT_PATH src/perf_tests/bin/$PERF_TESTS_PATH/Python.PerformanceTests.dll; fi"
5252

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- Alex Earl ([@slide](https://github.com/slide))
1616
- Alex Helms ([@alexhelms](https://github.com/alexhelms))
1717
- Alexandre Catarino([@AlexCatarino](https://github.com/AlexCatarino))
18+
- Andrey Sant'Anna ([@andreydani](https://github.com/andreydani))
1819
- Arvid JB ([@ArvidJB](https://github.com/ArvidJB))
1920
- Benoît Hudson ([@benoithudson](https://github.com/benoithudson))
2021
- Bradley Friedman ([@leith-bartrich](https://github.com/leith-bartrich))

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
2929
together with Nuitka
3030
- Fixes bug where delegates get casts (dotnetcore)
3131
- Determine size of interpreter longs at runtime
32+
- Handling exceptions ocurred in ModuleObject's getattribute
3233

3334
## [2.4.0][]
3435

ci/appveyor_build_recipe.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Build `conda.recipe` only if this is a Pull_Request. Saves time for CI.
22

3+
$stopwatch = [Diagnostics.Stopwatch]::StartNew()
4+
35
$env:CONDA_PY = "$env:PY_VER"
46
# Use pre-installed miniconda. Note that location differs if 64bit
57
$env:CONDA_BLD = "C:\miniconda36"
@@ -30,7 +32,9 @@ if ($env:APPVEYOR_PULL_REQUEST_NUMBER -or $env:APPVEYOR_REPO_TAG_NAME -or $env:F
3032

3133
$CONDA_PKG=(conda build conda.recipe --output)
3234
Copy-Item $CONDA_PKG .\dist\
33-
Write-Host "Completed conda build recipe" -ForegroundColor "Green"
35+
36+
$timeSpent = $stopwatch.Elapsed
37+
Write-Host "Completed conda build recipe in " $timeSpent -ForegroundColor "Green"
3438

3539
# Restore PATH back to original
3640
$env:path = $old_path

ci/appveyor_run_tests.ps1

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Script to simplify AppVeyor configuration and resolve path to tools
22

3+
$stopwatch = [Diagnostics.Stopwatch]::StartNew()
4+
[array]$timings = @()
5+
36
# Test Runner framework being used for embedded tests
47
$CS_RUNNER = "nunit3-console"
58

@@ -25,6 +28,17 @@ $PY = Get-Command python
2528
$CS_TESTS = ".\src\embed_tests\bin\Python.EmbeddingTest.dll"
2629
$RUNTIME_DIR = ".\src\runtime\bin\"
2730

31+
function ReportTime {
32+
param([string] $action)
33+
34+
$timeSpent = $stopwatch.Elapsed
35+
$timings += [pscustomobject]@{action=$action; timeSpent=$timeSpent}
36+
Write-Host $action " in " $timeSpent -ForegroundColor "Green"
37+
$stopwatch.Restart()
38+
}
39+
40+
ReportTime "Preparation done"
41+
2842
# Run python tests with C# coverage
2943
Write-Host ("Starting Python tests") -ForegroundColor "Green"
3044
.$OPENCOVER -register:user -searchdirs:"$RUNTIME_DIR" -output:py.coverage `
@@ -33,18 +47,24 @@ Write-Host ("Starting Python tests") -ForegroundColor "Green"
3347
$PYTHON_STATUS = $LastExitCode
3448
if ($PYTHON_STATUS -ne 0) {
3549
Write-Host "Python tests failed, continuing to embedded tests" -ForegroundColor "Red"
50+
ReportTime ""
51+
} else {
52+
ReportTime "Python tests completed"
3653
}
3754

3855
# Run Embedded tests with C# coverage
3956
Write-Host ("Starting embedded tests") -ForegroundColor "Green"
4057
.$OPENCOVER -register:user -searchdirs:"$RUNTIME_DIR" -output:cs.coverage `
41-
-target:"$CS_RUNNER" -targetargs:"$CS_TESTS" `
58+
-target:"$CS_RUNNER" -targetargs:"$CS_TESTS --labels=All" `
4259
-filter:"+[*]Python.Runtime*" `
4360
-returntargetcode
4461
$CS_STATUS = $LastExitCode
4562
if ($CS_STATUS -ne 0) {
4663
Write-Host "Embedded tests failed" -ForegroundColor "Red"
64+
ReportTime ""
4765
} else {
66+
ReportTime "Embedded tests completed"
67+
4868
# NuGet for pythonnet-2.3 only has 64-bit binary for Python 3.5
4969
# the test is only built using modern stack
5070
if (($env:PLATFORM -eq "x64") -and ($XPLAT) -and ($env:PYTHON_VERSION -eq "3.5")) {
@@ -60,6 +80,9 @@ if ($CS_STATUS -ne 0) {
6080
$CS_PERF_STATUS = $LastExitCode
6181
if ($CS_PERF_STATUS -ne 0) {
6282
Write-Host "Performance tests (C#) failed" -ForegroundColor "Red"
83+
ReportTime ""
84+
} else {
85+
ReportTime "Performance tests (C#) completed"
6386
}
6487
} else {
6588
Write-Host ("Skipping performance tests for ", $env:PYTHON_VERSION) -ForegroundColor "Yellow"
@@ -82,9 +105,14 @@ if ($XPLAT){
82105
$CS_STATUS = $LastExitCode
83106
if ($CS_STATUS -ne 0) {
84107
Write-Host "Embedded tests for netcoreapp2.0 failed" -ForegroundColor "Red"
108+
ReportTime ""
109+
} else {
110+
ReportTime ".NET Core 2.0 tests completed"
85111
}
86112
}
87113

114+
Write-Host "Timings:" ($timings | Format-Table | Out-String) -ForegroundColor "Green"
115+
88116
# Set exit code to fail if either Python or Embedded tests failed
89117
if ($PYTHON_STATUS -ne 0 -or $CS_STATUS -ne 0 -or $CS_PERF_STATUS -ne 0) {
90118
Write-Host "Tests failed" -ForegroundColor "Red"

src/embed_tests/Codecs.cs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
namespace Python.EmbeddingTest {
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
using NUnit.Framework;
6+
using Python.Runtime;
7+
using Python.Runtime.Codecs;
8+
9+
public class Codecs {
10+
[SetUp]
11+
public void SetUp() {
12+
PythonEngine.Initialize();
13+
}
14+
15+
[TearDown]
16+
public void Dispose() {
17+
PythonEngine.Shutdown();
18+
}
19+
20+
[Test]
21+
public void ConversionsGeneric() {
22+
ConversionsGeneric<ValueTuple<int, string, object>, ValueTuple>();
23+
}
24+
25+
static void ConversionsGeneric<T, TTuple>() {
26+
TupleCodec<TTuple>.Register();
27+
var tuple = Activator.CreateInstance(typeof(T), 42, "42", new object());
28+
T restored = default;
29+
using (Py.GIL())
30+
using (var scope = Py.CreateScope()) {
31+
void Accept(T value) => restored = value;
32+
var accept = new Action<T>(Accept).ToPython();
33+
scope.Set(nameof(tuple), tuple);
34+
scope.Set(nameof(accept), accept);
35+
scope.Exec($"{nameof(accept)}({nameof(tuple)})");
36+
Assert.AreEqual(expected: tuple, actual: restored);
37+
}
38+
}
39+
40+
[Test]
41+
public void ConversionsObject() {
42+
ConversionsObject<ValueTuple<int, string, object>, ValueTuple>();
43+
}
44+
static void ConversionsObject<T, TTuple>() {
45+
TupleCodec<TTuple>.Register();
46+
var tuple = Activator.CreateInstance(typeof(T), 42, "42", new object());
47+
T restored = default;
48+
using (Py.GIL())
49+
using (var scope = Py.CreateScope()) {
50+
void Accept(object value) => restored = (T)value;
51+
var accept = new Action<object>(Accept).ToPython();
52+
scope.Set(nameof(tuple), tuple);
53+
scope.Set(nameof(accept), accept);
54+
scope.Exec($"{nameof(accept)}({nameof(tuple)})");
55+
Assert.AreEqual(expected: tuple, actual: restored);
56+
}
57+
}
58+
59+
[Test]
60+
public void TupleRoundtripObject() {
61+
TupleRoundtripObject<ValueTuple<int, string, object>, ValueTuple>();
62+
}
63+
static void TupleRoundtripObject<T, TTuple>() {
64+
var tuple = Activator.CreateInstance(typeof(T), 42, "42", new object());
65+
using (Py.GIL()) {
66+
var pyTuple = TupleCodec<TTuple>.Instance.TryEncode(tuple);
67+
Assert.IsTrue(TupleCodec<TTuple>.Instance.TryDecode(pyTuple, out object restored));
68+
Assert.AreEqual(expected: tuple, actual: restored);
69+
}
70+
}
71+
72+
[Test]
73+
public void TupleRoundtripGeneric() {
74+
TupleRoundtripGeneric<ValueTuple<int, string, object>, ValueTuple>();
75+
}
76+
77+
static void TupleRoundtripGeneric<T, TTuple>() {
78+
var tuple = Activator.CreateInstance(typeof(T), 42, "42", new object());
79+
using (Py.GIL()) {
80+
var pyTuple = TupleCodec<TTuple>.Instance.TryEncode(tuple);
81+
Assert.IsTrue(TupleCodec<TTuple>.Instance.TryDecode(pyTuple, out T restored));
82+
Assert.AreEqual(expected: tuple, actual: restored);
83+
}
84+
}
85+
}
86+
}

src/embed_tests/Python.EmbeddingTest.15.csproj

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
2424
<PythonBuildDir Condition="'$(TargetFramework)'=='net40' AND '$(PythonBuildDir)' == ''">$(SolutionDir)\bin\</PythonBuildDir>
2525
<PublishDir Condition="'$(TargetFramework)'!='net40'">$(OutputPath)\$(TargetFramework)_publish</PublishDir>
26-
<LangVersion>6</LangVersion>
26+
<LangVersion>7.3</LangVersion>
2727
<ErrorReport>prompt</ErrorReport>
2828
<CustomDefineConstants Condition="'$(CustomDefineConstants)' == ''">$(PYTHONNET_DEFINE_CONSTANTS)</CustomDefineConstants>
2929
<BaseDefineConstants>XPLAT</BaseDefineConstants>
@@ -77,13 +77,17 @@
7777

7878

7979
<ItemGroup>
80-
<PackageReference Include="NUnit" Version="3.7.1" />
81-
<PackageReference Include="NUnit.ConsoleRunner" Version="3.7.0" />
82-
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0" />
83-
<PackageReference Include="NUnitLite" Version="3.7.2" />
80+
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
81+
<PackageReference Include="NUnit" Version="3.12.0" />
82+
<PackageReference Include="NUnit.ConsoleRunner" Version="3.11.1" />
83+
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
84+
<PrivateAssets>all</PrivateAssets>
85+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
86+
</PackageReference>
87+
<PackageReference Include="NUnitLite" Version="3.12.0" />
8488
</ItemGroup>
8589
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
86-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
90+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
8791
</ItemGroup>
8892
<ItemGroup>
8993
<ProjectReference Include="..\runtime\Python.Runtime.15.csproj" />

src/embed_tests/Python.EmbeddingTest.csproj

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<NoWarn>1591</NoWarn>
1515
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
1616
<PythonBuildDir Condition=" '$(PythonBuildDir)' == '' ">$(SolutionDir)\bin\</PythonBuildDir>
17-
<LangVersion>6</LangVersion>
17+
<LangVersion>7.3</LangVersion>
1818
<RestorePackages>true</RestorePackages>
1919
<ErrorReport>prompt</ErrorReport>
2020
</PropertyGroup>
@@ -70,8 +70,11 @@
7070
</PropertyGroup>
7171
<ItemGroup>
7272
<Reference Include="Microsoft.CSharp" />
73-
<Reference Include="nunit.framework, Version=3.7.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
74-
<HintPath>..\..\packages\NUnit.3.7.1\lib\net40\nunit.framework.dll</HintPath>
73+
<Reference Include="nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
74+
<HintPath>..\..\packages\NUnit.3.12.0\lib\net40\nunit.framework.dll</HintPath>
75+
</Reference>
76+
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
77+
<HintPath>..\..\packages\System.ValueTuple.4.5.0\lib\portable-net40+sl4+win8+wp8\System.ValueTuple.dll</HintPath>
7578
</Reference>
7679
<Reference Include="System" />
7780
</ItemGroup>
@@ -80,6 +83,7 @@
8083
<None Include="packages.config" />
8184
</ItemGroup>
8285
<ItemGroup>
86+
<Compile Include="Codecs.cs" />
8387
<Compile Include="dynamic.cs" />
8488
<Compile Include="pyimport.cs" />
8589
<Compile Include="pyinitialize.cs" />
@@ -126,4 +130,10 @@
126130
<Copy SourceFiles="$(TargetAssembly)" DestinationFolder="$(PythonBuildDir)" />
127131
<!--Copy SourceFiles="$(TargetAssemblyPdb)" Condition="Exists('$(TargetAssemblyPdb)')" DestinationFolder="$(PythonBuildDir)" /-->
128132
</Target>
133+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
134+
<PropertyGroup>
135+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
136+
</PropertyGroup>
137+
<Error Condition="!Exists('..\..\packages\NUnit.3.12.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\NUnit.3.12.0\build\NUnit.props'))" />
138+
</Target>
129139
</Project>

src/embed_tests/TestRuntime.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using NUnit.Framework;
34
using Python.Runtime;
45
using Python.Runtime.Platform;
@@ -113,9 +114,15 @@ public static void PyCheck_Iter_PyObject_IsIterable_ThreadingLock_Test()
113114
// Create an instance of threading.Lock, which is one of the very few types that does not have the
114115
// TypeFlags.HaveIter set in Python 2. This tests a different code path in PyObject_IsIterable and PyIter_Check.
115116
var threading = Runtime.Runtime.PyImport_ImportModule("threading");
117+
Exceptions.ErrorCheck(threading);
116118
var threadingDict = Runtime.Runtime.PyModule_GetDict(threading);
119+
Exceptions.ErrorCheck(threadingDict);
117120
var lockType = Runtime.Runtime.PyDict_GetItemString(threadingDict, "Lock");
121+
if (lockType == IntPtr.Zero)
122+
throw new KeyNotFoundException("class 'Lock' was not found in 'threading'");
123+
118124
var lockInstance = Runtime.Runtime.PyObject_CallObject(lockType, Runtime.Runtime.PyTuple_New(0));
125+
Exceptions.ErrorCheck(lockInstance);
119126

120127
Assert.IsFalse(Runtime.Runtime.PyObject_IsIterable(lockInstance));
121128
Assert.IsFalse(Runtime.Runtime.PyIter_Check(lockInstance));

src/embed_tests/packages.config

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="NUnit" version="3.7.1" targetFramework="net40" />
4-
<package id="NUnit.ConsoleRunner" version="3.7.0" targetFramework="net40" />
3+
<package id="NUnit" version="3.12.0" targetFramework="net40" />
4+
<package id="NUnit.ConsoleRunner" version="3.11.1" targetFramework="net40" />
5+
<package id="System.ValueTuple" version="4.5.0" targetFramework="net40" />
56
</packages>

0 commit comments

Comments
 (0)
X Tutup