Skip to content

Commit 88dc92e

Browse files
authored
Merge pull request #139 from MycroftAI/bugfix/unittests
Make Unittests runnable
2 parents db4e3f5 + 6345c50 commit 88dc92e

File tree

11 files changed

+72
-11
lines changed

11 files changed

+72
-11
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include precise/data/activate.wav
File renamed without changes.

precise/util.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ def play_audio(filename: str):
8080

8181
def activate_notify():
8282
audio = 'data/activate.wav'
83-
audio = abspath(dirname(abspath(__file__)) + '/../' + audio)
84-
83+
audio = join(dirname(abspath(__file__)), audio)
8584
play_audio(audio)
8685

8786

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@
6969
'precise-calc-threshold=precise.scripts.calc_threshold:main',
7070
]
7171
},
72+
include_package_data=True,
7273
install_requires=[
73-
'numpy',
74+
'numpy==1.16',
7475
'tensorflow>=1.13,<1.14', # Must be on piwheels
7576
'sonopy',
7677
'pyaudio',

test/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:3.7-slim
2+
ENV TERM linux
3+
ENV DEBIAN_FRONTEND noninteractive
4+
RUN apt-get update && apt-get -y install git python3-scipy cython libhdf5-dev python3-h5py portaudio19-dev swig libpulse-dev libatlas-base-dev
5+
ADD . mycroft-precise
6+
WORKDIR mycroft-precise
7+
RUN pip install .
8+
RUN pip install pytest
9+
ENV PYTHONPATH /mycroft-precise
10+
ENTRYPOINT ["pytest"]

test/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2019 Mycroft AI Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.

test/scripts/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2019 Mycroft AI Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.

test/scripts/dummy_audio_folder.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,14 @@ def rand(self, min, max):
3535
return min + (max - min) * np.random.random() * pr.buffer_t
3636

3737
def generate_samples(self, folder, name, value, duration):
38+
"""Generate sample file.
39+
40+
The file is generated in the specified folder, with the specified name,
41+
dummy value and duration.
42+
"""
3843
for i in range(self.count):
39-
save_audio(join(folder, name.format(i)), np.array([value] * int(duration * pr.sample_rate)))
44+
save_audio(join(folder, name.format(i)),
45+
np.array([value] * int(duration * pr.sample_rate)))
4046

4147
def subdir(self, *parts):
4248
folder = self.path(*parts)

test/scripts/test_combined.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,27 @@ def read_content(filename):
2626

2727

2828
def test_combined(train_folder, train_script):
29+
"""Test a "normal" development cycle, train, evaluate and calc threshold.
30+
"""
2931
train_script.run()
3032
params_file = train_folder.model + '.params'
3133
assert isfile(train_folder.model)
3234
assert isfile(params_file)
3335

34-
EvalScript.create(folder=train_folder.root, models=[train_folder.model]).run()
36+
EvalScript.create(folder=train_folder.root,
37+
models=[train_folder.model]).run()
3538

39+
# Ensure that the graph script generates a numpy savez file
3640
out_file = train_folder.path('outputs.npz')
37-
graph_script = GraphScript.create(folder=train_folder.root, models=[train_folder.model], output_file=out_file)
41+
graph_script = GraphScript.create(folder=train_folder.root,
42+
models=[train_folder.model],
43+
output_file=out_file)
3844
graph_script.run()
3945
assert isfile(out_file)
4046

47+
# Esure the params are updated after threshold is calculated
4148
params_before = read_content(params_file)
42-
CalcThresholdScript.create(folder=train_folder.root, model=train_folder.model, input_file=out_file).run()
49+
CalcThresholdScript.create(folder=train_folder.root,
50+
model=train_folder.model,
51+
input_file=out_file).run()
4352
assert params_before != read_content(params_file)

test/scripts/test_engine.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ def __init__(self):
3636

3737

3838
def test_engine(train_folder, train_script):
39+
"""
40+
Test t hat the output format of the engina matches a decimal form in the
41+
range 0.0 - 1.0.
42+
"""
3943
train_script.run()
4044
with open(glob.glob(join(train_folder.root, 'wake-word', '*.wav'))[0], 'rb') as f:
4145
data = f.read()

0 commit comments

Comments
 (0)