# HG changeset patch # User Mike Miller # Date 1471295955 25200 # Node ID 252b458bd9045b6f5772a13c51545676bb465aed # Parent 96b78e78a235a86f1a3898267d9f50d35471d0d3 Add %!tests of dict creation and equality * pycall.cc: Add %!tests of dict creation and equality. diff -r 96b78e78a235 -r 252b458bd904 pycall.cc --- a/pycall.cc Mon Aug 15 13:20:15 2016 -0700 +++ b/pycall.cc Mon Aug 15 14:19:15 2016 -0700 @@ -193,6 +193,24 @@ %!error (pycall ("list", {1, 2, 3; 4, 5, 6})) %!error (pycall ("dict", {1, 2, 3})) +## Test construction of dict from pyargs +%!test +%! a = pycall ("dict", pyargs ("a", 1, "b", 2, "c", 3)); +%! assert (sort (cell (pycall ("list", a.keys ()))), {"a", "b", "c"}) +%! assert (sort (double (pycall ("array.array", "d", a.values ()))), [1, 2, 3]) + +## Test copy construction of dict from dict +%!test +%! a = pycall ("dict", pyargs ("a", 1, "b", 2, "c", 3)); +%! b = pycall ("dict", a); +%! assert (isequal (a, b)) + +## Test construction of dict from sequence of key value pairs +%!test +%! a = pycall ("dict", pyargs ("a", 1, "b", 2, "c", 3)); +%! b = pycall ("dict", pycall ("zip", {"a", "b", "c"}, {1, 2, 3})); +%! assert (isequal (a, b)) + ## Test round trip type preservation / conversion %!test %! pyexec ("def roundtrip(x): return x");