Skip to content

Commit

Permalink
fix: remove test coverage for neo4j
Browse files Browse the repository at this point in the history
  • Loading branch information
gusye1234 committed Sep 24, 2024
1 parent 01d14ac commit 4384c01
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 35 deletions.
5 changes: 4 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ exclude_lines =

# Don't complain if tests don't hit defensive assertion code:
raise NotImplementedError
logger.
logger.
omit =
# Don't have a nice github action for neo4j now, so skip this file:
nano_graphrag/_storage/gdb_neo4j.py
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ jobs:
run: |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
- name: Build and Test
env:
NANO_GRAPHRAG_TEST_IGNORE_NEO4J: true
run: |
python -m pytest -o log_cli=true -o log_cli_level="INFO" --cov=nano_graphrag --cov-report=xml -v ./
- name: Check codecov file
Expand Down
61 changes: 27 additions & 34 deletions nano_graphrag/_storage/gdb_neo4j.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import asyncio
from functools import wraps
from collections import defaultdict
from neo4j import AsyncGraphDatabase, GraphDatabase
from neo4j import AsyncGraphDatabase
from dataclasses import dataclass
from typing import Union
from ..base import BaseGraphStorage, SingleCommunitySchema
from .._utils import logger, always_get_an_event_loop
from .._utils import logger
from ..prompt import GRAPH_FIELD_SEP

neo4j_lock = asyncio.Lock()
Expand All @@ -30,37 +29,31 @@ def __post_init__(self):
self.neo4j_url, auth=self.neo4j_auth
)

async def create_database(self):
async with self.async_driver.session() as session:
try:
constraints = await session.run("SHOW CONSTRAINTS")
# TODO I don't know why CREATE CONSTRAINT IF NOT EXISTS still trigger error
# so have to check if the constrain exists
constrain_exists = False

async for record in constraints:
print(
record,
self.namespace in record["labelsOrTypes"]
and "id" in record["properties"]
and record["type"] == "UNIQUENESS",
)
if (
self.namespace in record["labelsOrTypes"]
and "id" in record["properties"]
and record["type"] == "UNIQUENESS"
):
constrain_exists = True
break
if not constrain_exists:
await session.run(
f"CREATE CONSTRAINT FOR (n:{self.namespace}) REQUIRE n.id IS UNIQUE"
)
logger.info(f"Add constraint for namespace: {self.namespace}")

except Exception as e:
logger.error(f"Error accessing or setting up the database: {str(e)}")
raise
# async def create_database(self):
# async with self.async_driver.session() as session:
# try:
# constraints = await session.run("SHOW CONSTRAINTS")
# # TODO I don't know why CREATE CONSTRAINT IF NOT EXISTS still trigger error
# # so have to check if the constrain exists
# constrain_exists = False

# async for record in constraints:
# if (
# self.namespace in record["labelsOrTypes"]
# and "id" in record["properties"]
# and record["type"] == "UNIQUENESS"
# ):
# constrain_exists = True
# break
# if not constrain_exists:
# await session.run(
# f"CREATE CONSTRAINT FOR (n:{self.namespace}) REQUIRE n.id IS UNIQUE"
# )
# logger.info(f"Add constraint for namespace: {self.namespace}")

# except Exception as e:
# logger.error(f"Error accessing or setting up the database: {str(e)}")
# raise

async def _init_workspace(self):
await self.async_driver.verify_authentication()
Expand Down
3 changes: 3 additions & 0 deletions tests/test_neo4j_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from nano_graphrag._storage import Neo4jStorage
from nano_graphrag._utils import wrap_embedding_func_with_attrs

if os.environ.get("NANO_GRAPHRAG_TEST_IGNORE_NEO4J", False):
pytest.skip("skipping neo4j tests", allow_module_level=True)


@pytest.fixture(scope="module")
def neo4j_config():
Expand Down

0 comments on commit 4384c01

Please sign in to comment.