Skip to content

Commit 3ed68d8

Browse files
committed
Update NUnit
1 parent dc69411 commit 3ed68d8

24 files changed

Lines changed: 185 additions & 185 deletions

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<AssemblyCopyright>Copyright (c) 2006-2025 The Contributors of the Python.NET Project</AssemblyCopyright>
55
<AssemblyCompany>pythonnet</AssemblyCompany>
66
<AssemblyProduct>Python.NET</AssemblyProduct>
7-
<LangVersion>12.0</LangVersion>
7+
<LangVersion>14</LangVersion>
88
<IsPackable>false</IsPackable>
99
<DeterministicSourcePaths>true</DeterministicSourcePaths>
1010
<FullVersion>$([System.IO.File]::ReadAllText("$(MSBuildThisFileDirectory)version.txt").Trim())</FullVersion>

src/embed_tests/Codecs.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static void TupleConversionsGeneric<T, TTuple>()
3232
scope.Set(nameof(tuple), tuple);
3333
scope.Set(nameof(accept), accept);
3434
scope.Exec($"{nameof(accept)}({nameof(tuple)})");
35-
Assert.AreEqual(expected: tuple, actual: restored);
35+
Assert.That(actual: restored, Is.EqualTo(expected: tuple));
3636
}
3737
}
3838

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

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

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

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

124124
//can't convert python iterable to list (this will require a copy which isn't lossless)
@@ -162,8 +162,8 @@ public void SequenceDecoderTest()
162162
//the IList will report a Count of 3.
163163
ICollection<string> stringCollection = null;
164164
Assert.DoesNotThrow(() => { codec.TryDecode(pyList, out stringCollection); });
165-
Assert.AreEqual(3, stringCollection.Count());
166-
Assert.Throws(typeof(InvalidCastException), () => {
165+
Assert.That(stringCollection.Count(), Is.EqualTo(3));
166+
Assert.Throws<InvalidCastException>(() => {
167167
string[] array = new string[3];
168168
stringCollection.CopyTo(array, 0);
169169
});
@@ -199,8 +199,8 @@ public void SequenceDecoderTest()
199199
//the IList will report a Count of 3.
200200
ICollection<string> stringCollection2 = null;
201201
Assert.DoesNotThrow(() => { codec.TryDecode(pyTuple, out stringCollection2); });
202-
Assert.AreEqual(3, stringCollection2.Count());
203-
Assert.Throws(typeof(InvalidCastException), () => {
202+
Assert.That(stringCollection2.Count, Is.EqualTo(3));
203+
Assert.Throws<InvalidCastException>(() => {
204204
string[] array = new string[3];
205205
stringCollection2.CopyTo(array, 0);
206206
});
@@ -321,7 +321,7 @@ def call(func):
321321
");
322322
var callFunc = scope.Get("call");
323323
string message = callFunc.Invoke(callMeAction.ToPython()).As<string>();
324-
Assert.AreEqual(TestExceptionMessage, message);
324+
Assert.That(message, Is.EqualTo(TestExceptionMessage));
325325
}
326326

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

337337
[Test]
@@ -360,7 +360,7 @@ public void FloatDerivedDecoded()
360360
PyObjectConversions.RegisterDecoder(decoder);
361361
using var result = scope.Eval("FloatDerived()");
362362
object decoded = result.As<object>();
363-
Assert.AreEqual(42, decoded);
363+
Assert.That(decoded, Is.EqualTo(42));
364364
}
365365

366366
[Test]
@@ -374,7 +374,7 @@ public void ExceptionDecodedNoInstance()
374374
var error = Assert.Throws<ValueErrorWrapper>(() =>
375375
PythonEngine.Exec($"[].__iter__().__next__()")
376376
);
377-
Assert.AreEqual(TestExceptionMessage, error.Message);
377+
Assert.That(error.Message, Is.EqualTo(TestExceptionMessage));
378378
}
379379
else
380380
{
@@ -395,7 +395,7 @@ public void As_Object_AffectedByDecoders()
395395

396396
var pyObj = PythonEngine.Eval("iter");
397397
var decoded = pyObj.As<object>();
398-
Assert.AreSame(everythingElseToSelf, decoded);
398+
Assert.That(decoded, Is.SameAs(everythingElseToSelf));
399399
}
400400

401401
public class EverythingElseToSelfDecoder : IPyObjectDecoder

src/embed_tests/Dynamic.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ public void AssignObject()
1919
sys.testattr = stream;
2020
// Check whether there are the same object.
2121
dynamic _stream = sys.testattr.AsManagedObject(typeof(StringBuilder));
22-
Assert.AreEqual(_stream, stream);
22+
Assert.That(_stream, Is.EqualTo(stream));
2323

2424
PythonEngine.RunSimpleString(
2525
"import sys\n" +
2626
"sys.testattr.Append('Hello!')\n");
27-
Assert.AreEqual(stream.ToString(), "Hello!");
27+
Assert.That(stream.ToString(), Is.EqualTo("Hello!"));
2828
}
2929

