From 2571a7b7dcc54b77e569eb9d1c742d6d405b4803 Mon Sep 17 00:00:00 2001 From: Jeremy Stein Date: Thu, 5 Feb 2026 14:55:53 +0000 Subject: [PATCH] Broaden test so that it writes the CSV file out --- tests/test_file_writer.py | 40 ++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/tests/test_file_writer.py b/tests/test_file_writer.py index 6b5b923..484b8fb 100644 --- a/tests/test_file_writer.py +++ b/tests/test_file_writer.py @@ -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( @@ -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)