| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,7 @@ | |||
| 4 | 4 | <AssemblyCopyright>Copyright (c) 2006-2025 The Contributors of the Python.NET Project</AssemblyCopyright> | |
| 5 | 5 | <AssemblyCompany>pythonnet</AssemblyCompany> | |
| 6 | 6 | <AssemblyProduct>Python.NET</AssemblyProduct> | |
| 7 | - <LangVersion>10.0</LangVersion> | ||
| 7 | + <LangVersion>12.0</LangVersion> | ||
| 8 | 8 | <IsPackable>false</IsPackable> | |
| 9 | 9 | <FullVersion>$([System.IO.File]::ReadAllText("$(MSBuildThisFileDirectory)version.txt").Trim())</FullVersion> | |
| 10 | 10 | <VersionPrefix>$(FullVersion.Split('-', 2)[0])</VersionPrefix> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,34 +9,37 @@ namespace Python.EmbeddingTest | |||
| 9 | 9 | { | |
| 10 | 10 | public class CallableObject | |
| 11 | 11 | { | |
| 12 | + IPythonBaseTypeProvider BaseTypeProvider; | ||
| 13 | + | ||
| 12 | 14 | [OneTimeSetUp] | |
| 13 | 15 | public void SetUp() | |
| 14 | 16 | { | |
| 15 | - PythonEngine.Initialize(); | ||
| 16 | 17 | using var locals = new PyDict(); | |
| 17 | 18 | PythonEngine.Exec(CallViaInheritance.BaseClassSource, locals: locals); | |
| 18 | - CustomBaseTypeProvider.BaseClass = new PyType(locals[CallViaInheritance.BaseClassName]); | ||
| 19 | - PythonEngine.InteropConfiguration.PythonBaseTypeProviders.Add(new CustomBaseTypeProvider()); | ||
| 19 | + BaseTypeProvider = new CustomBaseTypeProvider(new PyType(locals[CallViaInheritance.BaseClassName])); | ||
| 20 | + PythonEngine.InteropConfiguration.PythonBaseTypeProviders.Add(BaseTypeProvider); | ||
| 20 | 21 | } | |
| 21 | 22 | ||
| 22 | 23 | [OneTimeTearDown] | |
| 23 | 24 | public void Dispose() | |
| 24 | 25 | { | |
| 25 | - PythonEngine.Shutdown(); | ||
| 26 | + PythonEngine.InteropConfiguration.PythonBaseTypeProviders.Remove(BaseTypeProvider); | ||
| 26 | 27 | } | |
| 28 | + | ||
| 27 | 29 | [Test] | |
| 28 | 30 | public void CallMethodMakesObjectCallable() | |
| 29 | 31 | { | |
| 30 | 32 | var doubler = new DerivedDoubler(); | |
| 31 | 33 | dynamic applyObjectTo21 = PythonEngine.Eval("lambda o: o(21)"); | |
| 32 | - Assert.AreEqual(doubler.__call__(21), (int)applyObjectTo21(doubler.ToPython())); | ||
| 34 | + Assert.That((int)applyObjectTo21(doubler.ToPython()), Is.EqualTo(doubler.__call__(21))); | ||
| 33 | 35 | } | |
| 36 | + | ||
| 34 | 37 | [Test] | |
| 35 | 38 | public void CallMethodCanBeInheritedFromPython() | |
| 36 | 39 | { | |
| 37 | 40 | var callViaInheritance = new CallViaInheritance(); | |
| 38 | 41 | dynamic applyObjectTo14 = PythonEngine.Eval("lambda o: o(14)"); | |
| 39 | - Assert.AreEqual(callViaInheritance.Call(14), (int)applyObjectTo14(callViaInheritance.ToPython())); | ||
| 42 | + Assert.That((int)applyObjectTo14(callViaInheritance.ToPython()), Is.EqualTo(callViaInheritance.Call(14))); | ||
| 40 | 43 | } | |
| 41 | 44 | ||
| 42 | 45 | [Test] | |
@@ -48,7 +51,7 @@ public void CanOverwriteCall() | |||
| 48 | 51 | scope.Exec("orig_call = o.Call"); | |
| 49 | 52 | scope.Exec("o.Call = lambda a: orig_call(a*7)"); | |
| 50 | 53 | int result = scope.Eval<int>("o.Call(5)"); | |
| 51 | - Assert.AreEqual(105, result); | ||
| 54 | + Assert.That(result, Is.EqualTo(105)); | ||
| 52 | 55 | } | |
| 53 | 56 | ||
| 54 | 57 | class Doubler | |
@@ -71,16 +74,14 @@ class {BaseClassName}(MyCallableBase): pass | |||
| 71 | 74 | public int Call(int arg) => 3 * arg; | |
| 72 | 75 | } | |
| 73 | 76 | ||
| 74 | - class CustomBaseTypeProvider : IPythonBaseTypeProvider | ||
| 77 | + class CustomBaseTypeProvider(PyType BaseClass) : IPythonBaseTypeProvider | ||
| 75 | 78 | { | |
| 76 | - internal static PyType BaseClass; | ||
| 77 | - | ||
| 78 | 79 | public IEnumerable<PyType> GetBaseTypes(Type type, IList<PyType> existingBases) | |
| 79 | 80 | { | |
| 80 | - Assert.Greater(BaseClass.Refcount, 0); | ||
| 81 | + Assert.That(BaseClass.Refcount, Is.GreaterThan(0)); | ||
| 81 | 82 | return type != typeof(CallViaInheritance) | |
| 82 | 83 | ? existingBases | |
| 83 | - : new[] { BaseClass }; | ||
| 84 | + : [BaseClass]; | ||
| 84 | 85 | } | |
| 85 | 86 | } | |
| 86 | 87 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,18 +6,6 @@ namespace Python.EmbeddingTest | |||
| 6 | 6 | { | |
| 7 | 7 | public class ClassManagerTests | |
| 8 | 8 | { | |
| 9 | - [OneTimeSetUp] | ||
| 10 | - public void SetUp() | ||
| 11 | - { | ||
| 12 | - PythonEngine.Initialize(); | ||
| 13 | - } | ||
| 14 | - | ||
| 15 | - [OneTimeTearDown] | ||
| 16 | - public void Dispose() | ||
| 17 | - { | ||
| 18 | - PythonEngine.Shutdown(); | ||
| 19 | - } | ||
| 20 | - | ||
| 21 | 9 | [Test] | |
| 22 | 10 | public void NestedClassDerivingFromParent() | |
| 23 | 11 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,7 +20,7 @@ public void GetEncodersByType() | |||
| 20 | 20 | }; | |
| 21 | 21 | ||
| 22 | 22 | var got = group.GetEncoders(typeof(Uri)).ToArray(); | |
| 23 | - CollectionAssert.AreEqual(new[]{encoder1, encoder2}, got); | ||
| 23 | + Assert.That(got, Is.EqualTo(new[] { encoder1, encoder2 }).AsCollection); | ||
| 24 | 24 | } | |
| 25 | 25 | ||
| 26 | 26 | [Test] | |
@@ -31,9 +31,13 @@ public void CanEncode() | |||
| 31 | 31 | new ObjectToEncoderInstanceEncoder<Uri>(), | |
| 32 | 32 | }; | |
| 33 | 33 | ||
| 34 | - Assert.IsTrue(group.CanEncode(typeof(Tuple<int>))); | ||
| 35 | - Assert.IsTrue(group.CanEncode(typeof(Uri))); | ||
| 36 | - Assert.IsFalse(group.CanEncode(typeof(string))); | ||
| 34 | + Assert.Multiple(() => | ||
| 35 | + { | ||
| 36 | + Assert.That(group.CanEncode(typeof(Tuple<int>)), Is.True); | ||
| 37 | + Assert.That(group.CanEncode(typeof(Uri)), Is.True); | ||
| 38 | + Assert.That(group.CanEncode(typeof(string)), Is.False); | ||
| 39 | + }); | ||
| 40 | + | ||
| 37 | 41 | } | |
| 38 | 42 | ||
| 39 | 43 | [Test] | |
@@ -50,12 +54,12 @@ public void Encodes() | |||
| 50 | 54 | ||
| 51 | 55 | var uri = group.TryEncode(new Uri("data:")); | |
| 52 | 56 | var clrObject = (CLRObject)ManagedType.GetManagedObject(uri); | |
| 53 | - Assert.AreSame(encoder1, clrObject.inst); | ||
| 54 | - Assert.AreNotSame(encoder2, clrObject.inst); | ||
| 57 | + Assert.That(clrObject.inst, Is.SameAs(encoder1)); | ||
| 58 | + Assert.That(clrObject.inst, Is.Not.SameAs(encoder2)); | ||
| 55 | 59 | ||
| 56 | 60 | var tuple = group.TryEncode(Tuple.Create(1)); | |
| 57 | 61 | clrObject = (CLRObject)ManagedType.GetManagedObject(tuple); | |
| 58 | - Assert.AreSame(encoder0, clrObject.inst); | ||
| 62 | + Assert.That(clrObject.inst, Is.SameAs(encoder0)); | ||
| 59 | 63 | } | |
| 60 | 64 | ||
| 61 | 65 | [Test] | |
@@ -72,11 +76,11 @@ public void GetDecodersByTypes() | |||
| 72 | 76 | }; | |
| 73 | 77 | ||
| 74 | 78 | var decoder = group.GetDecoder(pyfloat, typeof(string)); | |
| 75 | - Assert.AreSame(decoder2, decoder); | ||
| 79 | + Assert.That(decoder, Is.SameAs(decoder2)); | ||
| 76 | 80 | decoder = group.GetDecoder(pystr, typeof(string)); | |
| 77 | - Assert.IsNull(decoder); | ||
| 81 | + Assert.That(decoder, Is.Null); | ||
| 78 | 82 | decoder = group.GetDecoder(pyint, typeof(long)); | |
| 79 | - Assert.AreSame(decoder1, decoder); | ||
| 83 | + Assert.That(decoder, Is.SameAs(decoder1)); | ||
| 80 | 84 | } | |
| 81 | 85 | [Test] | |
| 82 | 86 | public void CanDecode() | |
@@ -91,10 +95,14 @@ public void CanDecode() | |||
| 91 | 95 | decoder2, | |
| 92 | 96 | }; | |
| 93 | 97 | ||
| 94 | - Assert.IsTrue(group.CanDecode(pyint, typeof(long))); | ||
| 95 | - Assert.IsFalse(group.CanDecode(pyint, typeof(int))); | ||
| 96 | - Assert.IsTrue(group.CanDecode(pyfloat, typeof(string))); | ||
| 97 | - Assert.IsFalse(group.CanDecode(pystr, typeof(string))); | ||
| 98 | + Assert.Multiple(() => | ||
| 99 | + { | ||
| 100 | + Assert.That(group.CanDecode(pyint, typeof(long))); | ||
| 101 | + Assert.That(group.CanDecode(pyint, typeof(int)), Is.False); | ||
| 102 | + Assert.That(group.CanDecode(pyfloat, typeof(string))); | ||
| 103 | + Assert.That(group.CanDecode(pystr, typeof(string)), Is.False); | ||
| 104 | + }); | ||
| 105 | + | ||
| 98 | 106 | } | |
| 99 | 107 | ||
| 100 | 108 | [Test] | |
@@ -109,24 +117,14 @@ public void Decodes() | |||
| 109 | 117 | decoder2, | |
| 110 | 118 | }; | |
| 111 | 119 | ||
| 112 | - Assert.IsTrue(group.TryDecode(new PyInt(10), out long longResult)); | ||
| 113 | - Assert.AreEqual(42, longResult); | ||
| 114 | - Assert.IsTrue(group.TryDecode(new PyFloat(10), out string strResult)); | ||
| 115 | - Assert.AreSame("atad:", strResult); | ||
| 116 | - | ||
| 117 | - Assert.IsFalse(group.TryDecode(new PyInt(10), out int _)); | ||
| 118 | - } | ||
| 119 | - | ||
| 120 | - [SetUp] | ||
| 121 | - public void SetUp() | ||
| 122 | - { | ||
| 123 | - PythonEngine.Initialize(); | ||
| 124 | - } | ||
| 125 | - | ||
| 126 | - [TearDown] | ||
| 127 | - public void Dispose() | ||
| 128 | - { | ||
| 129 | - PythonEngine.Shutdown(); | ||
| 120 | + Assert.Multiple(() => | ||
| 121 | + { | ||
| 122 | + Assert.That(group.TryDecode(new PyInt(10), out long longResult)); | ||
| 123 | + Assert.That(longResult, Is.EqualTo(42)); | ||
| 124 | + Assert.That(group.TryDecode(new PyFloat(10), out string strResult)); | ||
| 125 | + Assert.That(strResult, Is.SameAs("atad:")); | ||
| 126 | + Assert.That(group.TryDecode(new PyInt(10), out int _), Is.False); | ||
| 127 | + }); | ||
| 130 | 128 | } | |
| 131 | 129 | } | |
| 132 | 130 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,18 +8,6 @@ namespace Python.EmbeddingTest { | |||
| 8 | 8 | ||
| 9 | 9 | public class Codecs | |
| 10 | 10 | { | |
| 11 | - [SetUp] | ||
| 12 | - public void SetUp() | ||
| 13 | - { | ||
| 14 | - PythonEngine.Initialize(); | ||
| 15 | - } | ||
| 16 | - | ||
| 17 | - [TearDown] | ||
| 18 | - public void Dispose() | ||
| 19 | - { | ||
| 20 | - PythonEngine.Shutdown(); | ||
| 21 | - } | ||
| 22 | - | ||
| 23 | 11 | [Test] | |
| 24 | 12 | public void TupleConversionsGeneric() | |
| 25 | 13 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,18 +8,6 @@ namespace Python.EmbeddingTest | |||
| 8 | 8 | { | |
| 9 | 9 | public class DynamicTest | |
| 10 | 10 | { | |
| 11 | - [OneTimeSetUp] | ||
| 12 | - public void SetUp() | ||
| 13 | - { | ||
| 14 | - PythonEngine.Initialize(); | ||
| 15 | - } | ||
| 16 | - | ||
| 17 | - [OneTimeTearDown] | ||
| 18 | - public void Dispose() | ||
| 19 | - { | ||
| 20 | - PythonEngine.Shutdown(); | ||
| 21 | - } | ||
| 22 | - | ||
| 23 | 11 | /// <summary> | |
| 24 | 12 | /// Set the attribute of a PyObject with a .NET object. | |
| 25 | 13 | /// </summary> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,25 +8,13 @@ namespace Python.EmbeddingTest; | |||
| 8 | 8 | ||
| 9 | 9 | public class ExtensionTypes | |
| 10 | 10 | { | |
| 11 | - [OneTimeSetUp] | ||
| 12 | - public void SetUp() | ||
| 13 | - { | ||
| 14 | - PythonEngine.Initialize(); | ||
| 15 | - } | ||
| 16 | - | ||
| 17 | - [OneTimeTearDown] | ||
| 18 | - public void Dispose() | ||
| 19 | - { | ||
| 20 | - PythonEngine.Shutdown(); | ||
| 21 | - } | ||
| 22 | - | ||
| 23 | 11 | [Test] | |
| 24 | 12 | public void WeakrefIsNone_AfterBoundMethodIsGone() | |
| 25 | 13 | { | |
| 26 | 14 | using var makeref = Py.Import("weakref").GetAttr("ref"); | |
| 27 | 15 | var boundMethod = new UriBuilder().ToPython().GetAttr(nameof(UriBuilder.GetHashCode)); | |
| 28 | 16 | var weakref = makeref.Invoke(boundMethod); | |
| 29 | 17 | boundMethod.Dispose(); | |
| 30 | - Assert.IsTrue(weakref.Invoke().IsNone()); | ||
| 18 | + Assert.That(weakref.Invoke().IsNone(), Is.True); | ||
| 31 | 19 | } | |
| 32 | 20 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,7 @@ public partial class GlobalTestsSetup | |||
| 13 | 13 | public void GlobalSetup() | |
| 14 | 14 | { | |
| 15 | 15 | Finalizer.Instance.ErrorHandler += FinalizerErrorHandler; | |
| 16 | + PythonEngine.Initialize(); | ||
| 16 | 17 | } | |
| 17 | 18 | ||
| 18 | 19 | private void FinalizerErrorHandler(object sender, Finalizer.ErrorArgs e) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments