Skip to content

Commit

Permalink
setitem is now a wrapper for report
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldcampbelljr committed Oct 26, 2023
1 parent 8c19cb2 commit df4eed8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pipestat/pipestat.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,10 @@ def __getitem__(self, key):
print(key)

def __setitem__(self, key, value):
# self.cfg[self._keytransform(key)] = value
print(key)
# self.report()
# This is a wrapper for the report function:
result = self.report(record_identifier=key, values=value)
return result


def __delitem__(self, key):
del self.cfg[self._keytransform(key)]
Expand Down
44 changes: 44 additions & 0 deletions tests/test_pipestat.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,50 @@ def test_report_basic(
# This is being captured in TestSplitClasses
pass

@pytest.mark.parametrize(
["rec_id", "val"],
[
("sample1", {"name_of_something": "test_name"}),
("sample1", {"number_of_things": 1}),
],
)
@pytest.mark.parametrize("backend", ["file", "db"])
def test_report_setitem(
self,
rec_id,
val,
config_file_path,
schema_file_path,
results_file_path,
backend,
):
with NamedTemporaryFile() as f, ContextManagerDBTesting(DB_URL):
results_file_path = f.name
args = dict(schema_path=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)
#psm.report(record_identifier=rec_id, values=val, force_overwrite=True)
psm[rec_id] = val
if backend == "file":
print(psm.backend._data[STANDARD_TEST_PIPE_ID])
print("Test if", rec_id, " is in ", psm.backend._data[STANDARD_TEST_PIPE_ID])
assert rec_id in psm.backend._data[STANDARD_TEST_PIPE_ID][PROJECT_SAMPLE_LEVEL]
print("Test if", list(val.keys())[0], " is in ", rec_id)
assert (
list(val.keys())[0]
in psm.backend._data[STANDARD_TEST_PIPE_ID][PROJECT_SAMPLE_LEVEL][rec_id]
)
if backend == "file":
assert_is_in_files(results_file_path, str(list(val.values())[0]))
if backend == "db":
# This is being captured in TestSplitClasses
pass

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

0 comments on commit df4eed8

Please sign in to comment.