-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_convert.py
122 lines (104 loc) · 3.5 KB
/
test_convert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
from ChildProject.projects import ChildProject, CONVERTED_RECORDINGS
from ChildProject.pipelines.processors import AudioProcessingPipeline
import numpy as np
import os
import pandas as pd
import pytest
import shutil
from pathlib import Path
PATH = Path('output', 'process')
@pytest.fixture(scope="function")
def project(request):
if os.path.exists(PATH):
shutil.rmtree(PATH)
shutil.copytree(src="examples/valid_raw_data", dst=PATH)
project = ChildProject(PATH)
project.read()
yield project
def test_basic(project):
processed, parameters = AudioProcessingPipeline().run(
processor="basic",
path=project.path,
name="test",
format="wav",
codec="pcm_s16le",
sampling=16000,
)
recordings = project.recordings
converted_recordings = pd.read_csv(processed)
assert np.isclose(
8000, project.compute_recordings_duration()["duration"].sum()
), "audio duration equals expected value"
assert os.path.exists(
os.path.join(project.path, CONVERTED_RECORDINGS, "test")
), "missing processed recordings folder"
assert (
recordings.shape[0] == converted_recordings.shape[0]
), "conversion table is incomplete"
assert all(
converted_recordings["success"].tolist()
), "not all recordings were successfully processed"
assert all(
[
os.path.exists(
os.path.join(project.path, CONVERTED_RECORDINGS, "test", f)
)
for f in converted_recordings["converted_filename"].tolist()
]
), "recording files are missing"
def test_standard(project):
# Starting the audio processing pipeline using the default settings
processed, parameters = AudioProcessingPipeline().run(
processor="standard",
path=project.path,
)
recordings = project.recordings
converted_recordings = pd.read_csv(processed)
assert np.isclose(
8000, project.compute_recordings_duration()["duration"].sum()
), "audio duration equals expected value"
assert os.path.exists(
os.path.join(project.path, CONVERTED_RECORDINGS, "standard")
), "missing processed recordings folder"
assert (
recordings.shape[0] == converted_recordings.shape[0]
), "conversion table is incomplete"
assert all(
converted_recordings["success"].tolist()
), "not all recordings were successfully processed"
assert all(
[
os.path.exists(
os.path.join(project.path, CONVERTED_RECORDINGS, "standard", f)
)
for f in converted_recordings["converted_filename"].tolist()
]
), "recording files are missing"
def test_vetting(project):
pd.DataFrame(
[
{
"recording_filename": "sound.wav",
"segment_onset": 1000,
"segment_offset": 3000,
}
]
).to_csv(os.path.join(project.path, "segments.csv"))
AudioProcessingPipeline().run(
processor="vetting",
path=project.path,
name="vetted",
segments_path=os.path.join(project.path, "segments.csv"),
)
def test_channel_mapping(project, input=None):
AudioProcessingPipeline().run(
processor="channel-mapping",
path=project.path,
name="mapping",
channels=["0,2", "1,0"],
input_profile=input,
recordings=["sound.wav"],
)
def test_custom_input_profile(project):
test_vetting(project)
test_channel_mapping(project, input="vetted")