Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions polypheny/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,15 @@ def _py2proto(value, v):
elif value is None:
v.null.CopyFrom(value_pb2.ProtoNull())
elif type(value) is list:
v.list.SetInParent()
for element in value:
v.list.values.append(py2proto(element))
elif type(value) is dict:
v.document.SetInParent()
for key, element in value.items():
if not isinstance(key, str):
raise NotSupportedError("Document keys must be strings")
py2proto(element, v.document.entries[key])
else:
raise NotSupportedError()

Expand Down
12 changes: 8 additions & 4 deletions tests/test_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,15 @@ def test_serialize_varbinary(cur):
assert cur.fetchone()[0] == b'Hello World'
assert cur.fetchone() is None

def test_serialize_not_implemented(cur):
cur.execute('DROP TABLE IF EXISTS t')
cur.execute('CREATE TABLE t(i INTEGER NOT NULL, a INTEGER, PRIMARY KEY(i))')
@pytest.mark.parametrize('value', [[], {}, {'a': [None, {}, []], 'b': {'active': True}}])
def test_serialize_containers_local(value):
assert polypheny.serialize.proto2py(polypheny.serialize.py2proto(value)) == value


@pytest.mark.parametrize('value', [object(), {1: 'not a string key'}])
def test_serialize_not_implemented(value):
with pytest.raises(polypheny.NotSupportedError):
cur.execute('INSERT INTO t(i, a) VALUES (0, ?)', ({'a': 'b'},))
polypheny.serialize.py2proto(value)

def test_trailing_semicolon(cur):
cur.execute("SELECT 1;")
Expand Down
Loading