- Notifications
You must be signed in to change notification settings - Fork 236
/
Copy pathtest_engine.py
executable file
·53 lines (44 loc) · 1.54 KB
/
test_engine.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
#!/usr/bin/env python3
# Copyright 2019 Mycroft AI Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
importsys
importglob
importre
fromos.pathimportjoin
fromprecise.scripts.engineimportEngineScript
fromrunner.precise_runnerimportReadWriteStream
classFakeStdin:
def__init__(self, data: bytes):
self.buffer=ReadWriteStream(data)
defisatty(self):
returnFalse
classFakeStdout:
def__init__(self):
self.buffer=ReadWriteStream()
deftest_engine(train_folder, train_script):
"""
Test t hat the output format of the engina matches a decimal form in the
range 0.0 - 1.0.
"""
train_script.run()
withopen(glob.glob(join(train_folder.root, 'wake-word', '*.wav'))[0], 'rb') asf:
data=f.read()
try:
sys.stdin=FakeStdin(data)
sys.stdout=FakeStdout()
EngineScript.create(model_name=train_folder.model).run()
assertre.match(rb'[01]\.[0-9]+', sys.stdout.buffer.buffer)
finally:
sys.stdin=sys.__stdin__
sys.stdout=sys.__stdout__