Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<AssemblyCopyright>Copyright (c) 2006-2025 The Contributors of the Python.NET Project</AssemblyCopyright>
<AssemblyCompany>pythonnet</AssemblyCompany>
<AssemblyProduct>Python.NET</AssemblyProduct>
<LangVersion>12.0</LangVersion>
<LangVersion>14</LangVersion>
<IsPackable>false</IsPackable>
<DeterministicSourcePaths>true</DeterministicSourcePaths>
<FullVersion>$([System.IO.File]::ReadAllText("$(MSBuildThisFileDirectory)version.txt").Trim())</FullVersion>
Expand Down
28 changes: 14 additions & 14 deletions src/embed_tests/Codecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static void TupleConversionsGeneric<T, TTuple>()
scope.Set(nameof(tuple), tuple);
scope.Set(nameof(accept), accept);
scope.Exec($"{nameof(accept)}({nameof(tuple)})");
Assert.AreEqual(expected: tuple, actual: restored);
Assert.That(actual: restored, Is.EqualTo(expected: tuple));
}
}

Expand All @@ -53,7 +53,7 @@ static void TupleConversionsObject<T, TTuple>()
scope.Set(nameof(tuple), tuple);
scope.Set(nameof(accept), accept);
scope.Exec($"{nameof(accept)}({nameof(tuple)})");
Assert.AreEqual(expected: tuple, actual: restored);
Assert.That(actual: restored, Is.EqualTo(expected: tuple));
}
}

Expand All @@ -67,7 +67,7 @@ static void TupleRoundtripObject<T, TTuple>()
var tuple = Activator.CreateInstance(typeof(T), 42.0, "42", new object());
using var pyTuple = TupleCodec<TTuple>.Instance.TryEncode(tuple);
Assert.IsTrue(TupleCodec<TTuple>.Instance.TryDecode(pyTuple, out object restored));
Assert.AreEqual(expected: tuple, actual: restored);
Assert.That(actual: restored, Is.EqualTo(expected: tuple));
}

[Test]
Expand All @@ -81,7 +81,7 @@ static void TupleRoundtripGeneric<T, TTuple>()
var tuple = Activator.CreateInstance(typeof(T), 42, "42", new object());
using var pyTuple = TupleCodec<TTuple>.Instance.TryEncode(tuple);
Assert.IsTrue(TupleCodec<TTuple>.Instance.TryDecode(pyTuple, out T restored));
Assert.AreEqual(expected: tuple, actual: restored);
Assert.That(actual: restored, Is.EqualTo(expected: tuple));
}

static PyObject GetPythonIterable() => PythonEngine.Eval("map(lambda x: x, [1,2,3])");
Expand Down Expand Up @@ -118,7 +118,7 @@ public void ListDecoderTest()
//the IList will report a Count of 3.
IList<string> stringList = null;
Assert.DoesNotThrow(() => { codec.TryDecode(pyList, out stringList); });
Assert.AreEqual(stringList.Count, 3);
Assert.That(3, Is.EqualTo(stringList.Count));
Assert.Throws(typeof(InvalidCastException), () => { var x = stringList[0]; });

