From f16b6b5542c532d5de6bb15bab598b166e3dfa68 Mon Sep 17 00:00:00 2001 From: Anthony Shaw Date: Thu, 18 Jul 2024 15:08:34 +1000 Subject: [PATCH 1/2] Add a basic dictionary test --- Integration.Tests/BasicTest.cs | 12 ++++++++++++ Integration.Tests/Integration.Tests.csproj | 4 ++++ Integration.Tests/python/test_dicts.py | 3 +++ 3 files changed, 19 insertions(+) create mode 100644 Integration.Tests/python/test_dicts.py diff --git a/Integration.Tests/BasicTest.cs b/Integration.Tests/BasicTest.cs index 49e84699..876ed08d 100644 --- a/Integration.Tests/BasicTest.cs +++ b/Integration.Tests/BasicTest.cs @@ -1,5 +1,6 @@ using Python.Generated; using Python.Runtime; +using System.Collections.Immutable; using System.Reflection; namespace Integration.Tests; @@ -48,4 +49,15 @@ public void TestDefaults() Assert.Equal(1337, testDefaults.TestDefaultIntArg()); Assert.Equal(-1, testDefaults.TestDefaultFloatArg()); } + + [Fact] + public void TestDicts() + { + var testDicts = testEnv.Env.TestDicts(); + + IReadOnlyDictionary testDict = new Dictionary { { "hello", 1 }, { "world", 2 } }; + var result = testDicts.TestDictStrInt(testDict); + Assert.Equal(1, result["hello"]); + Assert.Equal(2, result["world"]); + } } \ No newline at end of file diff --git a/Integration.Tests/Integration.Tests.csproj b/Integration.Tests/Integration.Tests.csproj index 686a0310..09b46317 100644 --- a/Integration.Tests/Integration.Tests.csproj +++ b/Integration.Tests/Integration.Tests.csproj @@ -12,6 +12,7 @@ + @@ -22,6 +23,9 @@ Always + + Always + Always diff --git a/Integration.Tests/python/test_dicts.py b/Integration.Tests/python/test_dicts.py new file mode 100644 index 00000000..78491f7b --- /dev/null +++ b/Integration.Tests/python/test_dicts.py @@ -0,0 +1,3 @@ +def test_dict_str_int(a: dict[str, int]) -> dict[str, int]: + return a + From ed488baa5970835442b883e05c2c3bb1cad2d917 Mon Sep 17 00:00:00 2001 From: Anthony Shaw Date: Thu, 18 Jul 2024 15:16:11 +1000 Subject: [PATCH 2/2] Test weird nested dicts. --- Integration.Tests/BasicTest.cs | 10 ++++++++++ Integration.Tests/python/test_dicts.py | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/Integration.Tests/BasicTest.cs b/Integration.Tests/BasicTest.cs index 876ed08d..e7526292 100644 --- a/Integration.Tests/BasicTest.cs +++ b/Integration.Tests/BasicTest.cs @@ -59,5 +59,15 @@ public void TestDicts() var result = testDicts.TestDictStrInt(testDict); Assert.Equal(1, result["hello"]); Assert.Equal(2, result["world"]); + + + IReadOnlyDictionary> testListDict = new Dictionary> { { "hello", new List { 1, 2, 3 } }, { "world", new List { 4, 5, 6 } } }; + var result2 = testDicts.TestDictStrListInt(testListDict); + Assert.Equal([1, 2, 3], result2["hello"]); + Assert.Equal([4, 5, 6], result2["world"]); + + IReadOnlyDictionary> testDictDict = new Dictionary> { { "hello", new Dictionary { { "world", 1 } } } }; + var result3 = testDicts.TestDictStrDictInt(testDictDict); + Assert.Equal(1, result3["hello"]["world"]); } } \ No newline at end of file diff --git a/Integration.Tests/python/test_dicts.py b/Integration.Tests/python/test_dicts.py index 78491f7b..d6429241 100644 --- a/Integration.Tests/python/test_dicts.py +++ b/Integration.Tests/python/test_dicts.py @@ -1,3 +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