Skip to content

Commit

Permalink
Add workflow integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
maestroque committed Aug 26, 2024
1 parent 1d27cae commit e053e1d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
2 changes: 1 addition & 1 deletion phys2denoise/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from _pytest.logging import LogCaptureFixture
from loguru import logger
from physutils import Physio
from physutils import Physio, io

import phys2denoise.tasks as tasks

Expand Down
Binary file added phys2denoise/tests/data/fake_phys.phys
Binary file not shown.
1 change: 0 additions & 1 deletion phys2denoise/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ def test_export_metrics(fake_physio_with_metrics):

# Check if the output directory was created
assert os.path.exists(outdir)
assert task.result().output.out is None

# Check if the files were created
assert os.path.exists(
Expand Down
19 changes: 15 additions & 4 deletions phys2denoise/tests/test_tasks_integration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for phys2denoise.tasks and their integration."""
import logging
import os

import nest_asyncio
Expand All @@ -10,23 +11,33 @@

import phys2denoise.tasks as tasks

from .utils import create_fake_phys

nest_asyncio.apply()

LGR = logging.getLogger(__name__)
LGR.setLevel(logging.DEBUG)


def test_integration(fake_phys):
"""Test the integration of phys2denoise tasks."""
file_dir = os.path.dirname(os.path.abspath(__file__))
export_dir = os.path.join(file_dir, "test_output_data/integration")
create_fake_phys()

physio_file = os.path.abspath("phys2denoise/tests/data/fake_phys.phys")

wf = Workflow(
name="metrics_wf",
input_spec=["phys", "fs"],
phys="phys2denoise/tests/data/ECG.csv",
fs=62.5,
phys=physio_file,
)
wf.add(
transform_to_physio(
name="transform_to_physio", phys=wf.lzin.phys, fs=wf.lzin.fs, mode="physio"
name="transform_to_physio",
input_file=wf.lzin.phys,
fs=wf.lzin.fs,
mode="physio",
)
)
wf.add(
Expand Down Expand Up @@ -60,6 +71,6 @@ def test_integration(fake_phys):

with Submitter(plugin="cf") as sub:
sub(wf)
wf().result()
wf()

assert os.path.exists(export_dir)
36 changes: 36 additions & 0 deletions phys2denoise/tests/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import logging
import os

import numpy as np
import peakdet
from physutils import Physio, io

LGR = logging.getLogger(__name__)
LGR.setLevel(logging.DEBUG)


def create_fake_phys():
f = 0.3
fs = 62.5 # sampling rate
t = 300
samples = np.arange(t * fs) / fs
noise = np.random.normal(0, 0.5, len(samples))
fake_phys = 10 * np.sin(2 * np.pi * f * samples) + noise

phys = peakdet.Physio(fake_phys, fs=62.5)
phys = peakdet.operations.filter_physio(phys, cutoffs=3, method="lowpass")
phys = peakdet.operations.peakfind_physio(phys)

# TODO: Change to a simpler call once physutils are
# integrated to peakdet/prep4phys
physio_obj = Physio(phys.data, phys.fs)
physio_obj._metadata["peaks"] = phys.peaks
physio_obj._metadata["troughs"] = phys.troughs

LGR.debug(f"Current working directory: {os.getcwd()}")
save_path = os.path.abspath("phys2denoise/tests/data/fake_phys.phys")
LGR.info(f"save_path: {save_path}")

io.save_physio(save_path, physio_obj)

return physio_obj

0 comments on commit e053e1d

Please sign in to comment.