//can't convert python iterable to list (this will require a copy which isn't lossless)
Expand Down Expand Up @@ -162,8 +162,8 @@ public void SequenceDecoderTest()
//the IList will report a Count of 3.
ICollection<string> stringCollection = null;
Assert.DoesNotThrow(() => { codec.TryDecode(pyList, out stringCollection); });
Assert.AreEqual(3, stringCollection.Count());
Assert.Throws(typeof(InvalidCastException), () => {
Assert.That(stringCollection.Count(), Is.EqualTo(3));
Assert.Throws<InvalidCastException>(() => {
string[] array = new string[3];
stringCollection.CopyTo(array, 0);
});
Expand Down Expand Up @@ -199,8 +199,8 @@ public void SequenceDecoderTest()
//the IList will report a Count of 3.
ICollection<string> stringCollection2 = null;
Assert.DoesNotThrow(() => { codec.TryDecode(pyTuple, out stringCollection2); });
Assert.AreEqual(3, stringCollection2.Count());
Assert.Throws(typeof(InvalidCastException), () => {
Assert.That(stringCollection2.Count, Is.EqualTo(3));
Assert.Throws<InvalidCastException>(() => {
string[] array = new string[3];
stringCollection2.CopyTo(array, 0);
});
Expand Down Expand Up @@ -321,7 +321,7 @@ def call(func):
");
var callFunc = scope.Get("call");
string message = callFunc.Invoke(callMeAction.ToPython()).As<string>();
Assert.AreEqual(TestExceptionMessage, message);
Assert.That(message, Is.EqualTo(TestExceptionMessage));
}

[Test]
Expand All @@ -331,7 +331,7 @@ public void ExceptionDecoded()
using var scope = Py.CreateScope();
var error = Assert.Throws<ValueErrorWrapper>(()
=> PythonEngine.Exec($"raise ValueError('{TestExceptionMessage}')"));
Assert.AreEqual(TestExceptionMessage, error.Message);
Assert.That(error.Message, Is.EqualTo(TestExceptionMessage));
}

[Test]
Expand Down Expand Up @@ -360,7 +360,7 @@ public void FloatDerivedDecoded()
PyObjectConversions.RegisterDecoder(decoder);
using var result = scope.Eval("FloatDerived()");
object decoded = result.As<object>();
Assert.AreEqual(42, decoded);
Assert.That(decoded, Is.EqualTo(42));
}

[Test]
Expand All @@ -374,7 +374,7 @@ public void ExceptionDecodedNoInstance()
var error = Assert.Throws<ValueErrorWrapper>(() =>
PythonEngine.Exec($"[].__iter__().__next__()")
);
Assert.AreEqual(TestExceptionMessage, error.Message);
Assert.That(error.Message, Is.EqualTo(TestExceptionMessage));
}
else
{
Expand All @@ -395,7 +395,7 @@ public void As_Object_AffectedByDecoders()

var pyObj = PythonEngine.Eval("iter");
var decoded = pyObj.As<object>();
Assert.AreSame(everythingElseToSelf, decoded);
Assert.That(decoded, Is.SameAs(everythingElseToSelf));
}

public class EverythingElseToSelfDecoder : IPyObjectDecoder
Expand Down
20 changes: 5 additions & 15 deletions src/embed_tests/Dynamic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public void AssignObject()
sys.testattr = stream;
// Check whether there are the same object.
dynamic _stream = sys.testattr.AsManagedObject(typeof(StringBuilder));
Assert.AreEqual(_stream, stream);
Assert.That(_stream, Is.EqualTo(stream));

PythonEngine.RunSimpleString(
"import sys\n" +
"sys.testattr.Append('Hello!')\n");
Assert.AreEqual(stream.ToString(), "Hello!");
Assert.That(stream.ToString(), Is.EqualTo("Hello!"));
}

/// <summary>
Expand All @@ -45,25 +45,15 @@ public void AssignNone()
/// Check whether we can get the attr of a python object when the
/// value of attr is a PyObject.
/// </summary>
/// <remarks>
/// FIXME: Issue on Travis PY27: Error : Python.EmbeddingTest.dynamicTest.AssignPyObject
/// Python.Runtime.PythonException : ImportError : /home/travis/virtualenv/python2.7.9/lib/python2.7/lib-dynload/_io.so: undefined symbol: _PyLong_AsInt
/// </remarks>
[Test]
public void AssignPyObject()
{
if (Environment.GetEnvironmentVariable("TRAVIS") == "true" &&
Environment.GetEnvironmentVariable("TRAVIS_PYTHON_VERSION") == "2.7")
{
Assert.Ignore("Fails on Travis/PY27: ImportError: ... undefined symbol: _PyLong_AsInt");
}

dynamic sys = Py.Import("sys");
dynamic io = Py.Import("io");
sys.testattr = io.StringIO();
dynamic bb = sys.testattr; // Get the PyObject
bb.write("Hello!");
Assert.AreEqual(bb.getvalue().ToString(), "Hello!");
Assert.That(bb.getvalue().ToString(), Is.EqualTo("Hello!"));
}

/// <summary>
Expand All @@ -87,7 +77,7 @@ public void PassObjectInPython()
"import sys\n" +
"sys.testattr3 = sys.testattr1 is sys.testattr2\n"
);
Assert.AreEqual(sys.testattr3.ToString(), "True");
Assert.That(sys.testattr3.ToString(), Is.EqualTo("True"));

