Skip to content

Commit

Permalink
Improve unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonabreul committed Nov 1, 2024
1 parent 93fb973 commit 0acc2db
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/embed_tests/TestMethodBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,12 @@ def call_method(instance):

public class CSharpClass2
{
public string CalledMethodMessage { get; private set; }
public string CalledMethodMessage { get; private set; } = string.Empty;

public void Clear()
{
CalledMethodMessage = string.Empty;
}

public void Method()
{
Expand Down Expand Up @@ -967,13 +972,21 @@ public void PyObjectArgsHavePrecedenceOverOtherTypes()
pyInstance.InvokeMethod("Method", pyArg);
});

Assert.AreEqual("Overload 4", instance.CalledMethodMessage);
Assert.IsFalse(Exceptions.ErrorOccurred());
instance.Clear();

// With the first named argument
Assert.DoesNotThrow(() =>
{
using var kwargs = Py.kw("decimalArgument", 1.234m);
pyInstance.InvokeMethod("Method", new[] { pyArg }, kwargs);
});

Assert.AreEqual("Overload 4", instance.CalledMethodMessage);
Assert.IsFalse(Exceptions.ErrorOccurred());
instance.Clear();

// Snake case version
Assert.DoesNotThrow(() =>
{
Expand All @@ -982,7 +995,6 @@ public void PyObjectArgsHavePrecedenceOverOtherTypes()
});

Assert.AreEqual("Overload 4", instance.CalledMethodMessage);

Assert.IsFalse(Exceptions.ErrorOccurred());
}

Expand Down

0 comments on commit 0acc2db

Please sign in to comment.