Skip to content
Closed
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
25 changes: 25 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Run pytest

on:
push:
branches: [main, dev]
pull_request:
branches: [main, dev]
types: ["opened", "reopened", "synchronize", "ready_for_review", "draft"]
workflow_dispatch:

jobs:
build:
name: Run pytest
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v5
- name: Install uv
uses: astral-sh/setup-uv@v7

- name: Install dependencies
run: uv sync --locked --all-extras --dev

- name: Run the tests
run: uv run pytest tests
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies = [
"pika>=1.3.2",
"pre-commit>=4.5.0",
"psycopg2-binary>=2.9.11",
"pytest>=9.0.2",
]

[project.scripts]
Expand Down
Empty file added tests/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions tests/test_file_writer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pytest
from waveform_controller.csv_writer import create_file_name
from datetime import datetime, timezone


@pytest.mark.parametrize(
"units, expected_filename",
[
("uV", "2025-01-01.12345678.11.uV.csv"),
("mL/s", "2025-01-01.12345678.11.mLps.csv"),
("%", "2025-01-01.12345678.11.percent.csv"),
],
)
def test_create_file_name_handles_units(units, expected_filename, tmp_path):
sourceSystem = "11"
observationTime = datetime(2025, 1, 1, tzinfo=timezone.utc)
csn = "12345678"

filename = create_file_name(sourceSystem, observationTime, csn, units)

assert filename == expected_filename

# check we can write to it
with open(f"{tmp_path}/{filename}", "w") as fileout:
fileout.write("Test string")
63 changes: 63 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions waveform_controller/csv_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def create_file_name(
"""Create a unique file name based on the patient contact serial number
(csn) the date, and the source system."""
datestring = observationTime.strftime("%Y-%m-%d")
units = units.replace("/", "p")
units = units.replace("%", "percent")
return f"{datestring}.{csn}.{sourceSystem}.{units}.csv"


Expand Down