Repository: tinkerpop Updated Branches: refs/heads/TINKERPOP-1427 ef5b23fd3 -> 43f49dfc5
added GraphSONReader tests for set/list/map to test_graphsonV3d0.py. Already tested in the Jython infrastruture, but why not have it also localized in the pure Python tests. Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/43f49dfc Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/43f49dfc Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/43f49dfc Branch: refs/heads/TINKERPOP-1427 Commit: 43f49dfc5b9a3837d047fd5bc9f14c4172bb1f8a Parents: ef5b23f Author: Marko A. Rodriguez <okramma...@gmail.com> Authored: Fri Jul 7 14:52:30 2017 -0600 Committer: Marko A. Rodriguez <okramma...@gmail.com> Committed: Fri Jul 7 14:52:30 2017 -0600 ---------------------------------------------------------------------- .../tests/structure/io/test_graphsonV3d0.py | 31 ++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/43f49dfc/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV3d0.py ---------------------------------------------------------------------- diff --git a/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV3d0.py b/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV3d0.py index 19897dc..78798b3 100644 --- a/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV3d0.py +++ b/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV3d0.py @@ -33,9 +33,35 @@ from gremlin_python.process.traversal import P from gremlin_python.process.strategies import SubgraphStrategy from gremlin_python.process.graph_traversal import __ + class TestGraphSONReader(object): graphson_reader = GraphSONReader() + def test_collections(self): + x = self.graphson_reader.readObject( + json.dumps({"@type": "g:List", "@value": [{"@type": "g:Int32", "@value": 1}, + {"@type": "g:Int32", "@value": 2}, + "3"]})) + assert isinstance(x, list) + assert x[0] == 1 + assert x[1] == 2 + assert x[2] == "3" + ## + x = self.graphson_reader.readObject( + json.dumps({"@type": "g:Set", "@value": [{"@type": "g:Int32", "@value": 1}, + {"@type": "g:Int32", "@value": 2}, + "3"]})) + assert isinstance(x, set) + assert x == set([1, 2, "3"]) + ## + x = self.graphson_reader.readObject( + json.dumps({"@type": "g:Map", + "@value": ['a', {"@type": "g:Int32", "@value": 1}, 'b', "marko"]})) + assert isinstance(x, dict) + assert x['a'] == 1 + assert x['b'] == "marko" + assert len(x) == 2 + def test_number_input(self): x = self.graphson_reader.readObject(json.dumps({ "@type": "g:Int32", @@ -212,8 +238,9 @@ class TestGraphSONWriter(object): assert result == json.loads( self.graphson_writer.writeObject(P.lt("b").or_(P.gt("c")).and_(P.neq("d")))) - result = {'@type': 'g:P', '@value': {'predicate':'within','value': {'@type': 'g:List', '@value':[{"@type": "g:Int32", "@value": 1},{"@type": "g:Int32", "@value": 2}]}}} - assert result == json.loads(self.graphson_writer.writeObject(P.within([1,2]))) + result = {'@type': 'g:P', '@value': {'predicate': 'within', 'value': {'@type': 'g:List', '@value': [ + {"@type": "g:Int32", "@value": 1}, {"@type": "g:Int32", "@value": 2}]}}} + assert result == json.loads(self.graphson_writer.writeObject(P.within([1, 2]))) def test_strategies(self): # we have a proxy model for now given that we don't want to have to have g:XXX all registered on the Gremlin traversal machine (yet)