Skip to content

Commit

Permalink
sqlite now stores all the test databases in the .persist folder to ke…
Browse files Browse the repository at this point in the history
…ep things clean
  • Loading branch information
norton120 committed Jun 19, 2024
1 parent eb50aff commit 4d1444b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions development.compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ services:
- ./tests/pytest.ini:/memgpt/pytest.ini
- ./pyproject.toml:/pyproject.toml
- ./tests:/tests
- ./.persist/sqlite:/sqlite
ports:
- "8083:8083"
- "8283:8283"
26 changes: 17 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,25 @@ def db_session(request) -> "Session":
"""
function_ = request.node.name.replace("[","_").replace("]","_")
engine = create_engine(storage_type=request.param, database="test_memgpt")
adapter_statements = {
"sqlite_chroma": (text(f"attach ':memory:' as {function_}"),),
"postgres": (
text(f"CREATE SCHEMA IF NOT EXISTS {function_}"),
text(f"CREATE EXTENSION IF NOT EXISTS vector"),
text(f"SET search_path TO {function_},public"),
),
adapter_test_configurations = {
"sqlite_chroma": {
"statements": (text(f"attach ':memory:' as {function_}"),),
"database": f"/sqlite/{function_}.db"
},
"postgres": {
"statements":(
text(f"CREATE SCHEMA IF NOT EXISTS {function_}"),
text(f"CREATE EXTENSION IF NOT EXISTS vector"),
text(f"SET search_path TO {function_},public"),
),
"database": "test_memgpt"
}
}
adapter = adapter_test_configurations[request.param]
engine = create_engine(storage_type=request.param, database=adapter["database"])

with engine.begin() as connection:
for statement in adapter_statements[request.param]:
for statement in adapter["statements"]:
connection.execute(statement)
Base.metadata.drop_all(bind=connection)
Base.metadata.create_all(bind=connection)
Expand Down

0 comments on commit 4d1444b

Please sign in to comment.