Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/reflecto_exp/io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import warnings

import numpy as np
Expand Down Expand Up @@ -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):
Expand Down
Loading