-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathstartlist_test.py
232 lines (211 loc) · 8.52 KB
/
startlist_test.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# Wahoo! Results - https://github.com/JohnStrunk/wahoo-results
# Copyright (C) 2022 - John D. Strunk
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Tests for StartList class"""
import io
import textwrap
import pytest
from startlist import CTSStartList, StartList
def test_startlist():
"""Instantiating a bare StartList generates an empty start list"""
slist = StartList()
assert slist.event_name == ""
assert slist.event_num == 0
assert slist.heats == 0
assert slist.name(1, 2) == ""
assert slist.team(1, 2) == ""
assert slist.is_empty_lane(7, 4)
def test_two_heats():
"""General test on 2 heats worth of data"""
slist = CTSStartList(
io.StringIO(
textwrap.dedent(
"""\
#18 BOYS 10&U 50 FLY
--
--
--
PERSON, JUST A --TEAM
--
BIGBIGBIGLY, NAMENAM--LONGLONGLONGLONG
--
--
--
--
--
--
--
XXXXXXX, YYYYYY Z --
--
AAAAA, B --X
--
--
--
-- """
)
)
)
assert slist.event_name == "BOYS 10&U 50 FLY"
assert not slist.is_empty_lane(1, 4)
assert slist.name(1, 4) == "PERSON, JUST A"
assert slist.team(1, 4) == "TEAM"
assert slist.is_empty_lane(1, 5)
assert slist.name(1, 6) == "BIGBIGBIGLY, NAMENAM"
assert slist.team(1, 6) == "LONGLONGLONGLONG"
assert slist.name(2, 4) == "XXXXXXX, YYYYYY Z"
assert slist.team(2, 4) == ""
assert slist.name(2, 6) == "AAAAA, B"
assert slist.team(2, 6) == "X"
def test_six_heats():
"""General test on 6 heats worth of data"""
slist = CTSStartList(
io.StringIO(
textwrap.dedent(
"""\
#34 GIRLS 15&O 50 BACK
--
--
SANTIAGO, LINDSEY 0 --BLUE
BROWN, LORRAINE 0 --BLUE
HARRISON, JOSEPHINE --GREEN
DRAKE, MELISSA 0 --RED
--
--
--
--
LOWE, DOREEN 1 --GREEN
BRYAN, MARIA 1 --GREEN
PATTON, MOLLY 0 --GREEN
SUTTON, SARA 0 --GREEN
PARKS, SONYA 0 --RED
HANSEN, JANE 1 --RED
WADE, CHARLOTTE 0 --GREEN
WELCH, ALBERTA 0 --GREEN
--
--
FLOYD, PHYLLIS 0 --BLUE
HENRY, SOPHIA 0 --RED
PEREZ, EDNA 0 --RED
GREER, JENNA 0 --RED
ALVAREZ, FREDA 0 --RED
WASHINGTON, LYNDA 1 --GREEN
MILLS, JASMINE 0 --GREEN
DELGADO, BESSIE 0 --RED
--
--
COLEMAN, RENEE 0 --BLUE
TURNER, TAMARA 0 --RED
THORNTON, NAOMI 1 --GREEN
INGRAM, LESLIE 1 --BLUE
LARSON, EDNA 0 --GREEN
INGRAM, LOLA 1 --RED
CARPENTER, ERMA 0 --BLUE
HARRINGTON, STACY 0 --BLUE
--
--
ESTRADA, KRISTINA 0 --GREEN
ZIMMERMAN, LYDIA 0 --BLUE
HARVEY, SILVIA 0 --BLUE
PATTERSON, PATTI 1 --BLUE
DAVIS, MYRTLE 1 --RED
CRAIG, KRYSTAL 0 --RED
WILKINS, VICKIE 0 --RED
SINGLETON, LORENE 1 --RED
--
--
COLE, CYNTHIA 1 --BLUE
HARDY, LAVERNE 0 --RED
KELLER, LATOYA 1 --GREEN
WATERS, ROBIN 0 --GREEN
PADILLA, ESSIE 0 --BLUE
SCHMIDT, KATHY 0 --GREEN
WASHINGTON, TRACEY 1--RED
MCDANIEL, SUZANNE 1 --GREEN
--
-- """
)
)
)
assert slist.event_num == 34
assert slist.event_name == "GIRLS 15&O 50 BACK"
assert slist.heats == 6
assert slist.is_empty_lane(1, 1)
assert not slist.is_empty_lane(6, 8)
assert slist.is_empty_lane(6, 10)
def test_invalid_header():
"""Exception should be thrown when header can't be parsed"""
with pytest.raises(ValueError) as verr:
CTSStartList(
io.StringIO(
textwrap.dedent(
"""\
#AA BOYS 10&U 50 FLY
--
--
--
PERSON, JUST A --TEAM
--
BIGBIGBIGLY, NAMENAM--LONGLONGLONGLONG
--
--
--
-- """
)
)
)
assert verr.match(r"Unable to parse header")
def test_invalid_num_lanes():
"""Exception should be thrown when there are not 10 lanes per heat"""
with pytest.raises(ValueError) as verr:
CTSStartList(
io.StringIO(
textwrap.dedent(
"""\
#1 BOYS 10&U 50 FLY
--
--
--
PERSON, JUST A --TEAM
--
BIGBIGBIGLY, NAMENAM--LONGLONGLONGLONG
--
--
-- """
)
)
)
assert verr.match(r"Length is not a multiple of 10")
def test_invalid_line():
"""Exception should be thrown when a line can't be parsed as an entry"""
with pytest.raises(ValueError) as verr:
CTSStartList(
io.StringIO(
textwrap.dedent(
"""\
#1 BOYS 10&U 50 FLY
--
INVALID LINE
--
PERSON, JUST A --TEAM
--
BIGBIGBIGLY, NAMENAM--LONGLONGLONGLONG
--
--
--
-- """
)
)
)
assert verr.match(r"Unable to parse line")