Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sqlite option if included in config file #193

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pipestat/pipestat.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,11 @@ def initialize_dbbackend(self, record_identifier, show_db_logs):
dbconf = self.cfg[CONFIG_KEY].exp[
CFG_DATABASE_KEY
] # the .exp expands the paths before url construction
self.cfg[DB_URL] = construct_db_url(dbconf)
if "sqlite_url" in dbconf:
sqlite_url = f"sqlite:///{dbconf['sqlite_url']}"
self.cfg[DB_URL] = sqlite_url
else:
self.cfg[DB_URL] = construct_db_url(dbconf)
except KeyError:
raise PipestatDatabaseError(f"No database section ('{CFG_DATABASE_KEY}') in config")
self._show_db_logs = show_db_logs
Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ def schema_file_path():
return get_data_file_path("sample_output_schema.yaml")


@pytest.fixture
def schema_file_path_sqlite():
return get_data_file_path("sample_output_schema_sqlite.yaml")


@pytest.fixture
def highlight_schema_file_path():
return get_data_file_path("sample_output_schema_highlight.yaml")
Expand Down
14 changes: 14 additions & 0 deletions tests/data/sample_output_schema_sqlite.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
title: An example Pipestat output schema
description: A pipeline that uses pipestat to report sample and project level results.
type: object
properties:
pipeline_name: "default_pipeline_name"
samples:
type: object
properties:
number_of_things:
type: integer
description: "Number of things"
percentage_of_things:
type: number
description: "Percentage of things"
26 changes: 26 additions & 0 deletions tests/test_db_only_mode.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from tempfile import NamedTemporaryFile

import pytest

from pipestat import SamplePipestatManager
Expand Down Expand Up @@ -134,3 +136,27 @@ def test_select_pagination(
result = psm.select_records(cursor=offset, limit=limit)
print(result)
assert len(result["records"]) == min(max((psm.record_count - offset), 0), limit)


class TestSQLLITE:
def test_manager_can_be_built_without_exception(self, schema_file_path_sqlite):

with NamedTemporaryFile() as f:
sqllite_url = f"sqlite:///{f.name}"
config_dict = {
"project_name": "test",
"record_identifier": "sample1",
"schema_path": "sample_output_schema_sqlite.yaml",
"database": {"sqlite_url": f.name},
}

with ContextManagerDBTesting(sqllite_url):
try:
SamplePipestatManager(
schema_path=schema_file_path_sqlite,
record_identifier="irrelevant",
database_only=True,
config_dict=config_dict,
)
except Exception as e:
pytest.fail(f"Pipestat manager construction failed: {e})")
Loading