// Compare in .NET
Assert.IsTrue(sys.testattr1.Equals(sys.testattr2));
Expand All @@ -110,7 +100,7 @@ public void PassPyObjectInNet()
"sys.testattr3 = sys.testattr1 is sys.testattr2\n"
);

Assert.AreEqual(sys.testattr3.ToString(), "True");
Assert.That(sys.testattr3.ToString(), Is.EqualTo("True"));

// Compare in .NET
Assert.IsTrue(sys.testattr1.Equals(sys.testattr2));
Expand Down
2 changes: 1 addition & 1 deletion src/embed_tests/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
gc.collect()
");
Runtime.Runtime.TryCollectingGarbage(10);
Assert.AreEqual(0, ClassWithEventHandler.alive);
Assert.That(ClassWithEventHandler.alive, Is.EqualTo(0));
}
}

Expand All @@ -39,7 +39,7 @@
{
internal static int alive;

public event EventHandler LeakEvent;

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, arm64, ubuntu-22.04-arm, 3.11)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, arm64, ubuntu-22.04-arm, 3.11)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, arm64, ubuntu-22.04-arm, 3.10)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, arm64, ubuntu-22.04-arm, 3.10)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, arm64, ubuntu-22.04-arm, 3.13)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, arm64, ubuntu-22.04-arm, 3.13)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (windows, x86, windows-latest, -windows-x86-none, 3.11)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (windows, x86, windows-latest, -windows-x86-none, 3.11)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (windows, x86, windows-latest, -windows-x86-none, 3.12)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (windows, x86, windows-latest, -windows-x86-none, 3.12)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (windows, x64, windows-latest, -windows-x86_64-none, 3.12)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (windows, x64, windows-latest, -windows-x86_64-none, 3.12)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, arm64, ubuntu-22.04-arm, 3.12)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, arm64, ubuntu-22.04-arm, 3.12)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, x64, ubuntu-22.04, 3.14)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, x64, ubuntu-22.04, 3.14)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, arm64, ubuntu-22.04-arm, 3.14)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, arm64, ubuntu-22.04-arm, 3.14)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, x64, ubuntu-22.04, 3.12)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, x64, ubuntu-22.04, 3.12)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, x64, ubuntu-22.04, 3.10)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, x64, ubuntu-22.04, 3.10)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, x64, ubuntu-22.04, 3.13)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, x64, ubuntu-22.04, 3.13)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, x64, ubuntu-22.04, 3.11)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, x64, ubuntu-22.04, 3.11)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (windows, x64, windows-latest, -windows-x86_64-none, 3.14)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (windows, x64, windows-latest, -windows-x86_64-none, 3.14)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (windows, x86, windows-latest, -windows-x86-none, 3.14)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (windows, x86, windows-latest, -windows-x86-none, 3.14)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (windows, x64, windows-latest, -windows-x86_64-none, 3.13)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (windows, x64, windows-latest, -windows-x86_64-none, 3.13)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (windows, x64, windows-latest, -windows-x86_64-none, 3.11)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (windows, x64, windows-latest, -windows-x86_64-none, 3.11)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, arm64, macos-15, -macos-aarch64-none, 3.10)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, arm64, macos-15, -macos-aarch64-none, 3.10)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, arm64, macos-15, -macos-aarch64-none, 3.12)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, arm64, macos-15, -macos-aarch64-none, 3.12)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, arm64, macos-15, -macos-aarch64-none, 3.11)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, arm64, macos-15, -macos-aarch64-none, 3.11)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, x64, macos-15, -macos-x86_64-none, 3.14)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, x64, macos-15, -macos-x86_64-none, 3.14)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, arm64, macos-15, -macos-aarch64-none, 3.13)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, arm64, macos-15, -macos-aarch64-none, 3.13)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, x64, macos-15, -macos-x86_64-none, 3.10)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, x64, macos-15, -macos-x86_64-none, 3.10)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, x64, macos-15, -macos-x86_64-none, 3.13)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, x64, macos-15, -macos-x86_64-none, 3.13)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, arm64, macos-15, -macos-aarch64-none, 3.14)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, arm64, macos-15, -macos-aarch64-none, 3.14)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, x64, macos-15, -macos-x86_64-none, 3.11)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, x64, macos-15, -macos-x86_64-none, 3.11)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, x64, macos-15, -macos-x86_64-none, 3.12)

The event 'ClassWithEventHandler.LeakEvent' is never used

Check warning on line 42 in src/embed_tests/Events.cs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, x64, macos-15, -macos-x86_64-none, 3.12)

The event 'ClassWithEventHandler.LeakEvent' is never used
private Array arr; // dummy array to exacerbate memory leak

public ClassWithEventHandler()
Expand Down
18 changes: 9 additions & 9 deletions src/embed_tests/Modules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ public void TestScopeClass()
);
dynamic obj1 = _ps.Class1(20);
var result = obj1.call(10).As<int>();
Assert.AreEqual(130, result);
Assert.That(result, Is.EqualTo(130));

obj1.update(10);
result = ps.Get<int>("bb");
Assert.AreEqual(30, result);
Assert.That(result, Is.EqualTo(30));
}
}

Expand Down Expand Up @@ -185,11 +185,11 @@ public void TestCreateVirtualPackageStructure()

dynamic obj1 = ps2.Class1(20);
var result = obj1.call(10).As<int>();
Assert.AreEqual(130, result);
Assert.That(result, Is.EqualTo(130));

obj1.update(10);
result = ps2.Get<int>("bb");
Assert.AreEqual(30, result);
Assert.That(result, Is.EqualTo(30));
}
}

Expand Down Expand Up @@ -229,7 +229,7 @@ public void TestImportModule()
var value1 = ps.Eval<int>("sys.attr1");
var value2 = sys.attr1.As<int>();
Assert.That(value1, Is.EqualTo(2));
Assert.AreEqual(2, value2);
Assert.That(value2, Is.EqualTo(2));

//import as
ps.Import("sys", "sys1");
Expand Down Expand Up @@ -308,16 +308,16 @@ public void TestImportScopeFunction()
dynamic func2 = scope.Get("func2");

var result1 = func2().As<int>();
Assert.AreEqual(0, result1);
Assert.That(result1, Is.EqualTo(0));

scope.Set("cc", 20);//it has no effect on the globals of 'func1'
var result2 = func2().As<int>();
Assert.AreEqual(-10, result2);
Assert.That(result2, Is.EqualTo(-10));
scope.Set("cc", 10); //rollback

ps.Set("cc", 20);
var result3 = func2().As<int>();
Assert.AreEqual(10, result3);
Assert.That(result3, Is.EqualTo(10));
ps.Set("cc", 10); //rollback
}
}
Expand Down Expand Up @@ -437,7 +437,7 @@ public void TestCreate()
scope.Execute(code);

Assert.That(scope.TryGet("x", out dynamic x), Is.True);
Assert.AreEqual("True", x.ToString());
Assert.That(x.ToString(), Is.EqualTo("True"));
}

[Test]
Expand Down
4 changes: 2 additions & 2 deletions src/embed_tests/NeedsReinit/TestDomainReload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ public override ValueType Execute(ValueType arg)
");
}
var clrObj = obj.As<Domain.MyClass>();
Assert.AreEqual(clrObj.Property, 2);
Assert.AreEqual(clrObj.Field, 20);
Assert.That(2, Is.EqualTo(clrObj.Property));
Assert.That(20, Is.EqualTo(clrObj.Field));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/embed_tests/NeedsReinit/TestPyInitialize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static void LoadDefaultArgs()
{
using(var argv = new PyList(Runtime.Runtime.PySys_GetObject("argv")))
{
Assert.AreNotEqual(0, argv.Length());
Assert.That(argv.Length(), Is.Not.EqualTo(0));
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/embed_tests/NeedsReinit/TestPythonEngineProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void SetPythonHome()
PythonEngine.PythonHome = pythonHome;
PythonEngine.Initialize();

Assert.AreEqual(pythonHome, PythonEngine.PythonHome);
Assert.That(PythonEngine.PythonHome, Is.EqualTo(pythonHome));
PythonEngine.Shutdown();

// Restoring valid pythonhome.
Expand All @@ -45,7 +45,7 @@ public void SetPythonHomeTwice()
PythonEngine.PythonHome = pythonHome;
PythonEngine.Initialize();

Assert.AreEqual(pythonHome, PythonEngine.PythonHome);
Assert.That(PythonEngine.PythonHome, Is.EqualTo(pythonHome));
PythonEngine.Shutdown();

PythonEngine.PythonHome = pythonHomeBackup;
Expand All @@ -65,7 +65,7 @@ public void SetPythonHomeEmptyString()
}
PythonEngine.PythonHome = "";

Assert.AreEqual("", PythonEngine.PythonHome);
Assert.That(PythonEngine.PythonHome, Is.EqualTo(""));

PythonEngine.PythonHome = backup;
PythonEngine.Shutdown();
Expand All @@ -86,7 +86,7 @@ public void SetProgramName()
PythonEngine.ProgramName = programName;
PythonEngine.Initialize();

Assert.AreEqual(programName, PythonEngine.ProgramName);
Assert.That(PythonEngine.ProgramName, Is.EqualTo(programName));
PythonEngine.Shutdown();

PythonEngine.ProgramName = programNameBackup;
Expand Down Expand Up @@ -124,7 +124,7 @@ public void SetPythonPath()
PythonEngine.PythonPath = path;
PythonEngine.Initialize();

Assert.AreEqual(path, PythonEngine.PythonPath);
Assert.That(PythonEngine.PythonPath, Is.EqualTo(path));
if (importShouldSucceed) Py.Import(moduleName);

PythonEngine.Shutdown();
Expand Down
20 changes: 10 additions & 10 deletions src/embed_tests/NeedsReinit/TestRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public static void Py_IsInitializedValue()
Runtime.Runtime.PyGILState_Ensure();
}
Runtime.Runtime.Py_Finalize();
Assert.AreEqual(0, Runtime.Runtime.Py_IsInitialized());
Assert.That(Runtime.Runtime.Py_IsInitialized(), Is.EqualTo(0));
Runtime.Runtime.Py_Initialize();
Assert.AreEqual(1, Runtime.Runtime.Py_IsInitialized());
Assert.That(Runtime.Runtime.Py_IsInitialized(), Is.EqualTo(1));
Runtime.Runtime.Py_Finalize();
Assert.AreEqual(0, Runtime.Runtime.Py_IsInitialized());
Assert.That(Runtime.Runtime.Py_IsInitialized(), Is.EqualTo(0));
}

[Test]
Expand All @@ -30,27 +30,27 @@ public static void RefCountTest()
using var op = Runtime.Runtime.PyString_FromString("FooBar");

// New object RefCount should be one
Assert.AreEqual(1, Runtime.Runtime.Refcount32(op.BorrowOrThrow()));
Assert.That(Runtime.Runtime.Refcount32(op.BorrowOrThrow()), Is.EqualTo(1));

// Checking refcount didn't change refcount
Assert.AreEqual(1, Runtime.Runtime.Refcount32(op.Borrow()));
Assert.That(Runtime.Runtime.Refcount32(op.Borrow()), Is.EqualTo(1));

// Borrowing a reference doesn't increase refcount
BorrowedReference p = op.Borrow();
Assert.AreEqual(1, Runtime.Runtime.Refcount32(p));
Assert.That(Runtime.Runtime.Refcount32(p), Is.EqualTo(1));

// Py_IncRef/Py_DecRef increase and decrease RefCount
Runtime.Runtime.Py_IncRef(op.Borrow());
Assert.AreEqual(2, Runtime.Runtime.Refcount32(p));
Assert.That(Runtime.Runtime.Refcount32(p), Is.EqualTo(2));
Runtime.Runtime.Py_DecRef(StolenReference.DangerousFromPointer(op.DangerousGetAddress()));
Assert.AreEqual(1, Runtime.Runtime.Refcount32(p));
Assert.That(Runtime.Runtime.Refcount32(p), Is.EqualTo(1));

// XIncref/XDecref increase and decrease RefCount
#pragma warning disable CS0618 // Type or member is obsolete. We are testing corresponding members
Runtime.Runtime.XIncref(p);
Assert.AreEqual(2, Runtime.Runtime.Refcount32(p));
Assert.That(Runtime.Runtime.Refcount32(p), Is.EqualTo(2));
Runtime.Runtime.XDecref(op.Steal());
Assert.AreEqual(1, Runtime.Runtime.Refcount32(p));
Assert.That(Runtime.Runtime.Refcount32(p), Is.EqualTo(1));
#pragma warning restore CS0618 // Type or member is obsolete

op.Dispose();
Expand Down
Loading
Loading