Skip to content
Merged
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
40 changes: 31 additions & 9 deletions tests/test_file_writer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import os

import pytest
from src.csv_writer import create_file_name

from src import csv_writer
from datetime import datetime, timezone
import locations


@pytest.mark.parametrize(
Expand All @@ -13,15 +17,33 @@
],
)
def test_create_file_name_handles_units(
units, variable_id, channel_id, expected_filename, tmp_path
monkeypatch, units, variable_id, channel_id, expected_filename, tmp_path
):
observationTime = datetime(2025, 1, 1, 10, 10, 10, tzinfo=timezone.utc)
csn = "12345678"
# treat the normal absolute path as if it were a relative path, so we can put
# a prefix on it (this code is usually run in a container)
original_csv_dir = tmp_path / locations.WAVEFORM_ORIGINAL_CSV.relative_to("/")
monkeypatch.setattr(csv_writer, "WAVEFORM_ORIGINAL_CSV", original_csv_dir)
monkeypatch.setattr(locations, "WAVEFORM_ORIGINAL_CSV", original_csv_dir)

filename = create_file_name(variable_id, channel_id, observationTime, csn, units)
# the only precondition is that the base dir must exist
original_csv_dir.parent.mkdir(parents=True, exist_ok=True)

observation_time = datetime(2025, 1, 1, 10, 10, 10, tzinfo=timezone.utc)
csn = "12345678"
mrn = "whatever"

assert filename == expected_filename
csv_writer.write_frame(
{"value": "[1,2,3]"},
variable_id,
channel_id,
observation_time.timestamp(),
units,
50,
"mapped loc",
csn,
mrn,
)

# check we can write to it
with open(f"{tmp_path}/{filename}", "w") as fileout:
fileout.write("Test string")
# check that we can find the data again in its expected place
expected_csv_path = locations.WAVEFORM_ORIGINAL_CSV / expected_filename
assert os.path.exists(expected_csv_path)