3030
/// <summary>
@@ -63,7 +63,7 @@ public void AssignPyObject()
6363
sys.testattr = io.StringIO();
6464
dynamic bb = sys.testattr; // Get the PyObject
6565
bb.write("Hello!");
66-
Assert.AreEqual(bb.getvalue().ToString(), "Hello!");
66+
Assert.That(bb.getvalue().ToString(), Is.EqualTo("Hello!"));
6767
}
6868

6969
/// <summary>
@@ -87,7 +87,7 @@ public void PassObjectInPython()
8787
"import sys\n" +
8888
"sys.testattr3 = sys.testattr1 is sys.testattr2\n"
8989
);
90-
Assert.AreEqual(sys.testattr3.ToString(), "True");
90+
Assert.That(sys.testattr3.ToString(), Is.EqualTo("True"));
9191

9292
// Compare in .NET
9393
Assert.IsTrue(sys.testattr1.Equals(sys.testattr2));
@@ -110,7 +110,7 @@ public void PassPyObjectInNet()
110110
"sys.testattr3 = sys.testattr1 is sys.testattr2\n"
111111
);
112112

113-
Assert.AreEqual(sys.testattr3.ToString(), "True");
113+
Assert.That(sys.testattr3.ToString(), Is.EqualTo("True"));
114114

115115
// Compare in .NET
116116
Assert.IsTrue(sys.testattr1.Equals(sys.testattr2));

src/embed_tests/Events.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ del example
3131
gc.collect()
3232
");
3333
Runtime.Runtime.TryCollectingGarbage(10);
34-
Assert.AreEqual(0, ClassWithEventHandler.alive);
34+
Assert.That(ClassWithEventHandler.alive, Is.EqualTo(0));
3535
}
3636
}
3737

src/embed_tests/Modules.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ public void TestScopeClass()
149149
);
150150
dynamic obj1 = _ps.Class1(20);
151151
var result = obj1.call(10).As<int>();
152-
Assert.AreEqual(130, result);
152+
Assert.That(result, Is.EqualTo(130));
153153

154154
obj1.update(10);
155155
result = ps.Get<int>("bb");
156-
Assert.AreEqual(30, result);
156+
Assert.That(result, Is.EqualTo(30));
157157
}
158158
}
159159

@@ -185,11 +185,11 @@ public void TestCreateVirtualPackageStructure()
185185

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

190190
obj1.update(10);
191191
result = ps2.Get<int>("bb");
192-
Assert.AreEqual(30, result);
192+
Assert.That(result, Is.EqualTo(30));
193193
}
194194
}
195195

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

234234
//import as
235235
ps.Import("sys", "sys1");
@@ -308,16 +308,16 @@ public void TestImportScopeFunction()
308308
dynamic func2 = scope.Get("func2");
309309

310310
var result1 = func2().As<int>();
311-
Assert.AreEqual(0, result1);
311+
Assert.That(result1, Is.EqualTo(0));
312312

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

318318
ps.Set("cc", 20);
319319
var result3 = func2().As<int>();
320-
Assert.AreEqual(10, result3);
320+
Assert.That(result3, Is.EqualTo(10));
321321
ps.Set("cc", 10); //rollback
322322
}
323323
}
@@ -437,7 +437,7 @@ public void TestCreate()
437437
scope.Execute(code);
438438

439439
Assert.That(scope.TryGet("x", out dynamic x), Is.True);
440-
Assert.AreEqual("True", x.ToString());
440+
Assert.That(x.ToString(), Is.EqualTo("True"));
441441
}
442442

443443
[Test]

src/embed_tests/NeedsReinit/TestDomainReload.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ public override ValueType Execute(ValueType arg)
146146
");
147147
}
148148
var clrObj = obj.As<Domain.MyClass>();
149-
Assert.AreEqual(clrObj.Property, 2);
150-
Assert.AreEqual(clrObj.Field, 20);
149+
Assert.That(2, Is.EqualTo(clrObj.Property));
150+
Assert.That(20, Is.EqualTo(clrObj.Field));
151151
}
152152
}
153153
}

