FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add additional Py test & cleanup · AlgoTradingSrc/pythonnet@88720d5 · GitHub

Repository navigation

Commit 88720d5

Browse files
committed
Add additional Py test & cleanup
1 parent e591632 commit 88720d5

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

‎src/embed_tests/TestMethodBinder.cs‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ public void MethodWithParamsTest()
255255
[Test]
256256
public void TestGenericMethodBinding()
257257
{
258+
// Test matching generic
259+
// i.e. function signature is <T>(Generic<T> var1)
260+
258261
// Run in C#
259262
var class1 = new TestGenericClass1();
260263
var class2 = new TestGenericClass2();
@@ -285,6 +288,9 @@ raise AssertionError('Values were not updated')
285288
[Test]
286289
public void TestMultipleGenericMethodBinding()
287290
{
291+
// Test matching multiple generics
292+
// i.e. function signature is <T,K>(Generic<T,K> var1)
293+
288294
// Run in C#
289295
var class1 = new TestMultipleGenericClass1();
290296
var class2 = new TestMultipleGenericClass2();
@@ -315,6 +321,9 @@ raise AssertionError('Values were not updated')
315321
[Test]
316322
public void TestMultipleGenericParamMethodBinding()
317323
{
324+
// Test multiple param generics matching
325+
// i.e. function signature is <T,K>(Generic1<T> var1, Generic<T,K> var2)
326+
318327
// Run in C#
319328
var class1a = new TestGenericClass1();
320329
var class1b = new TestMultipleGenericClass1();
@@ -358,8 +367,11 @@ raise AssertionError('Values were not updated')
358367
}
359368

360369
[Test]
361-
public void TestMultipleGenericParamMethodBinding2()
370+
public void TestMultipleGenericParamMethodBinding_MixedOrder()
362371
{
372+
// Test matching multiple param generics with mixed order
373+
// i.e. function signature is <T,K>(Generic1<K> var1, Generic<T,K> var2)
374+
363375
// Run in C#
364376
var class1a = new TestGenericClass2();
365377
var class1b = new TestMultipleGenericClass1();
@@ -401,6 +413,33 @@ raise AssertionError('Values were not updated')
401413
"));
402414
}
403415

416+
[Test]
417+
public void TestPyClassGenericBinding(){
418+
// Overriding our generics in Python we should still match with the generic method
419+
Assert.DoesNotThrow(() => PythonEngine.ModuleFromString("test", @"
420+
from clr import AddReference
421+
AddReference(""System"")
422+
AddReference(""Python.EmbeddingTest"")
423+
from Python.EmbeddingTest import *
424+
425+
class PyGenericClass(TestMethodBinder.TestGenericClass1):
426+
pass
427+
428+
class PyMultipleGenericClass(TestMethodBinder.TestMultipleGenericClass1):
429+
pass
430+
431+
singleGenericClass = PyGenericClass()
432+
multiGenericClass = PyMultipleGenericClass()
433+
434+
TestMethodBinder.TestGenericMethod(singleGenericClass)
435+
TestMethodBinder.TestMultipleGenericMethod(multiGenericClass)
436+
TestMethodBinder.TestMultipleGenericParamsMethod(singleGenericClass, multiGenericClass)
437+
438+
if singleGenericClass.Value != 1 or multiGenericClass.Value != 1:
439+
raise AssertionError('Values were not updated')
440+
"));
441+
}
442+
404443
public class CSharpModel
405444
{
406445
public static dynamic ProvidedArgument;

‎src/runtime/methodbinder.cs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,6 @@ internal static MethodInfo ResolveGenericMethod(MethodInfo method, Type[] argTyp
124124
var methodGenerics = method.GetGenericArguments();
125125
var methodGenericMap = new Dictionary<Type, Type>();
126126

127-
// The generics matching these args to the method
128-
var argsGenericMap = new Dictionary<Type, Type[]>();
129-
130127
// Just cache this type for sake of performance on iterations
131128
var objType = typeof(object);
132129

@@ -151,7 +148,6 @@ internal static MethodInfo ResolveGenericMethod(MethodInfo method, Type[] argTyp
151148
// If the generic type matches our params generic definition, this is our match
152149
// go ahead and match these types to this arg
153150
if (paramGenericDefinition == genericType) {
154-
argsGenericMap.Add(argTypes[k], currentType.GenericTypeArguments);
155151

156152
// The matching generic for this method parameter
157153
var paramGenerics = parameters[k].ParameterType.GenericTypeArguments;

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL