Skip to content

Commit 7d7bfb3

Browse files
Fix rebase
1 parent da8f3d2 commit 7d7bfb3

28 files changed

+539
-5262
lines changed

src/embed_tests/QCTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def TestA(self):
2828
public void Setup()
2929
{
3030
PythonEngine.Initialize();
31-
module = PythonEngine.ModuleFromString("module", testModule).GetAttr("PythonModule").Invoke();
31+
module = PyModule.FromString("module", testModule).GetAttr("PythonModule").Invoke();
3232
}
3333

3434
[OneTimeTearDown]

src/embed_tests/TestConverter.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void ConvertListRoundTrip()
4242
var list = new List<Type> { typeof(decimal), typeof(int) };
4343
var py = list.ToPython();
4444
object result;
45-
var converted = Converter.ToManaged(py.Handle, typeof(List<Type>), out result, false);
45+
var converted = Converter.ToManaged(py, typeof(List<Type>), out result, false);
4646

4747
Assert.IsTrue(converted);
4848
Assert.AreEqual(result, list);
@@ -54,7 +54,7 @@ public void GenericList()
5454
var array = new List<Type> { typeof(decimal), typeof(int) };
5555
var py = array.ToPython();
5656
object result;
57-
var converted = Converter.ToManaged(py.Handle, typeof(IList<Type>), out result, false);
57+
var converted = Converter.ToManaged(py, typeof(IList<Type>), out result, false);
5858

5959
Assert.IsTrue(converted);
6060
Assert.AreEqual(typeof(List<Type>), result.GetType());
@@ -69,7 +69,7 @@ public void ReadOnlyCollection()
6969
var array = new List<Type> { typeof(decimal), typeof(int) };
7070
var py = array.ToPython();
7171
object result;
72-
var converted = Converter.ToManaged(py.Handle, typeof(IReadOnlyCollection<Type>), out result, false);
72+
var converted = Converter.ToManaged(py, typeof(IReadOnlyCollection<Type>), out result, false);
7373

7474
Assert.IsTrue(converted);
7575
Assert.AreEqual(typeof(List<Type>), result.GetType());
@@ -85,7 +85,7 @@ public void ConvertPyListToArray()
8585
var py = array.ToPython();
8686
object result;
8787
var outputType = typeof(Type[]);
88-
var converted = Converter.ToManaged(py.Handle, outputType, out result, false);
88+
var converted = Converter.ToManaged(py, outputType, out result, false);
8989

9090
Assert.IsTrue(converted);
9191
Assert.AreEqual(result, array);
@@ -99,7 +99,7 @@ public void ConvertInvalidDateTime()
9999
var pyNumber = number.ToPython();
100100

101101
object result;
102-
var converted = Converter.ToManaged(pyNumber.Handle, typeof(DateTime), out result, false);
102+
var converted = Converter.ToManaged(pyNumber, typeof(DateTime), out result, false);
103103

104104
Assert.IsFalse(converted);
105105
}
@@ -111,7 +111,7 @@ public void ConvertTimeSpanRoundTrip()
111111
var pyTimedelta = timespan.ToPython();
112112

113113
object result;
114-
var converted = Converter.ToManaged(pyTimedelta.Handle, typeof(TimeSpan), out result, false);
114+
var converted = Converter.ToManaged(pyTimedelta, typeof(TimeSpan), out result, false);
115115

