Skip to content

Commit 2ebbcbd

Browse files
committed
test: Add basic python tests for dicts/lists
1 parent d6eea7a commit 2ebbcbd

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

test/python_tests/python_tests.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,39 @@ TEST_F(PythonTest, callFunctionWithWrongArguments)
3838
EXPECT_FALSE(result_1.valueOr(true));
3939
EXPECT_FALSE(result_2.valueOr(true));
4040
}
41+
42+
TEST_F(PythonTest, callFunctionWithDict)
43+
{
44+
auto result = plugin->call<int>("accept_dict", std::map<std::string, int> {
45+
{ "", 1 },
46+
{ "a", 2 },
47+
{ "b", 3 },
48+
{ "c", 4 },
49+
},
50+
"c");
51+
52+
ASSERT_TRUE(result.hasValue()) << ppplugin::test::errorOutput(result);
53+
EXPECT_EQ(result.valueOr(0), 4);
54+
}
55+
56+
TEST_F(PythonTest, callFunctionWithList)
57+
{
58+
auto result = plugin->call<std::string>("accept_list", std::vector<char> { 'a', 'b', 'c' });
59+
60+
ASSERT_TRUE(result.hasValue()) << ppplugin::test::errorOutput(result);
61+
EXPECT_EQ(result.valueOr(""), "a,b,c,");
62+
}
63+
64+
TEST_F(PythonTest, nestedDict)
65+
{
66+
using ResultType = std::map<std::string, std::vector<std::map<int, int>>>;
67+
const ResultType expected = {
68+
{ "", {} },
69+
{ "a", { { { 1, 1 }, { 2, 2 } }, { { 0, 0 } } } },
70+
{ "b", { { { 1, 1 } } } }
71+
};
72+
73+
auto result = plugin->call<ResultType>("identity", expected);
74+
75+
EXPECT_EQ(result.valueOr(ResultType {}), expected);
76+
}

test/python_tests/test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,15 @@ def accept_int_string_bool_float(i, s, b, f):
77
return is_int and is_string and is_bool and is_float
88

99

10+
def accept_dict(d, key):
11+
return d[key]
12+
13+
def accept_list(l):
14+
result = ""
15+
for e in l:
16+
result += e + ","
17+
return result
18+
19+
1020
def identity(x):
1121
return x

0 commit comments

Comments
 (0)