-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.py
66 lines (56 loc) · 2.42 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
"""Tests for the more important routines in this work"""
# -*- coding: utf-8 -*-
# Copyright 2020 Atli Thor Sigurgeirsson <atlithors@ru.is>
#
# 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.
import unittest
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from conf import ROOT_DIR
from sequitur_tools import g2p_file
from prondata import PronData
TEST_DIR = ROOT_DIR / 'tests'
OUTPUT_DIR = TEST_DIR / 'output'
os.makedirs(OUTPUT_DIR, exist_ok=True)
class G2PTest(unittest.TestCase):
"""
Test the Sequitur G2P model agains a precomputed list
"""
def test(self):
"""Predict transcription and compare to precomputed transcription"""
print(f"Testing G2P, see {OUTPUT_DIR} for results")
g2p_file(
TEST_DIR / 'unscored_list_without_pron.txt',
OUTPUT_DIR / 'unscored_list_with_pron.txt')
with open(OUTPUT_DIR / 'unscored_list_with_pron.txt', 'r') as generated,\
open(TEST_DIR / 'unscored_list.txt', 'r') as truth:
generated_lines, truth_lines = generated.readlines(), truth.readlines()
for i, line in enumerate(generated_lines):
self.assertEqual(line, truth_lines[i])
class ScoreTest(unittest.TestCase):
"""
Test the greedy scoring method in prondata.PronData
"""
def test(self):
"""Compute scores and compare to real scores"""
print(f"Testing greedy score, see {OUTPUT_DIR} for results")
dataset = PronData(TEST_DIR / 'unscored_list.txt')
dataset.score(OUTPUT_DIR / 'scored_list.txt')
with open(OUTPUT_DIR / 'scored_list.txt', 'r') as generated,\
open(TEST_DIR / 'scored_list.txt', 'r') as truth:
generated_lines, truth_lines = generated.readlines(), truth.readlines()
for i, line in enumerate(generated_lines):
self.assertEqual(line, truth_lines[i])
if __name__ == '__main__':
unittest.main()