forked from bootphon/phonemizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_separator.py
82 lines (62 loc) · 2.6 KB
/
test_separator.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
# Copyright 2015-2021 Thomas Schatz, Xuan Nga Cao, Mathieu Bernard
#
# This file is part of phonemizer: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Phonemizer is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with phonemizer. If not, see <http://www.gnu.org/licenses/>.
"""Test of the Separator class"""
# pylint: disable=missing-docstring
import pytest
from phonemizer.separator import Separator, default_separator
def test_prop():
# read only attributes
with pytest.raises(AttributeError):
default_separator.phone = 'a'
with pytest.raises(AttributeError):
default_separator.syllable = 'a'
with pytest.raises(AttributeError):
default_separator.word = 'a'
@pytest.mark.parametrize('val', [None, '', False])
def test_empty(val):
s = Separator(val, val, val)
assert s.phone == ''
assert s.syllable == ''
assert s.word == ''
def test_same():
with pytest.raises(ValueError):
Separator(word=' ', phone=' ')
def test_str():
separator = Separator(word='w', syllable='s', phone='p')
assert str(separator) == '(phone: "p", syllable: "s", word: "w")'
assert str(default_separator) == '(phone: "", syllable: "", word: " ")'
def test_equal():
assert Separator() == Separator()
assert default_separator == Separator(phone='', syllable='', word=' ')
assert Separator(word=' ') != default_separator
def test_field_separator():
sep = Separator(word='w', syllable='s', phone='p')
assert 'w' in sep
assert 'p' in sep
assert 'wp' not in sep
assert ' ' not in sep
assert sep.input_output_separator(False) is False
assert sep.input_output_separator(None) is False
assert sep.input_output_separator('') is False
assert sep.input_output_separator(True) == '|'
assert sep.input_output_separator('io') == 'io'
with pytest.raises(RuntimeError) as err:
sep.input_output_separator([1, 2])
assert 'invalid input/output separator' in str(err)
with pytest.raises(RuntimeError) as err:
sep.input_output_separator('w')
assert 'cannot prepend input with "w"' in str(err)
sep = Separator(phone='|', syllable='||', word='|||')
assert sep.input_output_separator(True) == '||||'