Skip to content

Commit

Permalink
tests for sampler periodic
Browse files Browse the repository at this point in the history
  • Loading branch information
LoannPeurey committed Nov 14, 2024
1 parent cb3573f commit 491b9c9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
28 changes: 18 additions & 10 deletions tests/test_samplers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest
import shutil
from functools import partial
from pathlib import Path

from ChildProject.projects import ChildProject
from ChildProject.annotations import AnnotationManager
Expand All @@ -15,32 +16,39 @@
SamplerPipeline,
)

TRUTH = Path('tests', 'truth')
PATH = Path('output', 'samplers')

def fake_conversation(data, filename):
return data


@pytest.fixture(scope="function")
def project(request):
if not os.path.exists("output/samplers"):
shutil.copytree(src="examples/valid_raw_data", dst="output/samplers")
if os.path.exists(PATH):
# shutil.copytree(src="examples/valid_raw_data", dst="output/annotations")
shutil.rmtree(PATH)
shutil.copytree(src="examples/valid_raw_data", dst=PATH)

project = ChildProject("output/samplers")
project = ChildProject(PATH)
project.read()
yield project

yield project

def test_periodic(project):
@pytest.mark.parametrize("by,truth",
[('recording_filename', TRUTH / 'sampler' / 'periodic_rec.csv'),
('session_id', TRUTH / 'sampler' / 'periodic_sess.csv'),
])
def test_periodic(project, by, truth):
sampler = PeriodicSampler(
project=project, length=1000, period=1000, recordings=["sound.wav"]
project=project, offset=1000, length=500, period=200, recordings=["sound.wav",'sound2.wav'], by=by
)
sampler.sample()

duration = project.recordings[
project.recordings["recording_filename"] == "sound.wav"
]["duration"].iloc[0]
# sampler.segments.to_csv(truth, index=False)
truth = pd.read_csv(truth)

assert len(sampler.segments) == int(duration / (1000 + 1000))
pd.testing.assert_frame_equal(sampler.segments.reset_index(drop=True), truth, check_like=True)


def test_energy_detection(project):
Expand Down
11 changes: 11 additions & 0 deletions tests/truth/sampler/periodic_rec.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
segment_onset,segment_offset,recording_filename
1000,1500,sound.wav
1700,2200,sound.wav
2400,2900,sound.wav
3100,3600,sound.wav
3800,4000,sound.wav
1000,1500,sound2.wav
1700,2200,sound2.wav
2400,2900,sound2.wav
3100,3600,sound2.wav
3800,4000,sound2.wav
12 changes: 12 additions & 0 deletions tests/truth/sampler/periodic_sess.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
segment_onset,segment_offset,recording_filename
1000,1500,sound.wav
1700,2200,sound.wav
2400,2900,sound.wav
3100,3600,sound.wav
3800,4000,sound.wav
0,400,sound2.wav
600,1100,sound2.wav
1300,1800,sound2.wav
2000,2500,sound2.wav
2700,3200,sound2.wav
3400,3900,sound2.wav

0 comments on commit 491b9c9

Please sign in to comment.