atharrva01 commented on code in PR #383:
URL: https://github.com/apache/hugegraph-ai/pull/383#discussion_r4302688706


##########
hugegraph-llm/src/tests/utils/mock.py:
##########
@@ -74,3 +79,34 @@ def __len__(self):
     def search(self, query_vector, top_k=5):
         # Simply return the first top_k documents.
         return self.documents[: min(top_k, len(self.documents))]
+
+
+class FakeGremlinEndpoint:
+    """Stand-in for HugeGraph's /gremlin endpoint that rejects scripts whose 
g.V(...) ids don't parse.
+
+    Groovy and Python share the same rules for single-quoted literals with \\' 
and \\\\ escapes,
+    so ast.literal_eval acts as the parser. Vertex lookups return matching 
entries from `vertices`;
+    traversals (anything with `.repeat(`) return the `paths` that start at one 
of the requested ids.
+    """
+
+    def __init__(self, vertices, paths=None):
+        self.vertices = vertices
+        self.paths = paths or []
+        self.scripts = []
+
+    def exec(self, gremlin):
+        self.scripts.append(gremlin)
+        match = re.match(r"g\.V\((.*?)\)\s*[.\n]", gremlin, re.S)

Review Comment:
   Good point, fixed. The fake now scans the g.V(...) call and skips over 
quoted text and escapes, so ids like 1:x).y work. Added a test with a few ids 
like that (parens, brackets, quotes) going through get_vertex_details.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to