From 4384c019b0ba4444ddfb03db97246329f574c590 Mon Sep 17 00:00:00 2001 From: Gus Date: Tue, 24 Sep 2024 14:16:18 +0800 Subject: [PATCH] fix: remove test coverage for neo4j --- .coveragerc | 5 ++- .github/workflows/test.yml | 2 + nano_graphrag/_storage/gdb_neo4j.py | 61 +++++++++++++---------------- tests/test_neo4j_storage.py | 3 ++ 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/.coveragerc b/.coveragerc index 2f7552f..177da7e 100644 --- a/.coveragerc +++ b/.coveragerc @@ -5,4 +5,7 @@ exclude_lines = # Don't complain if tests don't hit defensive assertion code: raise NotImplementedError - logger. \ No newline at end of file + logger. +omit = + # Don't have a nice github action for neo4j now, so skip this file: + nano_graphrag/_storage/gdb_neo4j.py \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 865a594..cae9125 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/nano_graphrag/_storage/gdb_neo4j.py b/nano_graphrag/_storage/gdb_neo4j.py index 9effdbf..8457f80 100644 --- a/nano_graphrag/_storage/gdb_neo4j.py +++ b/nano_graphrag/_storage/gdb_neo4j.py @@ -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() @@ -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() diff --git a/tests/test_neo4j_storage.py b/tests/test_neo4j_storage.py index 80a70f8..488e813 100644 --- a/tests/test_neo4j_storage.py +++ b/tests/test_neo4j_storage.py @@ -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():