diff --git a/src/reflecto_exp/io_utils.py b/src/reflecto_exp/io_utils.py index 3f3900d..4cdc9a7 100644 --- a/src/reflecto_exp/io_utils.py +++ b/src/reflecto_exp/io_utils.py @@ -12,7 +12,7 @@ def append_timestamp(path: Path | str) -> Path: The exact naming format is not fixed. """ path = Path(path) - new_name = f"{path.name}_{datetime.now():%Y%m%d_%H%M%S}" + new_name = f"{path.stem}_{datetime.now():%Y%m%d_%H%M%S}" if path.suffix: return path.parent / (new_name + path.suffix) diff --git a/tests/test_utils.py b/tests/test_utils.py index 035a86c..f57e869 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,3 +1,4 @@ +import re import warnings import numpy as np @@ -51,13 +52,13 @@ def test_next_unique_file_numbers_after_the_highest_existing(tmp_path): assert next_unique_file(base) == tmp_path / "out(5).txt" -def test_append_timestamp_keeps_the_suffix(tmp_path): +def test_append_timestamp_puts_the_time_before_the_extension(tmp_path): with_suffix = append_timestamp(tmp_path / "scan.dat") - assert with_suffix.parent == tmp_path and with_suffix.suffix == ".dat" - assert with_suffix != tmp_path / "scan.dat" + assert with_suffix.parent == tmp_path + assert re.fullmatch(r"scan_\d{8}_\d{6}\.dat", with_suffix.name), with_suffix.name no_suffix = append_timestamp(tmp_path / "scan") - assert no_suffix.parent == tmp_path and no_suffix.suffix == "" - assert no_suffix.name.startswith("scan_") + assert no_suffix.parent == tmp_path + assert re.fullmatch(r"scan_\d{8}_\d{6}", no_suffix.name), no_suffix.name def test_load_xrr_dat_skips_comments_reads_scientific_notation_and_zeros_garbage(tmp_path):