Skip to content

Commit

Permalink
fix #211 spaces in html files
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldcampbelljr committed Dec 27, 2024
1 parent 4f1f7b0 commit b87b9e3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pipestat/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def create_object_parent_html(self, navbar, footer):
else ""
)
labels.append(f"<b>{key.replace('_', ' ')}</b>: {desc}")
page_path = os.path.join(self.pipeline_reports, f"{key}.html".lower())
page_path = os.path.join(self.pipeline_reports, f"{key}.html".replace(" ", "_").lower())
pages.append(os.path.relpath(page_path, self.pipeline_reports))

template_vars = dict(
Expand Down Expand Up @@ -364,7 +364,7 @@ def create_object_htmls(self, navbar, footer):
os.makedirs(self.pipeline_reports)
for file_result in file_results:
links = []
html_page_path = os.path.join(self.pipeline_reports, f"{file_result}.html".lower())
html_page_path = os.path.join(self.pipeline_reports, f"{file_result}.html".replace(" ", "_").lower())

pipeline_types = ["sample", "project"]

Expand Down Expand Up @@ -511,8 +511,7 @@ def create_sample_html(self, sample_stats, navbar, footer, sample_name):
"""
if not os.path.exists(self.pipeline_reports):
os.makedirs(self.pipeline_reports)
html_page = os.path.join(self.pipeline_reports, f"{sample_name}.html".lower())

html_page = os.path.join(self.pipeline_reports, f"{sample_name}.html".replace(" ", "_").lower())
if self.prj.cfg["multi_result_files"] is True:
self.prj.cfg["record_identifier"] = sample_name
temp_result_file_path = mkabs(
Expand Down Expand Up @@ -978,7 +977,7 @@ def _get_navbar_dropdown_data_objects(self, objs, wd, context):
for obj_id in objs:
displayable_ids.append(obj_id.replace("_", " "))
page_name = os.path.join(
self.pipeline_reports, (obj_id + ".html").replace(" ", "%20").lower()
self.pipeline_reports, (obj_id + ".html").replace(" ", "_").lower()
)
relpaths.append(_make_relpath(page_name, wd, context))
return relpaths, displayable_ids
Expand All @@ -997,7 +996,7 @@ def _get_navbar_dropdown_data_samples(self, wd, context):
sample_name = sample["record_identifier"]
page_name = os.path.join(
self.pipeline_reports,
f"{sample_name}.html".replace(" ", "%20").lower(),
f"{sample_name}.html".replace(" ", "_").lower(),
)
relpaths.append(_make_relpath(page_name, wd, context))
sample_names.append(sample_name)
Expand Down
3 changes: 3 additions & 0 deletions tests/data/output_schema_html_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ properties:
switch_value:
type: boolean
description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras pharetra."
output file with spaces:
$ref: "#/$defs/file"
description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce nec cursus nulla."
samples:
type: array
items:
Expand Down
48 changes: 48 additions & 0 deletions tests/test_pipestat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,54 @@ def test_zip_html_report_portable(

assert len(zip_files) > 0

@pytest.mark.parametrize("backend", ["file", "db"])
def test_report_spaces_in_record_identifiers(
self,
config_file_path,
output_schema_html_report,
results_file_path,
backend,
values_project,
):
with NamedTemporaryFile() as f, ContextManagerDBTesting(DB_URL):
results_file_path = f.name
args = dict(schema_path=output_schema_html_report, database_only=False)
backend_data = (
{"config_file": config_file_path}
if backend == "db"
else {"results_file_path": results_file_path}
)
args.update(backend_data)
# project level
psm = ProjectPipestatManager(**args)

for i in values_project:
for r, v in i.items():
psm.report(
record_identifier=r,
values=v,
force_overwrite=True,
)
psm.set_status(record_identifier=r, status_identifier="running")

# Add record with sspace in name
r = "SAMPLE Three WITH SPACES"
psm.report( record_identifier=r,
values={'name_of_something': 'name of something string'},
force_overwrite=True,)
psm.set_status(record_identifier=r, status_identifier="completed")
r = "SAMPLE FOUR WITH Spaces"
psm.report( record_identifier=r,
values={'output file with spaces': {"path":"here is path", "title":"here is a title"}},
force_overwrite=True,)

htmlreportpath = psm.summarize(amendment="")

directory_path = os.path.dirname(htmlreportpath)
all_files = os.listdir(directory_path)

assert "sample_three_with_spaces.html" in all_files
assert "output_file_with_spaces.html" in all_files

@pytest.mark.skipif(not DB_DEPENDENCIES, reason="Requires dependencies")
@pytest.mark.skipif(SERVICE_UNAVAILABLE, reason="requires service X to be available")
Expand Down

0 comments on commit b87b9e3

Please sign in to comment.