Skip to content

Commit

Permalink
Fixed codec test cases now that int is not PyInt
Browse files Browse the repository at this point in the history
  • Loading branch information
eirannejad committed Dec 21, 2023
1 parent 4a14028 commit 4b1f59f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/embed_tests/Codecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void IterableDecoderTest()
//ensure a PyList can be converted to a plain IEnumerable
System.Collections.IEnumerable plainEnumerable1 = null;
Assert.DoesNotThrow(() => { codec.TryDecode(pyList, out plainEnumerable1); });
CollectionAssert.AreEqual(plainEnumerable1.Cast<PyInt>().Select(i => i.ToInt32()), new List<object> { 1, 2, 3 });
CollectionAssert.AreEqual(plainEnumerable1.Cast<int>(), new List<int> { 1, 2, 3 });

//can convert to any generic ienumerable. If the type is not assignable from the python element
//it will lead to an empty iterable when decoding. TODO - should it throw?
Expand Down Expand Up @@ -272,7 +272,7 @@ public void IterableDecoderTest()
var fooType = foo.GetPythonType();
System.Collections.IEnumerable plainEnumerable2 = null;
Assert.DoesNotThrow(() => { codec.TryDecode(pyList, out plainEnumerable2); });
CollectionAssert.AreEqual(plainEnumerable2.Cast<PyInt>().Select(i => i.ToInt32()), new List<object> { 1, 2, 3 });
CollectionAssert.AreEqual(plainEnumerable2.Cast<int>(), new List<int> { 1, 2, 3 });

//can convert to any generic ienumerable. If the type is not assignable from the python element
//it will be an exception during TryDecode
Expand Down
9 changes: 5 additions & 4 deletions src/embed_tests/TestConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,12 @@ public void BigIntExplicit()
}

[Test]
public void PyIntImplicit()
public void PyIntExplicit()
{
var i = new PyInt(1);
var ni = (PyObject)i.As<object>();
Assert.IsTrue(PythonReferenceComparer.Instance.Equals(i, ni));
int val = 42;
var i = new PyInt(val);
var ni = i.As<int>();
Assert.AreEqual(val, ni);
}

[Test]
Expand Down

0 comments on commit 4b1f59f

Please sign in to comment.