diff --git a/WDL/Value.py b/WDL/Value.py index fc2dcdf6..34b66210 100644 --- a/WDL/Value.py +++ b/WDL/Value.py @@ -296,7 +296,7 @@ def __str__(self) -> str: @property def json(self) -> Any: "" - return [self.value[0].json, self.value[1].json] + return {"left": self.value[0].json, "right": self.value[1].json} @property def children(self) -> Iterable[Base]: @@ -416,11 +416,11 @@ def from_json(type: Type.Base, value: Any) -> Base: return String(value) if isinstance(type, Type.Array) and isinstance(value, list): return Array(type, [from_json(type.item_type, item) for item in value]) - if isinstance(type, Type.Pair) and isinstance(value, list) and len(value) == 2: + if isinstance(type, Type.Pair) and isinstance(value, dict) and set(value) == {"left", "right"}: return Pair( type.left_type, type.right_type, - (from_json(type.left_type, value[0]), from_json(type.right_type, value[1])), + (from_json(type.left_type, value["left"]), from_json(type.right_type, value["right"])), ) if ( isinstance(type, Type.Map) diff --git a/tests/test_0eval.py b/tests/test_0eval.py index efdcd50b..621388ff 100644 --- a/tests/test_0eval.py +++ b/tests/test_0eval.py @@ -453,7 +453,7 @@ def test_json(self): (WDL.Type.Map((WDL.Type.String(), WDL.Type.Int())), {"cats": 42, "dogs": 99}), (pty, {"name": "Alyssa", "age": 42, "pets": None}), (pty, {"name": "Alyssa", "age": 42, "pets": {"cats": 42, "dogs": 99}}), - (WDL.Type.Array(WDL.Type.Pair(WDL.Type.String(), WDL.Type.Int())), [["a",0],["b",1]]), + (WDL.Type.Array(WDL.Type.Pair(WDL.Type.String(), WDL.Type.Int())), [{"left": "a", "right": 0},{"left": "b", "right": 1}]), (WDL.Type.Boolean(), 42, WDL.Error.InputError), (WDL.Type.Float(), "your president", WDL.Error.InputError), diff --git a/tests/test_5stdlib.py b/tests/test_5stdlib.py index e485017f..0251584c 100644 --- a/tests/test_5stdlib.py +++ b/tests/test_5stdlib.py @@ -280,7 +280,11 @@ def test_flatten(self): """) self.assertEqual(outputs["ai"], [1, 2, 3, 1, 21, 22]) self.assertEqual(outputs["af"], ["/tmp/X.txt", "/tmp/Y.txt", "/tmp/Z.txt"]) - self.assertEqual(outputs["ap"], [[0.1, "mouse"], [3, "cat"], [15, "dog"]]) + self.assertEqual(outputs["ap"], [ + {"left": 0.1, "right": "mouse"}, + {"left": 3, "right": "cat"}, + {"left": 15, "right": "dog"} + ]) def test_size(self): with open(os.path.join(self._dir, "alyssa.txt"), "w") as outfile: @@ -696,8 +700,19 @@ def test_zip_cross(self): } } """) - self.assertEqual(outputs["zipped"], [[1, "a"], [2, "b"], [3, "c"]]) - self.assertEqual(outputs["crossed"], [[1, "d"], [1, "e"], [2, "d"], [2, "e"], [3, "d"], [3, "e"]]) + self.assertEqual(outputs["zipped"], [ + {"left": 1, "right": "a"}, + {"left": 2, "right": "b"}, + {"left": 3, "right": "c"} + ]) + self.assertEqual(outputs["crossed"], [ + {"left": 1, "right": "d"}, + {"left": 1, "right": "e"}, + {"left": 2, "right": "d"}, + {"left": 2, "right": "e"}, + {"left": 3, "right": "d"}, + {"left": 3, "right": "e"} + ]) outputs = self._test_task(R""" version 1.0 diff --git a/tests/test_6workflowrun.py b/tests/test_6workflowrun.py index 24fc7643..d714e1db 100644 --- a/tests/test_6workflowrun.py +++ b/tests/test_6workflowrun.py @@ -176,7 +176,16 @@ def test_scatters(self): } } """, {"m": 4, "n": 2}) - self.assertEqual(outputs["pairs"], [[0, 0], [0, 1], [1, 0], [1, 1], [2, 0], [2, 1], [3, 0], [3, 1]]) + self.assertEqual(outputs["pairs"], [ + {"left": 0, "right": 0}, + {"left": 0, "right": 1}, + {"left": 1, "right": 0}, + {"left": 1, "right": 1}, + {"left": 2, "right": 0}, + {"left": 2, "right": 1}, + {"left": 3, "right": 0}, + {"left": 3, "right": 1} + ]) outputs = self._test_workflow(""" version 1.0 @@ -213,7 +222,16 @@ def test_scatters(self): } } """, {"m": 4, "n": 2}) - self.assertEqual(outputs["pairs"], [[0, 0], [0, 1], [1, 0], [1, 1], [2, 0], [2, 1], [3, 0], [3, 1]]) + self.assertEqual(outputs["pairs"], [ + {"left": 0, "right": 0}, + {"left": 0, "right": 1}, + {"left": 1, "right": 0}, + {"left": 1, "right": 1}, + {"left": 2, "right": 0}, + {"left": 2, "right": 1}, + {"left": 3, "right": 0}, + {"left": 3, "right": 1} + ]) def test_ifs(self): outputs = self._test_workflow("""