-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_utils.py
executable file
·72 lines (50 loc) · 1.86 KB
/
test_utils.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
"""Test of the wordseg.utils module"""
import pytest
import wordseg.utils
# CountingIterator
@pytest.mark.parametrize('sequence', [
range(1, 11),
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
(c for c in range(1, 11)),
{c: str(c) for c in range(1, 11)}])
def test_counting_iterator_int(sequence):
counter = wordseg.utils.CountingIterator(sequence)
assert sum(counter) == 55
assert counter.count == 10
def test_counting_iterator_str():
counter = wordseg.utils.CountingIterator('sequence')
assert counter.count == 0
for c in counter:
pass
assert counter.count == 8
@pytest.mark.parametrize('not_sequence', [1, None])
def test_counting_iterator_bad(not_sequence):
with pytest.raises(TypeError):
wordseg.utils.CountingIterator(not_sequence)
# get_binary
@pytest.mark.parametrize('binary', ['ag', 'dpseg'])
def test_get_binary_good(binary):
# raise RuntimeError on error
wordseg.utils.get_binary(binary)
@pytest.mark.parametrize('binary', ['AG', 'Dpseg', 'puddle'])
def test_get_binary_bad(binary):
with pytest.raises(RuntimeError):
wordseg.utils.get_binary(binary)
# get_config_files
@pytest.mark.parametrize('binary', ['ag', 'dpseg'])
def test_get_config_file_good(binary):
# raise RuntimeError on error
wordseg.utils.get_config_files(binary)
@pytest.mark.parametrize('binary', ['puddle', 'tp', 'dibs'])
def test_get_config_file_bad(binary):
with pytest.raises(RuntimeError):
wordseg.utils.get_config_files(binary)
# strip
@pytest.mark.parametrize('string', [' ab c ', 'ab\nc', ' \t\tab\n c '])
def test_strip_abc(string):
assert wordseg.utils.strip(string) == 'ab c'
def test_strip_misc():
assert wordseg.utils.strip(' ') == ''
assert wordseg.utils.strip('\na\ta \t\naa a\n ') == 'a a aa a'
assert wordseg.utils.strip('a a \n') == 'a a'