Skip to content

Commit

Permalink
Merge pull request #452 from ChristopherBradley/449
Browse files Browse the repository at this point in the history
ENH: deserialise_result handles tuples as keys
  • Loading branch information
GavinHuttley committed Dec 12, 2019
2 parents 0ecffb0 + abb50a3 commit 679bf32
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/cogent3/util/deserialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ def deserialise_result(data):
# required
if type(value) == dict and "app.result" in str(value.get("type")):
value = deserialise_object(value)
result[key] = value
try:
result[key] = value
except TypeError:
result[tuple(key)] = value
return result


Expand Down
9 changes: 9 additions & 0 deletions tests/test_util/test_deserialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@ def test_roundtrip_model_result(self):
self.assertNotIsInstance(got_obj.lf, dict)
self.assertEqual(got_obj.lf.nfp, got_obj.nfp)

def test_roundtrip_tuple_key(self):
"""deserialise_result handles tuples as keys"""
from cogent3.app.result import generic_result

r = generic_result(source="none")
r[(1, 2)] = 24
got = deserialise_object(r.to_json())
self.assertEqual(got[(1, 2)], 24)

def test_not_completed_result(self):
"""correctly reconstructs a NotCompletedResult object"""
from cogent3.app.composable import NotCompleted
Expand Down

0 comments on commit 679bf32

Please sign in to comment.