From fa2332175ee1eedcc706daed1e76619ac3713d31 Mon Sep 17 00:00:00 2001 From: Donald Campbell <125581724+donaldcampbelljr@users.noreply.github.com> Date: Tue, 23 Apr 2024 11:23:50 -0400 Subject: [PATCH 01/10] add a test for #170 --- tests/conftest.py | 49 +++++++++++++++++++++--------------------- tests/test_pipestat.py | 33 ++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index e31df43d..5c1ba27e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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: diff --git a/tests/test_pipestat.py b/tests/test_pipestat.py index c874f36c..1015e418 100644 --- a/tests/test_pipestat.py +++ b/tests/test_pipestat.py @@ -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 * @@ -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"], [ From b13299f593df4caaab02b5cfc20fdb36d413964e Mon Sep 17 00:00:00 2001 From: Donald Campbell <125581724+donaldcampbelljr@users.noreply.github.com> Date: Tue, 23 Apr 2024 11:42:27 -0400 Subject: [PATCH 02/10] revert test skipping when checking for dependencies --- tests/conftest.py | 48 +++++++++++++++++++++--------------------- tests/data/config.yaml | 2 +- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 5c1ba27e..f4a634c1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -22,30 +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: diff --git a/tests/data/config.yaml b/tests/data/config.yaml index f6b37c09..d3c64b4a 100644 --- a/tests/data/config.yaml +++ b/tests/data/config.yaml @@ -1,6 +1,6 @@ project_name: test record_identifier: sample1 -schema_path: sample_output_schema.yaml +schema_path: sample_output_schema_recursive.yaml database: dialect: postgresql driver: psycopg From 074a41cd739b8c17e63341b93a0e31bba4e7555f Mon Sep 17 00:00:00 2001 From: Donald Campbell <125581724+donaldcampbelljr@users.noreply.github.com> Date: Tue, 23 Apr 2024 12:06:16 -0400 Subject: [PATCH 03/10] potential fix for #150 --- pipestat/reports.py | 2 +- tests/test_pipestat.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/pipestat/reports.py b/pipestat/reports.py index 2cf5422b..ffff8a57 100644 --- a/pipestat/reports.py +++ b/pipestat/reports.py @@ -704,7 +704,7 @@ def create_index_html(self, navbar, footer): all_result_identifiers = input_sample_attributes + all_result_identifiers if self.prj.cfg["multi_result_files"] is True: - pipeline_types = ["sample", "project"] + pipeline_types = ["sample"] else: pipeline_types = [self.prj.backend.pipeline_type] diff --git a/tests/test_pipestat.py b/tests/test_pipestat.py index 1015e418..cd0a6ec7 100644 --- a/tests/test_pipestat.py +++ b/tests/test_pipestat.py @@ -2514,3 +2514,36 @@ def test_select_history_complex_objects( assert len(history_result.keys()) == 1 assert "output_image" in history_result assert len(history_result["output_image"].keys()) == 2 + + @pytest.mark.parametrize("backend", ["file"]) + def test_temp( + self, + config_file_path, + results_file_path, + recursive_schema_file_path, + backend, + range_values, + ): + # This is for temporary PEATAC testing for determining summarize function + with TemporaryDirectory() as d, ContextManagerDBTesting(DB_URL): + temp_dir = d + # single_results_file_path = "{record_identifier}/results.yaml" + # results_file_path = os.path.join(temp_dir, single_results_file_path) + # args = dict(schema_path=recursive_schema_file_path, database_only=False) + # n = 3 + config_file_path = "/home/drc/pepatac_tutorial/processed/looper_pipestat_config.yaml" + + # for i in range_values[:n]: + # r_id = i[0] + # val = i[1] + # backend_data = {"record_identifier": r_id, "results_file_path": results_file_path} + # args.update(backend_data) + # psm = SamplePipestatManager(**args) + # psm.report(record_identifier=r_id, values=val, force_overwrite=True) + psm = PipestatManager(config_file=config_file_path) + reportlink = psm.summarize() + print(reportlink) + statstsv = psm.table() + print(statstsv) + # data = YAMLConfigManager(filepath=os.path.join(temp_dir, "aggregate_results.yaml")) + # assert r_id in data[psm.pipeline_name][psm.pipeline_type].keys() From 182455a09d68a7c1ff70b1cdb3d808e04f3af70d Mon Sep 17 00:00:00 2001 From: Donald Campbell <125581724+donaldcampbelljr@users.noreply.github.com> Date: Tue, 23 Apr 2024 12:58:29 -0400 Subject: [PATCH 04/10] potential fix for #148 --- pipestat/reports.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pipestat/reports.py b/pipestat/reports.py index ffff8a57..ee2d0989 100644 --- a/pipestat/reports.py +++ b/pipestat/reports.py @@ -731,6 +731,15 @@ def create_index_html(self, navbar, footer): if key not in sample_stat_results.keys(): sample_stat_results[key] = "" + for key in self.schema.keys(): + if "type" in self.schema[key]: + if ( + self.schema[key]["type"] == "file" + or self.schema[key]["type"] == "image" + or self.schema[key]["type"] == "object" + ): + del sample_stat_results[key] + # Sort to ensure alignment in the table sorted_sample_stat_results = dict(sorted(sample_stat_results.items())) From 5379c36dee8ae19ce7112f894d835361f8f7a377 Mon Sep 17 00:00:00 2001 From: Donald Campbell <125581724+donaldcampbelljr@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:09:01 -0400 Subject: [PATCH 05/10] Remove record identifier from stats column #148 --- pipestat/reports.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pipestat/reports.py b/pipestat/reports.py index ee2d0989..b4ff4c79 100644 --- a/pipestat/reports.py +++ b/pipestat/reports.py @@ -789,13 +789,14 @@ def create_index_html(self, navbar, footer): ) project_objects = self.create_project_objects() - columns = ["Record Identifiers"] + list(sorted_sample_stat_results.keys()) + columns_table = ["Record Identifiers"] + list(sorted_sample_stat_results.keys()) + columns_stats = list(sorted_sample_stat_results.keys()) template_vars = dict( navbar=navbar, stats_file_path=stats_file_path, objs_file_path=objs_file_path, - columns=columns, - columns_json=dumps(columns), + columns=columns_table, + columns_json=dumps(columns_stats), table_row_data=table_row_data, project_name=self.prj.cfg[PROJECT_NAME], pipeline_name=self.pipeline_name, @@ -947,7 +948,7 @@ def get_nonhighlighted_results(self, types): def _stats_to_json_str(self): results = {} if self.prj.cfg["multi_result_files"] is True: - pipeline_types = ["sample", "project"] + pipeline_types = ["sample"] else: pipeline_types = [self.prj.backend.pipeline_type] From 07b4697378c7fe16fe8f98a263cb15915474193d Mon Sep 17 00:00:00 2001 From: Donald Campbell <125581724+donaldcampbelljr@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:17:34 -0400 Subject: [PATCH 06/10] Remove manual reporting test --- tests/test_pipestat.py | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/tests/test_pipestat.py b/tests/test_pipestat.py index cd0a6ec7..7e5f08fe 100644 --- a/tests/test_pipestat.py +++ b/tests/test_pipestat.py @@ -2515,35 +2515,3 @@ def test_select_history_complex_objects( assert "output_image" in history_result assert len(history_result["output_image"].keys()) == 2 - @pytest.mark.parametrize("backend", ["file"]) - def test_temp( - self, - config_file_path, - results_file_path, - recursive_schema_file_path, - backend, - range_values, - ): - # This is for temporary PEATAC testing for determining summarize function - with TemporaryDirectory() as d, ContextManagerDBTesting(DB_URL): - temp_dir = d - # single_results_file_path = "{record_identifier}/results.yaml" - # results_file_path = os.path.join(temp_dir, single_results_file_path) - # args = dict(schema_path=recursive_schema_file_path, database_only=False) - # n = 3 - config_file_path = "/home/drc/pepatac_tutorial/processed/looper_pipestat_config.yaml" - - # for i in range_values[:n]: - # r_id = i[0] - # val = i[1] - # backend_data = {"record_identifier": r_id, "results_file_path": results_file_path} - # args.update(backend_data) - # psm = SamplePipestatManager(**args) - # psm.report(record_identifier=r_id, values=val, force_overwrite=True) - psm = PipestatManager(config_file=config_file_path) - reportlink = psm.summarize() - print(reportlink) - statstsv = psm.table() - print(statstsv) - # data = YAMLConfigManager(filepath=os.path.join(temp_dir, "aggregate_results.yaml")) - # assert r_id in data[psm.pipeline_name][psm.pipeline_type].keys() From 66cdc2f9ed321f374d36858d2b2344ed2db879b5 Mon Sep 17 00:00:00 2001 From: Donald Campbell <125581724+donaldcampbelljr@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:23:43 -0400 Subject: [PATCH 07/10] lint --- tests/test_pipestat.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_pipestat.py b/tests/test_pipestat.py index 7e5f08fe..1015e418 100644 --- a/tests/test_pipestat.py +++ b/tests/test_pipestat.py @@ -2514,4 +2514,3 @@ def test_select_history_complex_objects( assert len(history_result.keys()) == 1 assert "output_image" in history_result assert len(history_result["output_image"].keys()) == 2 - From 1dc6fa0857a23f21b41b2627db4c3cfd03554c56 Mon Sep 17 00:00:00 2001 From: Donald Campbell <125581724+donaldcampbelljr@users.noreply.github.com> Date: Wed, 24 Apr 2024 16:28:17 -0400 Subject: [PATCH 08/10] comment out unused area of html template --- pipestat/jinja_templates/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipestat/jinja_templates/index.html b/pipestat/jinja_templates/index.html index d9431a29..93fab95a 100644 --- a/pipestat/jinja_templates/index.html +++ b/pipestat/jinja_templates/index.html @@ -199,7 +199,7 @@ - +