This is an automated email from the ASF dual-hosted git repository.

imbajin pushed a commit to branch goal-test
in repository https://gitbox.apache.org/repos/asf/hugegraph-ai.git

commit 3840a4b92e903c49ece4d554245225a248b1cc9e
Author: imbajin <[email protected]>
AuthorDate: Sun May 31 12:36:14 2026 +0800

    refactor(llm): share HugeGraph test fixture
    
    - add a shared hugegraph_client fixture for LLM tests
    - remove duplicate client setup from KG smoke tests
    - remove duplicate client setup from boundary tests
    - verify smoke and HugeGraph integration paths
---
 hugegraph-llm/src/tests/conftest.py                | 40 ++++++++++++++-
 .../src/tests/integration/test_core_kg_smoke.py    | 45 +---------------
 .../tests/integration/test_hugegraph_boundary.py   | 60 ++++------------------
 3 files changed, 50 insertions(+), 95 deletions(-)

diff --git a/hugegraph-llm/src/tests/conftest.py 
b/hugegraph-llm/src/tests/conftest.py
index ac4bb867..a8764547 100644
--- a/hugegraph-llm/src/tests/conftest.py
+++ b/hugegraph-llm/src/tests/conftest.py
@@ -20,6 +20,7 @@ import os
 import sys
 
 import nltk
+import pytest
 
 # Get project root directory
 project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), 
"../.."))
@@ -32,7 +33,44 @@ sys.path.insert(0, tests_path)
 
 from fixtures.hugegraph_service import hugegraph_service  # noqa: E402
 
-__all__ = ["hugegraph_service"]
+__all__ = ["hugegraph_client", "hugegraph_service"]
+
+
[email protected]()
+def hugegraph_client(hugegraph_service):
+    from pyhugegraph.client import PyHugeClient
+
+    from hugegraph_llm.config import huge_settings
+
+    original = {
+        "graph_url": huge_settings.graph_url,
+        "graph_name": huge_settings.graph_name,
+        "graph_user": huge_settings.graph_user,
+        "graph_pwd": huge_settings.graph_pwd,
+        "graph_space": huge_settings.graph_space,
+    }
+    huge_settings.graph_url = hugegraph_service.url
+    huge_settings.graph_name = hugegraph_service.graph
+    huge_settings.graph_user = hugegraph_service.user
+    huge_settings.graph_pwd = hugegraph_service.password
+    huge_settings.graph_space = hugegraph_service.graphspace
+
+    client = PyHugeClient(
+        url=hugegraph_service.url,
+        graph=hugegraph_service.graph,
+        user=hugegraph_service.user,
+        pwd=hugegraph_service.password,
+        graphspace=hugegraph_service.graphspace,
+    )
+    client.graphs().clear_graph_all_data()
+    try:
+        yield client
+    finally:
+        try:
+            client.graphs().clear_graph_all_data()
+        finally:
+            for key, value in original.items():
+                setattr(huge_settings, key, value)
 
 
 # Download NLTK resources
diff --git a/hugegraph-llm/src/tests/integration/test_core_kg_smoke.py 
b/hugegraph-llm/src/tests/integration/test_core_kg_smoke.py
index 7d9721de..ed505921 100644
--- a/hugegraph-llm/src/tests/integration/test_core_kg_smoke.py
+++ b/hugegraph-llm/src/tests/integration/test_core_kg_smoke.py
@@ -19,7 +19,6 @@ import json
 from pathlib import Path
 
 import pytest
-from pyhugegraph.client import PyHugeClient
 
 pytestmark = [pytest.mark.smoke, pytest.mark.integration, 
pytest.mark.hugegraph]
 
@@ -55,46 +54,7 @@ QUALITY_COMMIT_SCHEMA = {
 }
 
 
-def _make_client(service):
-    return PyHugeClient(
-        url=service.url,
-        graph=service.graph,
-        user=service.user,
-        pwd=service.password,
-        graphspace=service.graphspace,
-    )
-
-
[email protected]()
-def configured_hugegraph(hugegraph_service):
-    from hugegraph_llm.config import huge_settings
-
-    original = {
-        "graph_url": huge_settings.graph_url,
-        "graph_name": huge_settings.graph_name,
-        "graph_user": huge_settings.graph_user,
-        "graph_pwd": huge_settings.graph_pwd,
-        "graph_space": huge_settings.graph_space,
-    }
-    huge_settings.graph_url = hugegraph_service.url
-    huge_settings.graph_name = hugegraph_service.graph
-    huge_settings.graph_user = hugegraph_service.user
-    huge_settings.graph_pwd = hugegraph_service.password
-    huge_settings.graph_space = hugegraph_service.graphspace
-
-    client = _make_client(hugegraph_service)
-    client.graphs().clear_graph_all_data()
-    try:
-        yield hugegraph_service
-    finally:
-        try:
-            client.graphs().clear_graph_all_data()
-        finally:
-            for key, value in original.items():
-                setattr(huge_settings, key, value)
-
-
-def test_kg_construction_smoke_uses_production_code(configured_hugegraph):
+def test_kg_construction_smoke_uses_production_code(hugegraph_client):
     from hugegraph_llm.operators.hugegraph_op.commit_to_hugegraph import 
Commit2Graph
     from hugegraph_llm.operators.hugegraph_op.fetch_graph_data import 
FetchGraphData
 
