def test_connection(): # see https://github.com/apache/tinkerpop/blob/master/gremlin-python/src/main/jython/gremlin_python/driver/driver_remote_connection.py remoteTraversal=remote.RemoteTraversal() g = remoteTraversal.g() t=g.V() remoteConnection=remoteTraversal.remoteConnection # see https://github.com/apache/tinkerpop/blob/master/gremlin-python/src/main/jython/gremlin_python/driver/client.py client=remoteConnection._client connection=client._get_connection() message = RequestMessage('traversal', 'bytecode', {'gremlin': t.bytecode, 'aliases': {'g': client._traversal_source}}) results_set = connection.write(message).result() future = results_set.all() results = future.result() print ("%d results" % (len(results))) #assert len(results) == 6 assert isinstance(results, list) assert results_set.done.done() #assert 'host' in results_set.status_attributes print (results_set.status_attributes)
def test_createGraphvizGraph(): # make sure we re-load the tinkerpop modern example remoteTraversal = remote.RemoteTraversal() remoteTraversal.load("tinkerpop-modern.xml") # start a graphviz dot = Digraph(comment='Modern') # get vertice properties including id and label as dicts for vDict in g.V().valueMap(True).toList(): # uncomment to debug # print vDict # get id and label vId = vDict[T.id] vLabel = vDict[T.label] # greate a graphviz node label # name property is alway there gvLabel = r"%s\n%s\nname=%s" % (vId, vLabel, vDict["name"][0]) # if there is an age property add it to the label if "age" in vDict: gvLabel = gvLabel + r"\nage=%s" % (vDict["age"][0]) # create a graphviz node dot.node("node%d" % (vId), gvLabel) # loop over all edges for e in g.E(): # get the detail information with a second call per edge (what a pitty to be so inefficient ...) eDict = g.E(e.id).valueMap(True).next() # uncomment if you'd like to debug # print (e,eDict) # create a graphviz label geLabel = r"%s\n%s\nweight=%s" % (e.id, e.label, eDict["weight"]) # add a graphviz edge dot.edge("node%d" % (e.outV.id), "node%d" % (e.inV.id), label=geLabel) # modify the styling see http://www.graphviz.org/doc/info/attrs.html dot.edge_attr.update(arrowsize='2', penwidth='2') dot.node_attr.update(style='filled', fillcolor="#A8D0E4") # print the source code print(dot.source) # render without viewing - default is creating a pdf file dot.render('/tmp/modern.gv', view=False) # check that the pdf file exists assert os.path.isfile('/tmp/modern.gv.pdf')
# see # http://wiki.bitplan.com/index.php/Gremlin_python#Getting_Started from tutorial import remote from gremlin_python.process.graph_traversal import GraphTraversal # initialize a remote traversal remoteTraversal = remote.RemoteTraversal() g = remoteTraversal.g() # in TinkerGraph this is the first id id1 = 1 # convert object to string and print out for debugging def asString(object): text = str(object) print(text) return text # get id of Marko's vertex which is usually 1 but might be different e.g. # when Neo4j is used def test_tutorial0(): global id1 l = g.V().toList() id1 = l[0].id # Marko's id might not be 1 # print (id1) # http://wiki.bitplan.com/index.php/Gremlin_python#g.V.28.29_-_the_vertices #gremlin> g.V() //(1)
def test_LoadModern(): remoteTraversal = remote.RemoteTraversal() remoteTraversal.load("tinkerpop-modern.xml")
# see https://github.com/WolfgangFahl/gremlin-python-tutorial/blob/master/test_001.py from tutorial import remote # initialize a remote traversal g = remote.RemoteTraversal().g() # test the number of vertices def test_LoadModern(): remoteTraversal = remote.RemoteTraversal() remoteTraversal.load("tinkerpop-modern.xml") # call the loadModern test test_LoadModern()