Skip to content

Commit a68712a

Browse files
committed
WIP: e2e tests
1 parent 1b724c5 commit a68712a

File tree

5 files changed

+164
-9
lines changed

5 files changed

+164
-9
lines changed

poetry.lock

+12-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ json-repair = "^0.30.2"
5252
types-pyyaml = "^6.0.12.20240917"
5353
ollama = {version = "^0.4.4", optional = true}
5454
uuid = "^1.30"
55+
weaviate = "^0.1.2"
5556

5657
[tool.poetry.group.dev.dependencies]
5758
urllib3 = "<2"

tests/e2e/conftest.py

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ def driver() -> Generator[Any, Any, Any]:
4646
driver.close()
4747

4848

49+
@pytest.fixture(scope="function", autouse=True)
50+
def clear_db(driver: Driver) -> Any:
51+
driver.execute_query("MATCH (n) DETACH DELETE n")
52+
yield
53+
54+
4955
@pytest.fixture(scope="function")
5056
def llm() -> MagicMock:
5157
return MagicMock(spec=LLMInterface)

tests/e2e/experimental/pipeline/config/test_pipeline_runner_e2e.py

-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@
99
from neo4j_graphrag.llm import LLMResponse
1010

1111

12-
@pytest.fixture(scope="function", autouse=True)
13-
def clear_db(driver: neo4j.Driver) -> Any:
14-
driver.execute_query("MATCH (n) DETACH DELETE n")
15-
yield
16-
17-
1812
@pytest.mark.asyncio
1913
async def test_pipeline_from_json_config(harry_potter_text: str, driver: Mock) -> None:
2014
os.environ["NEO4J_URI"] = "neo4j://localhost:7687"

tests/e2e/test_simplekgpipeline_e2e.py

+145-2
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,148 @@ async def test_pipeline_builder_happy_path(
108108
)
109109

110110
# Run the knowledge graph building process with text input
111-
text_input = "John Doe lives in New York City."
112-
await kg_builder_text.run_async(text=text_input)
111+
await kg_builder_text.run_async(text=harry_potter_text)
112+
113+
114+
115+
@pytest.mark.asyncio
116+
@pytest.mark.usefixtures("setup_neo4j_for_kg_construction")
117+
async def test_pipeline_builder_two_documents(
118+
harry_potter_text_part1: str,
119+
harry_potter_text_part2: str,
120+
llm: MagicMock,
121+
embedder: MagicMock,
122+
driver: neo4j.Driver,
123+
) -> None:
124+
"""When everything works as expected, extracted entities, relations and text
125+
chunks must be in the DB
126+
"""
127+
driver.execute_query("MATCH (n) DETACH DELETE n")
128+
embedder.embed_query.return_value = [1, 2, 3]
129+
llm.ainvoke.side_effect = [
130+
# first document
131+
# first chunk
132+
LLMResponse(
133+
content="""{
134+
"nodes": [
135+
{
136+
"id": "0",
137+
"label": "Person",
138+
"properties": {
139+
"name": "Harry Potter"
140+
}
141+
},
142+
],
143+
"relationships": []
144+
}"""
145+
),
146+
# second chunk
147+
LLMResponse(content='{"nodes": [], "relationships": []}'),
148+
# second document
149+
# first chunk
150+
LLMResponse(
151+
content="""{
152+
"nodes": [
153+
{
154+
"id": "0",
155+
"label": "Person",
156+
"properties": {
157+
"name": "Hermione Granger"
158+
}
159+
},
160+
],
161+
"relationships": []
162+
}"""
163+
),
164+
# second chunk
165+
LLMResponse(content='{"nodes": [], "relationships": []}'),
166+
]
167+
168+
# Create an instance of the SimpleKGPipeline
169+
kg_builder_text = SimpleKGPipeline(
170+
llm=llm,
171+
driver=driver,
172+
embedder=embedder,
173+
from_pdf=False,
174+
)
175+
176+
# Run the knowledge graph building process with text input
177+
await kg_builder_text.run_async(text=harry_potter_text_part1)
178+
await kg_builder_text.run_async(text=harry_potter_text_part2)
179+
180+
# check graph content
181+
records, _, _ = driver.execute_query("MATCH (n) RETURN n")
182+
print(records)
183+
184+
assert False
185+
186+
187+
@pytest.mark.asyncio
188+
@pytest.mark.usefixtures("setup_neo4j_for_kg_construction")
189+
async def test_pipeline_builder_same_document_two_runs(
190+
harry_potter_text_part1: str,
191+
llm: MagicMock,
192+
embedder: MagicMock,
193+
driver: neo4j.Driver,
194+
) -> None:
195+
"""When everything works as expected, extracted entities, relations and text
196+
chunks must be in the DB
197+
"""
198+
driver.execute_query("MATCH (n) DETACH DELETE n")
199+
embedder.embed_query.return_value = [1, 2, 3]
200+
llm.ainvoke.side_effect = [
201+
# first run
202+
# first chunk
203+
LLMResponse(
204+
content="""{
205+
"nodes": [
206+
{
207+
"id": "0",
208+
"label": "Person",
209+
"properties": {
210+
"name": "Harry Potter"
211+
}
212+
},
213+
],
214+
"relationships": []
215+
}"""
216+
),
217+
# second chunk
218+
LLMResponse(content='{"nodes": [], "relationships": []}'),
219+
# second run
220+
# first chunk
221+
LLMResponse(
222+
content="""{
223+
"nodes": [
224+
{
225+
"id": "0",
226+
"label": "Person",
227+
"properties": {
228+
"name": "Harry Potter"
229+
}
230+
},
231+
],
232+
"relationships": []
233+
}"""
234+
),
235+
# second chunk
236+
LLMResponse(content='{"nodes": [], "relationships": []}'),
237+
]
238+
239+
# Create an instance of the SimpleKGPipeline
240+
kg_builder_text = SimpleKGPipeline(
241+
llm=llm,
242+
driver=driver,
243+
embedder=embedder,
244+
from_pdf=False,
245+
)
246+
247+
# Run the knowledge graph building process with text input
248+
await kg_builder_text.run_async(text=harry_potter_text_part1)
249+
await kg_builder_text.run_async(text=harry_potter_text_part1)
250+
251+
# check graph content
252+
records, _, _ = driver.execute_query("MATCH (n) RETURN n")
253+
print(records)
254+
255+
assert False

0 commit comments

Comments
 (0)