Skip to content

Commit

Permalink
add a test for #170
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldcampbelljr committed Apr 23, 2024
1 parent 2b1f4ec commit fa23321
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 25 deletions.
49 changes: 24 additions & 25 deletions tests/conftest.py
Expand Up @@ -22,31 +22,30 @@
"""
STANDARD_TEST_PIPE_ID = "default_pipeline_name"

try:
subprocess.check_output(
"docker inspect pipestat_test_db --format '{{.State.Status}}'", shell=True
)
SERVICE_UNAVAILABLE = False
except:
register(print, f"Some tests require a test database. To initiate it, run:\n{DB_CMD}")
SERVICE_UNAVAILABLE = True

try:
result = subprocess.check_output(
"pipestat report --c 'tests/data/config.yaml' -i 'name_of_something' -v 'test_value' -r 'dependency_value'",
shell=True,
)
DB_DEPENDENCIES = True
except:
register(
print,
f"Warning: you must install dependencies with pip install pipestat['dbbackend'] to run database tests.",
)
DB_DEPENDENCIES = False


# SERVICE_UNAVAILABLE = False
# DB_DEPENDENCIES = True
# try:
# subprocess.check_output(
# "docker inspect pipestat_test_db --format '{{.State.Status}}'", shell=True
# )
# SERVICE_UNAVAILABLE = False
# except:
# register(print, f"Some tests require a test database. To initiate it, run:\n{DB_CMD}")
# SERVICE_UNAVAILABLE = True
#
# try:
# result = subprocess.check_output(
# "pipestat report --c 'tests/data/config.yaml' -i 'name_of_something' -v 'test_value' -r 'dependency_value'",
# shell=True,
# )
# DB_DEPENDENCIES = True
# except:
# register(
# print,
# f"Warning: you must install dependencies with pip install pipestat['dbbackend'] to run database tests.",
# )
# DB_DEPENDENCIES = False

SERVICE_UNAVAILABLE = False
DB_DEPENDENCIES = True


def get_data_file_path(filename: str) -> str:
Expand Down
33 changes: 33 additions & 0 deletions tests/test_pipestat.py
Expand Up @@ -7,6 +7,7 @@
import pytest
from jsonschema import ValidationError

import pipestat.exceptions
from pipestat import SamplePipestatManager, ProjectPipestatManager, PipestatBoss, PipestatManager
from pipestat.const import *
from pipestat.exceptions import *
Expand Down Expand Up @@ -355,6 +356,38 @@ def test_complex_object_report(
]
)

@pytest.mark.parametrize(
"val",
[
{"output_file": {"path": "path_string", "title": "title_string"}},
{
"output_image": {
"path": "path_string",
"thumbnail_path": "thumbnail_path_string",
"title": "title_string",
}
},
],
)
@pytest.mark.parametrize("backend", ["db"])
def test_complex_object_report_missing_fields(
self, val, config_file_path, recursive_schema_file_path, results_file_path, backend
):
with NamedTemporaryFile() as f, ContextManagerDBTesting(DB_URL):
results_file_path = f.name
args = dict(schema_path=recursive_schema_file_path, database_only=False)
backend_data = (
{"config_file": config_file_path}
if backend == "db"
else {"results_file_path": results_file_path}
)
args.update(backend_data)

psm = SamplePipestatManager(**args)
del val[list(val.keys())[0]]["path"]
with pytest.raises(pipestat.exceptions.SchemaValidationErrorDuringReport):
psm.report(record_identifier=REC_ID, values=val, force_overwrite=True)

@pytest.mark.parametrize(
["rec_id", "val"],
[
Expand Down

0 comments on commit fa23321

Please sign in to comment.