116116
Assert.IsTrue(converted);
117117
Assert.AreEqual(result, timespan);
@@ -128,7 +128,7 @@ public void ConvertDecimalPerformance()
128128
{
129129
var pyDecimal = value.ToPython();
130130
object result;
131-
var converted = Converter.ToManaged(pyDecimal.Handle, typeof(decimal), out result, false);
131+
var converted = Converter.ToManaged(pyDecimal, typeof(decimal), out result, false);
132132
if (!converted || result == null)
133133
{
134134
throw new Exception("");
@@ -150,7 +150,7 @@ public void ConvertDateTimeRoundTripPerformance(DateTimeKind kind)
150150
{
151151
var pyDatetime = datetime.ToPython();
152152
object result;
153-
var converted = Converter.ToManaged(pyDatetime.Handle, typeof(DateTime), out result, false);
153+
var converted = Converter.ToManaged(pyDatetime, typeof(DateTime), out result, false);
154154
if (!converted || result == null)
155155
{
156156
throw new Exception("");
@@ -167,7 +167,7 @@ public void ConvertDateTimeRoundTripNoTime()
167167
var pyDatetime = datetime.ToPython();
168168

169169
object result;
170-
var converted = Converter.ToManaged(pyDatetime.Handle, typeof(DateTime), out result, false);
170+
var converted = Converter.ToManaged(pyDatetime, typeof(DateTime), out result, false);
171171

172172
Assert.IsTrue(converted);
173173
Assert.AreEqual(datetime, result);
@@ -181,7 +181,7 @@ public void ConvertDateTimeRoundTrip(DateTimeKind kind)
181181
var pyDatetime = datetime.ToPython();
182182

183183
object result;
184-
var converted = Converter.ToManaged(pyDatetime.Handle, typeof(DateTime), out result, false);
184+
var converted = Converter.ToManaged(pyDatetime, typeof(DateTime), out result, false);
185185

186186
Assert.IsTrue(converted);
187187
Assert.AreEqual(datetime, result);
@@ -194,7 +194,7 @@ public void ConvertTimestampRoundTrip()
194194
var pyTimeSpan = timeSpan.ToPython();
195195

196196
object result;
197-
var converted = Converter.ToManaged(pyTimeSpan.Handle, typeof(TimeSpan), out result, false);
197+
var converted = Converter.ToManaged(pyTimeSpan, typeof(TimeSpan), out result, false);
198198

199199
Assert.IsTrue(converted);
200200
Assert.AreEqual(timeSpan, result);

src/embed_tests/TestMethodBinder.cs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void SetUp()
8181
catch (PythonException)
8282
{
8383
}
84-
module = PythonEngine.ModuleFromString("module", testModule).GetAttr("PythonModel").Invoke();
84+
module = PyModule.FromString("module", testModule).GetAttr("PythonModel").Invoke();
8585
}
8686

8787
[OneTimeTearDown]
@@ -152,7 +152,7 @@ public void ImplicitConversionErrorHandling()
152152
catch (Exception e)
153153
{
154154
errorCaught = true;
155-
Assert.AreEqual("TypeError : Failed to implicitly convert Python.EmbeddingTest.TestMethodBinder+ErroredImplicitConversion to System.String", e.Message);
155+
Assert.AreEqual("Failed to implicitly convert Python.EmbeddingTest.TestMethodBinder+ErroredImplicitConversion to System.String", e.Message);
156156
}
157157

158158
Assert.IsTrue(errorCaught);
@@ -243,7 +243,7 @@ public void NumpyDateTime64()
243243
var numpyDateTime = Numpy.datetime64("2011-02");
244244

245245
object result;
246-
var converted = Converter.ToManaged(numpyDateTime.Handle, typeof(DateTime), out result, false);
246+
var converted = Converter.ToManaged(numpyDateTime, typeof(DateTime), out result, false);
247247

248248
Assert.IsTrue(converted);
249249
Assert.AreEqual(new DateTime(2011, 02, 1), result);
@@ -312,7 +312,7 @@ public void TestNonStaticGenericMethodBinding()
312312
Assert.AreEqual(1, class2.Value);
313313

314314
// Run in Python
315-
Assert.DoesNotThrow(() => PythonEngine.ModuleFromString("test", @"
315+
Assert.DoesNotThrow(() => PyModule.FromString("test", @"
316316
from clr import AddReference
317317
AddReference(""System"")
318318
AddReference(""Python.EmbeddingTest"")
@@ -345,7 +345,7 @@ public void TestGenericMethodBinding()
345345
Assert.AreEqual(1, class2.Value);
346346

347347
// Run in Python
348-
Assert.DoesNotThrow(() => PythonEngine.ModuleFromString("test", @"
348+
Assert.DoesNotThrow(() => PyModule.FromString("test", @"
349349
from clr import AddReference
350350
AddReference(""System"")
351351
AddReference(""Python.EmbeddingTest"")
@@ -378,7 +378,7 @@ public void TestMultipleGenericMethodBinding()
378378
Assert.AreEqual(1, class2.Value);
379379

380380
// Run in Python
381-
Assert.DoesNotThrow(() => PythonEngine.ModuleFromString("test", @"
381+
Assert.DoesNotThrow(() => PyModule.FromString("test", @"
382382
from clr import AddReference
383383
AddReference(""System"")
384384
AddReference(""Python.EmbeddingTest"")
@@ -419,7 +419,7 @@ public void TestMultipleGenericParamMethodBinding()
419419
Assert.AreEqual(1, class2b.Value);
420420

421421
// Run in Python
422-
Assert.DoesNotThrow(() => PythonEngine.ModuleFromString("test", @"
422+
Assert.DoesNotThrow(() => PyModule.FromString("test", @"
423423
from clr import AddReference
424424
AddReference(""System"")
425425
AddReference(""Python.EmbeddingTest"")
@@ -466,7 +466,7 @@ public void TestMultipleGenericParamMethodBinding_MixedOrder()
466466
Assert.AreEqual(1, class2b.Value);
467467

468468
// Run in Python
469-
Assert.DoesNotThrow(() => PythonEngine.ModuleFromString("test", @"
469+
Assert.DoesNotThrow(() => PyModule.FromString("test", @"
470470
from clr import AddReference
471471
AddReference(""System"")
472472
AddReference(""Python.EmbeddingTest"")
@@ -493,7 +493,7 @@ raise AssertionError('Values were not updated')
493493
public void TestPyClassGenericBinding()
494494
{
495495
// Overriding our generics in Python we should still match with the generic method
496-
Assert.DoesNotThrow(() => PythonEngine.ModuleFromString("test", @"
496+
Assert.DoesNotThrow(() => PyModule.FromString("test", @"
497497
from clr import AddReference
498498
AddReference(""System"")
499499
AddReference(""Python.EmbeddingTest"")
@@ -527,7 +527,7 @@ public void TestNonGenericIsUsedWhenAvailable()
527527

528528

529529
// When available, should select non-generic method over generic method
530-
Assert.DoesNotThrow(() => PythonEngine.ModuleFromString("test", @"
530+
Assert.DoesNotThrow(() => PyModule.FromString("test", @"
531531
from clr import AddReference
532532
AddReference(""System"")
533533
AddReference(""Python.EmbeddingTest"")
@@ -551,7 +551,7 @@ public void TestMatchTypedGenericOverload()
551551
TestGenericMethod(class1);
552552
Assert.AreEqual(15, class1.Value);
553553

554-
Assert.DoesNotThrow(() => PythonEngine.ModuleFromString("test", @"
554+
Assert.DoesNotThrow(() => PyModule.FromString("test", @"
555555
from clr import AddReference
556556
AddReference(""System"")
557557
AddReference(""Python.EmbeddingTest"")
@@ -586,7 +586,7 @@ public void TestGenericTypeMatchingWithConvertedPyType()
586586
// This test ensures that we can still match and bind a generic method when we
587587
// have a converted pytype in the args (py timedelta -> C# TimeSpan)
588588

589-
Assert.DoesNotThrow(() => PythonEngine.ModuleFromString("test", @"
589+
Assert.DoesNotThrow(() => PyModule.FromString("test", @"
590590
from datetime import timedelta
591591
from clr import AddReference
592592
AddReference(""System"")
@@ -608,7 +608,7 @@ public void TestGenericTypeMatchingWithDefaultArgs()
608608
{
609609
// This test ensures that we can still match and bind a generic method when we have default args
610610

611-
Assert.DoesNotThrow(() => PythonEngine.ModuleFromString("test", @"
611+
Assert.DoesNotThrow(() => PyModule.FromString("test", @"
612612
from datetime import timedelta
613613
from clr import AddReference
614614
AddReference(""System"")
@@ -628,13 +628,13 @@ raise AssertionError('Value was not 50, was {class1.Value}')
628628
"));
629629
}
630630

631-
[Test]
631+
[Test]
632632
public void TestGenericTypeMatchingWithNullDefaultArgs()
633633
{
634634
// This test ensures that we can still match and bind a generic method when we have \
635635
// null default args, important because caching by arg types occurs
636636

637-
Assert.DoesNotThrow(() => PythonEngine.ModuleFromString("test", @"
637+
Assert.DoesNotThrow(() => PyModule.FromString("test", @"
638638
from datetime import timedelta
639639
from clr import AddReference
640640
AddReference(""System"")
@@ -658,7 +658,7 @@ raise AssertionError('Value was not 50, was {class1.Value}')
658658
public void TestMatchPyDateToDateTime()
659659
{
660660
// This test ensures that we match py datetime.date object to C# DateTime object
661-
Assert.DoesNotThrow(() => PythonEngine.ModuleFromString("test", @"
661+
Assert.DoesNotThrow(() => PyModule.FromString("test", @"
662662
from datetime import *
663663
from clr import AddReference
664664
AddReference(""System"")
@@ -675,7 +675,8 @@ from Python.EmbeddingTest import *
675675

676676

677677
// Used to test that we match this function with Py DateTime & Date Objects
678-
public static int GetMonth(DateTime test){
678+
public static int GetMonth(DateTime test)
679+
{
679680
return test.Month;
680681
}
681682

@@ -875,7 +876,8 @@ public static void TestGenericMethodWithDefault<T>(GenericClassBase<T> test, int
875876
public static void TestGenericMethodWithNullDefault<T>(GenericClassBase<T> test, Object testObj = null)
876877
where T : class
877878
{
878-
if(testObj == null){
879+
if (testObj == null)
880+
{
879881
test.Value = 10;
880882
}
881883
else

0 commit comments

Comments
 (0)