src/embed_tests/NeedsReinit/TestPyInitialize.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static void LoadDefaultArgs()
2828
{
2929
using(var argv = new PyList(Runtime.Runtime.PySys_GetObject("argv")))
3030
{
31-
Assert.AreNotEqual(0, argv.Length());
31+
Assert.That(argv.Length(), Is.Not.EqualTo(0));
3232
}
3333
}
3434
}

src/embed_tests/NeedsReinit/TestPythonEngineProperties.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void SetPythonHome()
2222
PythonEngine.PythonHome = pythonHome;
2323
PythonEngine.Initialize();
2424

25-
Assert.AreEqual(pythonHome, PythonEngine.PythonHome);
25+
Assert.That(PythonEngine.PythonHome, Is.EqualTo(pythonHome));
2626
PythonEngine.Shutdown();
2727

2828
// Restoring valid pythonhome.
@@ -45,7 +45,7 @@ public void SetPythonHomeTwice()
4545
PythonEngine.PythonHome = pythonHome;
4646
PythonEngine.Initialize();
4747

48-
Assert.AreEqual(pythonHome, PythonEngine.PythonHome);
48+
Assert.That(PythonEngine.PythonHome, Is.EqualTo(pythonHome));
4949
PythonEngine.Shutdown();
5050

5151
PythonEngine.PythonHome = pythonHomeBackup;
@@ -65,7 +65,7 @@ public void SetPythonHomeEmptyString()
6565
}
6666
PythonEngine.PythonHome = "";
6767

68-
Assert.AreEqual("", PythonEngine.PythonHome);
68+
Assert.That(PythonEngine.PythonHome, Is.EqualTo(""));
6969

7070
PythonEngine.PythonHome = backup;
7171
PythonEngine.Shutdown();
@@ -86,7 +86,7 @@ public void SetProgramName()
8686
PythonEngine.ProgramName = programName;
8787
PythonEngine.Initialize();
8888

89-
Assert.AreEqual(programName, PythonEngine.ProgramName);
89+
Assert.That(PythonEngine.ProgramName, Is.EqualTo(programName));
9090
PythonEngine.Shutdown();
9191

9292
PythonEngine.ProgramName = programNameBackup;
@@ -124,7 +124,7 @@ public void SetPythonPath()
124124
PythonEngine.PythonPath = path;
125125
PythonEngine.Initialize();
126126

127-
Assert.AreEqual(path, PythonEngine.PythonPath);
127+
Assert.That(PythonEngine.PythonPath, Is.EqualTo(path));
128128
if (importShouldSucceed) Py.Import(moduleName);
129129

130130
PythonEngine.Shutdown();

src/embed_tests/NeedsReinit/TestRuntime.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public static void Py_IsInitializedValue()
1616
Runtime.Runtime.PyGILState_Ensure();
1717
}
1818
Runtime.Runtime.Py_Finalize();
19-
Assert.AreEqual(0, Runtime.Runtime.Py_IsInitialized());
19+
Assert.That(Runtime.Runtime.Py_IsInitialized(), Is.EqualTo(0));
2020
Runtime.Runtime.Py_Initialize();
21-
Assert.AreEqual(1, Runtime.Runtime.Py_IsInitialized());
21+
Assert.That(Runtime.Runtime.Py_IsInitialized(), Is.EqualTo(1));
2222
Runtime.Runtime.Py_Finalize();
23-
Assert.AreEqual(0, Runtime.Runtime.Py_IsInitialized());
23+
Assert.That(Runtime.Runtime.Py_IsInitialized(), Is.EqualTo(0));
2424
}
2525

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

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

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

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

4242
// Py_IncRef/Py_DecRef increase and decrease RefCount
4343
Runtime.Runtime.Py_IncRef(op.Borrow());
44-
Assert.AreEqual(2, Runtime.Runtime.Refcount32(p));
44+
Assert.That(Runtime.Runtime.Refcount32(p), Is.EqualTo(2));
4545
Runtime.Runtime.Py_DecRef(StolenReference.DangerousFromPointer(op.DangerousGetAddress()));
46-
Assert.AreEqual(1, Runtime.Runtime.Refcount32(p));
46+
Assert.That(Runtime.Runtime.Refcount32(p), Is.EqualTo(1));
4747

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

5656
op.Dispose();

0 commit comments

Comments
 (0)