-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtests.py
81 lines (55 loc) · 2.39 KB
/
tests.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
# pylint: disable=W0613
import numpy as np
import pandas as pd
from src.feature import _calc_cqt, _calc_stft, _extract_label, calc_cqt, calc_stft
class Test_calcStft:
"""Test for `_calc_stft`"""
def test_shape(self, mocker):
def _dummy_librosa_load(path):
return ([x for x in range(100000)], 16000)
mocker.patch("librosa.load", _dummy_librosa_load)
assert len(_calc_stft("dummy_path.flac").shape) == 3
def test_is_ndarray(self, mocker):
def _dummy_librosa_load(path):
return ([x for x in range(100000)], 16000)
mocker.patch("librosa.load", _dummy_librosa_load)
assert type(_calc_stft("dummy_path.flac")) == np.ndarray
class TestCalcStft:
"""Test for `calc_stft`"""
def test_shape(self, mocker):
dummy = {
"protocol_df": pd.DataFrame({"utt_id": ["dummy-1", "dummy-2"]}),
"path": "dummy_path",
}
mocker.patch("src.feature._calc_stft", lambda x: np.random.randn(100, 100, 1))
mocker.patch("src.feature._extract_label", lambda x: np.random.randint(0, 2, 2))
data, _ = calc_stft(**dummy)
assert len(data.shape) == 4
class Test_calcCqt:
"""Test for `_calc_cqt`"""
def test_shape(self, mocker):
def _dummy_librosa_load(path):
return ([x for x in range(100000)], 16000)
mocker.patch("librosa.load", _dummy_librosa_load)
assert len(_calc_cqt("dummy_path.flac").shape) == 2
def test_is_ndarray(self, mocker):
def _dummy_librosa_load(path):
return ([x for x in range(100000)], 16000)
mocker.patch("librosa.load", _dummy_librosa_load)
assert type(_calc_cqt("dummy_path.flac")) == np.ndarray
class TestCalcCqt:
"""Test for `calc_cqt`"""
def test_shape(self, mocker):
dummy = {
"protocol_df": pd.DataFrame({"utt_id": ["dummy-1", "dummy-2"]}),
"path": "dummy_path",
}
mocker.patch("src.feature._calc_cqt", lambda x: np.random.randn(100, 100))
mocker.patch("src.feature._extract_label", lambda x: np.random.randint(0, 2, 2))
data, _ = calc_cqt(**dummy)
assert len(data.shape) == 4
class TestExtractsLabel:
"""Test for `_extract_label`"""
def test_dtype_is_int(self):
dummy = pd.DataFrame({"key": ["bonafide", "spoof", "bonafide"]})
assert _extract_label(dummy).dtype == np.dtype("int")