-
Notifications
You must be signed in to change notification settings - Fork 772
Domain reload test cases fixes #1287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
fc7da1d
72fafdd
20861b2
2253ef3
635edac
0ee931e
3dad96e
90a81f3
10276f1
4d0e2ce
02fa245
91c881c
284e8e1
fe96781
6ff9e0b
4d2d05b
5f061bc
3adc559
e8543cf
61b0d8c
c8bacf3
cde5c23
a956773
ee3b391
9b4d5f9
a2f3294
46dcb9d
10116bb
102054e
329de5d
f97262b
ceb3fab
2d6ae4c
16a39a6
ace340d
78a8088
3232f79
87287a5
44b4800
79516f1
421f665
5e4c976
9d1991a
bcf0cd6
73e5a6b
510a7ae
21eb14c
59e81e2
1383b5a
fbc06ef
b3e86da
0b027c6
b4533c4
0a3f044
639236a
3069285
5c14aad
00c19d5
833e836
62ae107
eedbae5
73f39bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -913,8 +913,7 @@ public static int Main() | |
| PythonEngine.Initialize(mode:{0}); | ||
| using (Py.GIL()) | ||
| {{ | ||
| // Because the generated assemblies are in the $TEMP folder, add it to the path | ||
| var temp = Path.GetTempPath(); | ||
| var temp = AppDomain.CurrentDomain.BaseDirectory; | ||
| dynamic sys = Py.Import(""sys""); | ||
| sys.path.append(new PyString(temp)); | ||
| dynamic test_mod = Py.Import(""domain_test_module.mod""); | ||
|
|
@@ -938,6 +937,8 @@ public static int Main() | |
| "; | ||
| readonly static string PythonDllLocation = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Python.Runtime.dll"); | ||
|
|
||
| static string TestPath = null; | ||
|
|
||
| public static int Main(string[] args) | ||
| { | ||
| TestCase testCase; | ||
|
|
@@ -951,16 +952,11 @@ public static int Main(string[] args) | |
| Console.WriteLine($"-- Looking for domain reload test case {testName}"); | ||
| testCase = Cases.First(c => c.Name == testName); | ||
| } | ||
|
|
||
| Console.WriteLine($"-- Running domain reload test case: {testCase.Name}"); | ||
|
|
||
| var tempFolderPython = Path.Combine(Path.GetTempPath(), "Python.Runtime.dll"); | ||
| if (File.Exists(tempFolderPython)) | ||
| { | ||
| File.Delete(tempFolderPython); | ||
| } | ||
| SetupTestFolder(testCase.Name); | ||
|
|
||
| File.Copy(PythonDllLocation, tempFolderPython); | ||
|
|
||
| CreatePythonModule(testCase); | ||
| { | ||
| var runnerAssembly = CreateCaseRunnerAssembly(verb:"before"); | ||
|
|
@@ -989,9 +985,32 @@ public static int Main(string[] args) | |
| RunAndUnload(runnerDomain, runnerAssembly); | ||
| } | ||
| } | ||
|
|
||
| // Don't delete unconditionally. It's sometimes useful to leave the | ||
| // folder behind to debug failing tests. | ||
| TeardownTestFolder(); | ||
|
|
||
| return 0; | ||
| } | ||
| #if !NETCOREAPP | ||
|
|
||
| static void SetupTestFolder(string testCaseName) | ||
| { | ||
| TestPath = Path.Combine(Path.GetTempPath(), $"Python.TestRunner.{testCaseName}"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think some random number should also be added to indicate the overall run, so that different runs would not clash.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They wouldn't, if the folder exists when setting up the test, it gets deleted first. Also, the executable can only run one test per invocation. One could run all the tests in parallel, and there'd be no clashing. If a test fails, the folder is not deleted and the contents cans be examined.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still see a problem with running tests for multiple Python versions on the same machine in parallel.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I hadn't thought about that one. I'll add the python version and architecture to the folder name.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add the PID instead |
||
| if (Directory.Exists(TestPath)) | ||
| { | ||
| Directory.Delete(TestPath, recursive: true); | ||
| } | ||
| Directory.CreateDirectory(TestPath); | ||
| File.Copy(PythonDllLocation, Path.Combine(TestPath, "Python.Runtime.dll")); | ||
| } | ||
|
|
||
| static void TeardownTestFolder() | ||
| { | ||
| if (Directory.Exists(TestPath)) | ||
| { | ||
| Directory.Delete(TestPath, recursive: true); | ||
| } | ||
| } | ||
|
|
||
| static void RunAndUnload(AppDomain domain, string assemblyPath) | ||
| { | ||
|
|
@@ -1027,7 +1046,7 @@ static string CreateAssembly(string name, string code, bool exe = false) | |
| CompilerParameters parameters = new CompilerParameters(); | ||
| parameters.GenerateExecutable = exe; | ||
| var assemblyName = name; | ||
| var assemblyFullPath = Path.Combine(Path.GetTempPath(), assemblyName); | ||
| var assemblyFullPath = Path.Combine(TestPath, assemblyName); | ||
| parameters.OutputAssembly = assemblyFullPath; | ||
| parameters.ReferencedAssemblies.Add("System.dll"); | ||
| parameters.ReferencedAssemblies.Add("System.Core.dll"); | ||
|
|
@@ -1062,7 +1081,7 @@ static AppDomain CreateDomain(string name) | |
| var currentDomain = AppDomain.CurrentDomain; | ||
| var domainsetup = new AppDomainSetup() | ||
| { | ||
| ApplicationBase = Path.GetTempPath(), | ||
| ApplicationBase = TestPath, | ||
| ConfigurationFile = currentDomain.SetupInformation.ConfigurationFile, | ||
| LoaderOptimization = LoaderOptimization.SingleDomain, | ||
| PrivateBinPath = "." | ||
|
|
@@ -1077,7 +1096,7 @@ static AppDomain CreateDomain(string name) | |
|
|
||
| static string CreatePythonModule(TestCase testCase) | ||
| { | ||
| var modulePath = Path.Combine(Path.GetTempPath(), "domain_test_module"); | ||
| var modulePath = Path.Combine(TestPath, "domain_test_module"); | ||
| if (Directory.Exists(modulePath)) | ||
| { | ||
| Directory.Delete(modulePath, recursive: true); | ||
|
|
@@ -1092,7 +1111,5 @@ static string CreatePythonModule(TestCase testCase) | |
|
|
||
| return null; | ||
| } | ||
| #endif | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,39 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFrameworks>netstandard2.0</TargetFrameworks> | ||
| <Platforms>AnyCPU</Platforms> | ||
| <RootNamespace>Python.Runtime</RootNamespace> | ||
| <AssemblyName>Python.Runtime</AssemblyName> | ||
| <PackageId>pythonnet</PackageId> | ||
| <PackageLicenseUrl>https://github.com/pythonnet/pythonnet/blob/master/LICENSE</PackageLicenseUrl> | ||
| <RepositoryUrl>https://github.com/pythonnet/pythonnet</RepositoryUrl> | ||
| <RepositoryType>git</RepositoryType> | ||
| <PackageTags>python interop dynamic dlr Mono pinvoke</PackageTags> | ||
| <PackageIconUrl>https://raw.githubusercontent.com/pythonnet/pythonnet/master/src/console/python-clear.ico</PackageIconUrl> | ||
| <PackageProjectUrl>https://pythonnet.github.io/</PackageProjectUrl> | ||
| <NoWarn>1591;NU1701</NoWarn> | ||
| <AllowUnsafeBlocks>True</AllowUnsafeBlocks> | ||
| </PropertyGroup> | ||
| <PropertyGroup> | ||
| <DefineConstants>$(DefineConstants);$(ConfiguredConstants)</DefineConstants> | ||
| </PropertyGroup> | ||
| <ItemGroup Condition=" '$(PythonInteropFile)' != '' "> | ||
| <Compile Remove="interop*.cs" /> | ||
| <Compile Include="interop.cs" /> | ||
| <Compile Include="$(PythonInteropFile)" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <None Remove="resources\clr.py" /> | ||
| <EmbeddedResource Include="resources\clr.py"> | ||
| <LogicalName>clr.py</LogicalName> | ||
| </EmbeddedResource> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="System.Security.Permissions" Version="4.4.0" /> | ||
| <PackageReference Include="System.Reflection.Emit" Version="4.3.0" /> | ||
| </ItemGroup> | ||
| </Project> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFrameworks>netstandard2.0</TargetFrameworks> | ||
| <Platforms>AnyCPU</Platforms> | ||
| <RootNamespace>Python.Runtime</RootNamespace> | ||
| <AssemblyName>Python.Runtime</AssemblyName> | ||
| <PackageId>pythonnet</PackageId> | ||
| <PackageLicenseUrl>https://github.com/pythonnet/pythonnet/blob/master/LICENSE</PackageLicenseUrl> | ||
| <RepositoryUrl>https://github.com/pythonnet/pythonnet</RepositoryUrl> | ||
| <RepositoryType>git</RepositoryType> | ||
| <PackageTags>python interop dynamic dlr Mono pinvoke</PackageTags> | ||
| <PackageIconUrl>https://raw.githubusercontent.com/pythonnet/pythonnet/master/src/console/python-clear.ico</PackageIconUrl> | ||
| <PackageProjectUrl>https://pythonnet.github.io/</PackageProjectUrl> | ||
| <NoWarn>1591;NU1701</NoWarn> | ||
| <AllowUnsafeBlocks>True</AllowUnsafeBlocks> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <DefineConstants>$(DefineConstants);$(ConfiguredConstants)</DefineConstants> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup Condition=" '$(PythonInteropFile)' != '' "> | ||
| <Compile Remove="interop*.cs" /> | ||
| <Compile Include="interop.cs" /> | ||
| <Compile Include="$(PythonInteropFile)" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Remove="resources\clr.py" /> | ||
| <EmbeddedResource Include="resources\clr.py"> | ||
| <LogicalName>clr.py</LogicalName> | ||
| </EmbeddedResource> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="System.Security.Permissions" Version="4.4.0" /> | ||
| <PackageReference Include="System.Reflection.Emit" Version="4.3.0" /> | ||
| </ItemGroup> | ||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,8 @@ internal class MethodBinder | |
|
|
||
| [NonSerialized] | ||
| public bool init = false; | ||
| public bool allow_threads = true; | ||
| public const bool DefaultAllowThreads = true; | ||
| public bool allow_threads = DefaultAllowThreads; | ||
|
|
||
| internal MethodBinder() | ||
| { | ||
|
|
@@ -187,7 +188,7 @@ internal static int GetPrecedence(MethodBase mi) | |
| { | ||
| if (mi == null) | ||
| { | ||
| return -1; | ||
| return int.MaxValue; | ||
| } | ||
|
|
||
|
Comment on lines
+188
to
+193
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think UPD. can this even be null?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it could be null if we change the return type to |
||
| ParameterInfo[] pi = mi.GetParameters(); | ||
|
|
@@ -864,8 +865,8 @@ internal class MethodSorter : IComparer<MaybeMethodBase> | |
| { | ||
| int IComparer<MaybeMethodBase>.Compare(MaybeMethodBase m1, MaybeMethodBase m2) | ||
| { | ||
| MethodBase me1 = m1.Valid ? m1.Value : null; | ||
| MethodBase me2 = m2.Valid ? m2.Value : null; | ||
| MethodBase me1 = m1.UnsafeValue; | ||
| MethodBase me2 = m2.UnsafeValue; | ||
| if (me1 == null && me2 == null) | ||
| { | ||
| return 0; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: I might be more reliable to do
typeof(Py).Assembly.Location.