@@ -110,7 +70,6 @@ def 
test_kg_construction_smoke_uses_production_code(configured_hugegraph):
     }
     Commit2Graph().run(data)
 
-    client = _make_client(configured_hugegraph)
-    summary = FetchGraphData(client).run({})
+    summary = FetchGraphData(hugegraph_client).run({})
     assert summary["vertex_num"] >= len(fixture["vertices"])
     assert summary["edge_num"] >= len(fixture["edges"])
diff --git a/hugegraph-llm/src/tests/integration/test_hugegraph_boundary.py 
b/hugegraph-llm/src/tests/integration/test_hugegraph_boundary.py
index 4592d7b8..e86dba15 100644
--- a/hugegraph-llm/src/tests/integration/test_hugegraph_boundary.py
+++ b/hugegraph-llm/src/tests/integration/test_hugegraph_boundary.py
@@ -18,7 +18,6 @@
 from copy import deepcopy
 
 import pytest
-from pyhugegraph.client import PyHugeClient
 
 pytestmark = [pytest.mark.integration, pytest.mark.hugegraph]
 
@@ -100,45 +99,6 @@ QUALITY_COMMIT_DATA = {
 }
 
 
-def _make_client(service):
-    return PyHugeClient(
-        url=service.url,
-        graph=service.graph,
-        user=service.user,
-        pwd=service.password,
-        graphspace=service.graphspace,
-    )
-
-
[email protected]()
-def configured_hugegraph(hugegraph_service):
-    from hugegraph_llm.config import huge_settings
-
-    original = {
-        "graph_url": huge_settings.graph_url,
-        "graph_name": huge_settings.graph_name,
-        "graph_user": huge_settings.graph_user,
-        "graph_pwd": huge_settings.graph_pwd,
-        "graph_space": huge_settings.graph_space,
-    }
-    huge_settings.graph_url = hugegraph_service.url
-    huge_settings.graph_name = hugegraph_service.graph
-    huge_settings.graph_user = hugegraph_service.user
-    huge_settings.graph_pwd = hugegraph_service.password
-    huge_settings.graph_space = hugegraph_service.graphspace
-
-    client = _make_client(hugegraph_service)
-    client.graphs().clear_graph_all_data()
-    try:
-        yield hugegraph_service
-    finally:
-        try:
-            client.graphs().clear_graph_all_data()
-        finally:
-            for key, value in original.items():
-                setattr(huge_settings, key, value)
-
-
 def _create_quality_schema(client):
     schema = client.schema()
     schema.propertyKey("name").asText().ifNotExist().create()
@@ -160,13 +120,12 @@ def _commit_quality_graph():
     return commit.run(data)
 
 
-def test_schema_manager_reads_real_schema(configured_hugegraph):
+def test_schema_manager_reads_real_schema(hugegraph_client):
     from hugegraph_llm.operators.hugegraph_op.schema_manager import 
SchemaManager
 
-    client = _make_client(configured_hugegraph)
-    _create_quality_schema(client)
+    _create_quality_schema(hugegraph_client)
 
-    manager = SchemaManager(graph_name=configured_hugegraph.graph)
+    manager = SchemaManager(graph_name=hugegraph_client.cfg.graph_name)
     context = manager.run({})
 
     assert "schema" in context
@@ -175,16 +134,15 @@ def 
test_schema_manager_reads_real_schema(configured_hugegraph):
     assert any(label["name"] == "quality_person" for label in 
context["schema"]["vertexlabels"])
 
 
-def test_commit_to_graph_writes_vertices_and_edges(configured_hugegraph):
+def test_commit_to_graph_writes_vertices_and_edges(hugegraph_client):
     _commit_quality_graph()
 
-    client = _make_client(configured_hugegraph)
-    counts = client.gremlin().exec(
+    counts = hugegraph_client.gremlin().exec(
         """
         g.V().hasLabel('quality_person', 'quality_software').count()
         """
     )["data"][0]
-    edges = client.gremlin().exec(
+    edges = hugegraph_client.gremlin().exec(
         """
         g.E().hasLabel('quality_created').
           project('out', 'in', 'date').
@@ -201,11 +159,11 @@ def 
test_commit_to_graph_writes_vertices_and_edges(configured_hugegraph):
     assert edges[0]["date"] == "2026-05-31"
 
 
-def test_fetch_graph_data_returns_counts_and_samples(configured_hugegraph):
+def test_fetch_graph_data_returns_counts_and_samples(hugegraph_client):
     from hugegraph_llm.operators.hugegraph_op.fetch_graph_data import 
FetchGraphData
 
     _commit_quality_graph()
-    result = FetchGraphData(_make_client(configured_hugegraph)).run({})
+    result = FetchGraphData(hugegraph_client).run({})
 
     assert {"vertex_num", "edge_num", "vertices", "edges", 
"note"}.issubset(result)
     assert result["vertex_num"] == 2
@@ -214,7 +172,7 @@ def 
test_fetch_graph_data_returns_counts_and_samples(configured_hugegraph):
     assert isinstance(result["edges"], list)
 
 
-def test_gremlin_execute_surfaces_invalid_query(configured_hugegraph):
+def test_gremlin_execute_surfaces_invalid_query(hugegraph_client):
     from hugegraph_llm.nodes.hugegraph_node.gremlin_execute import 
GremlinExecuteNode
 
     node = GremlinExecuteNode()

Reply via email to