-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_names.py
79 lines (56 loc) · 2.42 KB
/
test_names.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
"""Test the monitors module."""
import pytest
from names import Names
@pytest.fixture
def new_empty_names():
"""Return a Names class instance."""
return Names()
@pytest.fixture
def new_names():
"""Return a Names class instance and initialises names."""
names = Names()
names.names_list = ['Sw1', 'Sw2']
return names
def test_unique_error_codes(new_empty_names):
"""Test if unique_error_codes returns list of unique integer codes."""
num_error_codes = 10
codes = new_empty_names.unique_error_codes(num_error_codes)
assert new_empty_names.error_code_count == num_error_codes
assert codes == range(0, num_error_codes)
def test_unique_error_codes_gives_errors(new_empty_names):
"""Test if test_unique_error_codes raises correct errors."""
num_error_codes = 4.44
with pytest.raises(TypeError):
new_empty_names.unique_error_codes(num_error_codes)
def test_query(new_names):
"""Test if query returns correct name ID for name_string."""
assert new_names.query('Sw1') == 0
assert new_names.query('Sw2') == 1
assert new_names.query('yoohoo') is None
def test_lookup(new_names):
"""Test if lookup returns correct name IDs for present and new names."""
# Test look up returns correct name ids for current names
assert new_names.lookup(['Sw1', 'Sw2']) == [0, 1]
# Test look up returns correct name ids for new names
assert new_names.lookup(['Sw3', 'Sw4']) == [2, 3]
# Test look up returns correct name ids for newly added names
assert new_names.lookup(['Sw4', 'Sw1']) == [3, 0]
# Test look up returns correct name ids for new and present names
assert new_names.lookup(['Sw5', 'Sw3']) == [4, 2]
def test_lookup_gives_errors(new_names):
"""Test if lookup returns correct errors for invalid name_string."""
invalid_name_string = ["yoohoo", 4.44]
with pytest.raises(TypeError):
new_names.lookup(invalid_name_string)
def test_get_name_string(new_names):
"""Test if get_name_string returns correct name."""
assert new_names.get_name_string(0) == 'Sw1'
assert new_names.get_name_string(1) == 'Sw2'
def test_get_name_string_gives_errors(new_names):
"""Test if get_name_string raises correct errors."""
with pytest.raises(TypeError):
new_names.get_name_string("yoohoo")
with pytest.raises(ValueError):
new_names.get_name_string(-1)
with pytest.raises(ValueError):
new_names.get_name_string(5)