Skip to content

Commit

Permalink
Merge pull request #193 from pepkit/dev_sqllite_support
Browse files Browse the repository at this point in the history
add sqlite option if included in config file
  • Loading branch information
donaldcampbelljr authored Jul 18, 2024
2 parents 1a0cce9 + f75adca commit 17a1273
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pipestat/pipestat.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,11 @@ def initialize_dbbackend(self, record_identifier: str = None, show_db_logs: bool
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 @@ -82,6 +82,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 @@ -132,3 +134,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})")

0 comments on commit 17a1273

Please sign in to comment.