Skip to content

Commit

Permalink
Merge pull request #4 from tonybaloney/integration_testing
Browse files Browse the repository at this point in the history
Integration testing dictionaries
  • Loading branch information
tonybaloney authored Jul 18, 2024
2 parents 321a5ec + ed488ba commit 9df2dbb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Integration.Tests/BasicTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Python.Generated;
using Python.Runtime;
using System.Collections.Immutable;
using System.Reflection;

namespace Integration.Tests;
Expand Down Expand Up @@ -48,4 +49,25 @@ public void TestDefaults()
Assert.Equal(1337, testDefaults.TestDefaultIntArg());
Assert.Equal(-1, testDefaults.TestDefaultFloatArg());
}

[Fact]
public void TestDicts()
{
var testDicts = testEnv.Env.TestDicts();

IReadOnlyDictionary<string, long> testDict = new Dictionary<string, long> { { "hello", 1 }, { "world", 2 } };
var result = testDicts.TestDictStrInt(testDict);
Assert.Equal(1, result["hello"]);
Assert.Equal(2, result["world"]);


IReadOnlyDictionary<string, IEnumerable<long>> testListDict = new Dictionary<string, IEnumerable<long>> { { "hello", new List<long> { 1, 2, 3 } }, { "world", new List<long> { 4, 5, 6 } } };
var result2 = testDicts.TestDictStrListInt(testListDict);
Assert.Equal([1, 2, 3], result2["hello"]);
Assert.Equal([4, 5, 6], result2["world"]);

IReadOnlyDictionary<string, IReadOnlyDictionary<string, long>> testDictDict = new Dictionary<string, IReadOnlyDictionary<string, long>> { { "hello", new Dictionary<string, long> { { "world", 1 } } } };
var result3 = testDicts.TestDictStrDictInt(testDictDict);
Assert.Equal(1, result3["hello"]["world"]);
}
}
4 changes: 4 additions & 0 deletions Integration.Tests/Integration.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<ItemGroup>
<None Remove="python\test_basic.py" />
<None Remove="python\test_defaults.py" />
<None Remove="python\test_dicts.py" />
<None Remove="python\test_false_returns.py" />
</ItemGroup>

Expand All @@ -22,6 +23,9 @@
<AdditionalFiles Include="python\test_defaults.py">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</AdditionalFiles>
<AdditionalFiles Include="python\test_dicts.py">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</AdditionalFiles>
<AdditionalFiles Include="python\test_false_returns.py">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</AdditionalFiles>
Expand Down
8 changes: 8 additions & 0 deletions Integration.Tests/python/test_dicts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def test_dict_str_int(a: dict[str, int]) -> dict[str, int]:
return a

def test_dict_str_list_int(a: dict[str, list[int]]) -> dict[str, list[int]]:
return a

def test_dict_str_dict_int(a: dict[str, dict[str, int]]) -> dict[str, dict[str, int]]:
return a

0 comments on commit 9df2dbb

Please sign in to comment.