Skip to content

Commit

Permalink
fix all tests #99
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldcampbelljr committed Oct 26, 2023
1 parent debcecd commit 12545ea
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 40 deletions.
4 changes: 2 additions & 2 deletions pipestat/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ def main(test_args=None):
types_to_read_from_json = ["object"] + list(CANONICAL_TYPES.keys())
if args.command == REPORT_CMD:
value = args.value
if psm.schema is None:
if psm.store[SCHEMA_KEY] is None:
raise SchemaNotFoundError(msg="report", cli=True)
result_metadata = psm.schema.results_data[args.result_identifier]
result_metadata = psm.store[SCHEMA_KEY].results_data[args.result_identifier]
if result_metadata[SCHEMA_TYPE_KEY] in types_to_read_from_json:
path_to_read = expandpath(value)
if os.path.exists(path_to_read):
Expand Down
78 changes: 46 additions & 32 deletions pipestat/pipestat.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,22 @@ def __init__(
self.store = {}

# Uses setitem
self['test'] = 'test2'
self["test"] = "test2"
# Does NOT use setitem
self.test3 = "test4"

# Load and validate database configuration
# If results_file_path is truthy, backend is a file
# Otherwise, backend is a database.
#self._config_path = select_config(config_file, ENV_VARS["config"])
# self._config_path = select_config(config_file, ENV_VARS["config"])

self.store["config_path"] = select_config(config_file, ENV_VARS["config"])

#_LOGGER.info(f"Config: {self.store["config_path"]}.")
# _LOGGER.info(f"Config: {self.store["config_path"]}.")

self.store[CONFIG_KEY] = YAMLConfigManager(entries=config_dict, filepath=self.store["config_path"])
self.store[CONFIG_KEY] = YAMLConfigManager(
entries=config_dict, filepath=self.store["config_path"]
)

_, cfg_schema = read_yaml_data(CFG_SCHEMA, "config schema")
validate(self.store[CONFIG_KEY].exp, cfg_schema)
Expand All @@ -146,12 +148,15 @@ def __init__(
) # schema_path if schema_path is not None else None
self.process_schema(schema_path)

#self[RECORD_IDENTIFIER] = record_identifier
#self.record_identifier = record_identifier
# self[RECORD_IDENTIFIER] = record_identifier
# self.record_identifier = record_identifier
self.store[RECORD_IDENTIFIER] = record_identifier

print(self.store[SCHEMA_KEY])
self.store[PIPELINE_NAME] = (
self.schema.pipeline_name if self.schema is not None else pipeline_name
self.store[SCHEMA_KEY].pipeline_name
if self.store[SCHEMA_KEY] is not None
else pipeline_name
)

self.store[PROJECT_NAME] = self.store[CONFIG_KEY].priority_get(
Expand Down Expand Up @@ -179,7 +184,9 @@ def __init__(

self.store[MULTI_PIPELINE] = multi_pipelines

self.store[OUTPUT_DIR] = self.store[CONFIG_KEY].priority_get("output_dir", override=output_dir)
self.store[OUTPUT_DIR] = self.store[CONFIG_KEY].priority_get(
"output_dir", override=output_dir
)

if self.store[FILE_KEY]:
# file backend
Expand All @@ -195,30 +202,30 @@ def __str__(self):
:return str: string representation of the object
"""
res = f"{self.__class__.__name__} ({self[PIPELINE_NAME]})"
res = f"{self.__class__.__name__} ({self.store[PIPELINE_NAME]})"
res += "\nBackend: {}".format(
f"File\n - results: {self.file}\n - status: {self[STATUS_FILE_DIR]}"
if self.file
f"File\n - results: {self.store[FILE_KEY]}\n - status: {self.store[STATUS_FILE_DIR]}"
if self.store[FILE_KEY]
else f"Database (dialect: {self.backend.db_engine_key})"
)
if self.file:
res += f"\nMultiple Pipelines Allowed: {self[MULTI_PIPELINE]}"
if self.store[FILE_KEY]:
res += f"\nMultiple Pipelines Allowed: {self.store[MULTI_PIPELINE]}"
else:
res += f"\nProject Name: {self[PROJECT_NAME]}"
res += f"\nDatabase URL: {self[DB_URL]}"
res += f"\nProject Name: {self.store[PROJECT_NAME]}"
res += f"\nDatabase URL: {self.store[DB_URL]}"
res += f"\nConfig File: {self.config_path}"

res += f"\nPipeline name: {self[PIPELINE_NAME]}"
res += f"\nPipeline type: {self[PIPELINE_TYPE]}"
res += f"\nPipeline name: {self.store[PIPELINE_NAME]}"
res += f"\nPipeline type: {self.store[PIPELINE_TYPE]}"
if self.store[SCHEMA_PATH] is not None:
res += f"\nProject Level Data:"
for k, v in self[SCHEMA_KEY].project_level_data.items():
for k, v in self.store[SCHEMA_KEY].project_level_data.items():
res += f"\n {k} : {v}"
res += f"\nSample Level Data:"
for k, v in self[SCHEMA_KEY].sample_level_data.items():
for k, v in self.store[SCHEMA_KEY].sample_level_data.items():
res += f"\n {k} : {v}"
res += f"\nStatus Schema key: {self[STATUS_SCHEMA_KEY]}"
res += f"\nResults formatter: {str(self[RESULT_FORMATTER].__name__)}"
res += f"\nStatus Schema key: {self.store[STATUS_SCHEMA_KEY]}"
res += f"\nResults formatter: {str(self.store[RESULT_FORMATTER].__name__)}"
res += f"\nResults schema source: {self.store[SCHEMA_PATH]}"
res += f"\nStatus schema source: {self.status_schema_source}"
res += f"\nRecords count: {self.record_count}"
Expand All @@ -231,12 +238,11 @@ def __str__(self):
return res

def __getitem__(self, key):
#return self.store[self._keytransform(key)]
print(key)

# return self.store[self._keytransform(key)]
print(key)

def __setitem__(self, key, value):
#self.store[self._keytransform(key)] = value
# self.store[self._keytransform(key)] = value
print(key)
# self.report()

Expand Down Expand Up @@ -264,7 +270,9 @@ def initialize_filebackend(self, record_identifier, results_file_path, flag_file
flag_file_dir = self.store[CONFIG_KEY].priority_get(
"flag_file_dir", override=flag_file_dir, default=os.path.dirname(self.store[FILE_KEY])
)
self.store[STATUS_FILE_DIR] = mk_abs_via_cfg(flag_file_dir, self.config_path or self.store[FILE_KEY])
self.store[STATUS_FILE_DIR] = mk_abs_via_cfg(
flag_file_dir, self.config_path or self.store[FILE_KEY]
)

self.backend = FileBackend(
self.store[FILE_KEY],
Expand Down Expand Up @@ -425,9 +433,10 @@ def process_schema(self, schema_path):
# Status schema
self.store[STATUS_SCHEMA_KEY] = parsed_schema.status_data
if not self.store[STATUS_SCHEMA_KEY]:
self.store[STATUS_SCHEMA_SOURCE_KEY], self.store[STATUS_SCHEMA_KEY] = read_yaml_data(
path=STATUS_SCHEMA, what="default status schema"
)
(
self.store[STATUS_SCHEMA_SOURCE_KEY],
self.store[STATUS_SCHEMA_KEY],
) = read_yaml_data(path=STATUS_SCHEMA, what="default status schema")
else:
self.store[STATUS_SCHEMA_SOURCE_KEY] = schema_to_read

Expand Down Expand Up @@ -522,7 +531,7 @@ def report(
raise NotImplementedError("You must supply a record identifier to report results")

result_identifiers = list(values.keys())
if self.schema is not None:
if self.store[SCHEMA_KEY] is not None:
for r in result_identifiers:
validate_type(
value=values[r], schema=self.result_schemas[r], strict_type=strict_type
Expand Down Expand Up @@ -642,7 +651,9 @@ def summarize(
"""

html_report_builder = HTMLReportBuilder(prj=self)
report_path = html_report_builder(pipeline_name=self.pipeline_name, amendment=amendment)
report_path = html_report_builder(
pipeline_name=self.store[PIPELINE_NAME], amendment=amendment
)
return report_path

@require_backend
Expand Down Expand Up @@ -787,7 +798,10 @@ def result_schemas(self) -> Dict[str, Any]:
:return dict: schemas that formalize the structure of each result
in a canonical jsonschema way
"""
return {**self.store[SCHEMA_KEY].project_level_data, **self.store[SCHEMA_KEY].sample_level_data}
return {
**self.store[SCHEMA_KEY].project_level_data,
**self.store[SCHEMA_KEY].sample_level_data,
}

@property
def schema(self) -> ParsedSchema:
Expand Down
4 changes: 2 additions & 2 deletions pipestat/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def __init__(self, prj):
self.prj = prj
self.jinja_env = get_jinja_env()
results_file_path = getattr(self.prj.backend, "results_file_path", None)
config_path = self.prj.store.get('config_path', None)
output_dir = getattr(self.prj, "output_dir", None)
config_path = self.prj.store.get("config_path", None)
output_dir = getattr(self.prj.store[OUTPUT_DIR], "output_dir", None)
self.output_dir = output_dir or results_file_path or config_path
self.output_dir = os.path.dirname(self.output_dir)
self.reports_dir = os.path.join(self.output_dir, "reports")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_pipestat.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,8 @@ def test_manager_has_correct_status_schema_and_status_schema_source(
schema_file_path, exp_status_schema, exp_status_schema_path, backend_data
):
psm = SamplePipestatManager(schema_path=schema_file_path, **backend_data)
assert psm.status_schema == exp_status_schema
assert psm.status_schema_source == exp_status_schema_path
assert psm.store[STATUS_SCHEMA_KEY] == exp_status_schema
assert psm.store[STATUS_SCHEMA_SOURCE_KEY] == exp_status_schema_path


class TestPipestatBoss:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import pytest
from pipestat import SamplePipestatManager, SamplePipestatManager, ProjectPipestatManager
from pipestat.const import STATUS_FILE_DIR
from pipestat.const import STATUS_FILE_DIR, FILE_KEY
from .conftest import BACKEND_KEY_DB, BACKEND_KEY_FILE, DB_URL

from .test_db_only_mode import ContextManagerDBTesting
Expand All @@ -17,7 +17,7 @@ def test_status_file_default_location(schema_file_path, results_file_path):
results_file_path=results_file_path,
schema_path=schema_file_path,
)
assert psm[STATUS_FILE_DIR] == os.path.dirname(psm.file)
assert psm.store[STATUS_FILE_DIR] == os.path.dirname(psm.store[FILE_KEY])


@pytest.mark.parametrize("backend_data", ["file", "db"], indirect=True)
Expand Down

0 comments on commit 12545ea

Please sign in to comment.