Coverage for test\test_swc.py: 100%
239 statements
« prev ^ index » next coverage.py v7.6.3, created at 2024-10-15 19:33 +0000
« prev ^ index » next coverage.py v7.6.3, created at 2024-10-15 19:33 +0000
1import re
3substitutions = {
4 "PLYR": r"(?P<PNAME>\w+)",
5 "BRKTS": r"(\(button\) |\(small blind\) |\(big blind\) |\(button\) \(small blind\) |\(button\) \(big blind\)| )?",
6 "NUM": r"(.,\d+)|(\d+)", # Regex pattern for matching numbers
7 "NUM2": r"\b((?:\d{1,3}(?:\s\d{3})*)|(?:\d+))\b", # Regex pattern for matching numbers with spaces
8}
11re_GameInfo = re.compile(
12 r"""SwCPoker\sHand\s*\#(?P<HID>\d+):\s((Tournament|Cashgame|sitngo)\s\(((?P<TABLE2>.*?))\)\#(?P<TOURNO>\d+),\s(?P<BUYIN>(?P<BIAMT>\d+(\.\d+)?))\+(?P<BIRAKE>\d+(\.\d+)?)\s|\s)(?P<GAME>(Hold\'em|Omaha|Omaha\s5\sCards))\s(?P<LIMIT>(NL|PL|Limit|Pot\sLimit|No\sLimit))\s((-\sLevel\s\w+\s)|)\((?P<SB>\d+(\.\d+)?(\,\d+)?)/(?P<BB>\d+(\.\d+)?(\,\d+)?)\)\s-\s(?P<DATETIME>.*)""",
13 re.VERBOSE,
14)
17def test_re_GameInfo():
18 text = "SwCPoker Hand #183314831: Tournament (5 Card Omaha Freeroll [20 Chips])#183316169, 0+0 Omaha 5 Cards Pot Limit - Level I (10/20) - 2023/06/26 19:30:22 UTC"
19 match = re_GameInfo.search(text)
20 assert match is not None
21 assert match.group("HID") == "183314831"
22 assert match.group("TOURNO") == "183316169"
23 assert match.group("TABLE2") == "5 Card Omaha Freeroll [20 Chips]"
24 assert match.group("BUYIN") == "0"
25 assert match.group("BIAMT") == "0"
26 assert match.group("BIRAKE") == "0"
27 assert match.group("GAME") == "Omaha 5 Cards"
28 assert match.group("LIMIT") == "Pot Limit"
29 assert match.group("SB") == "10"
30 assert match.group("BB") == "20"
31 assert match.group("DATETIME") == "2023/06/26 19:30:22 UTC"
34def test_re_GameInfo9():
35 text = "SwCPoker Hand #194644676: Tournament (NLH Freeroll [50 Chips])#194634844, 0+0 Hold'em No Limit - Level XVIII (1,000/2,000) - 2023/09/22 23:06:25 UTC"
36 match = re_GameInfo.search(text)
37 assert match is not None
38 assert match.group("HID") == "194644676"
39 assert match.group("TOURNO") == "194634844"
40 assert match.group("TABLE2") == "NLH Freeroll [50 Chips]"
41 assert match.group("BUYIN") == "0"
42 assert match.group("BIAMT") == "0"
43 assert match.group("BIRAKE") == "0"
44 assert match.group("GAME") == "Hold'em"
45 assert match.group("LIMIT") == "No Limit"
46 assert match.group("SB") == "1,000"
47 assert match.group("BB") == "2,000"
48 assert match.group("DATETIME") == "2023/09/22 23:06:25 UTC"
51def test_re_GameInfo3():
52 text = "SwCPoker Hand #183387021: Tournament (NLH Freeroll [30 Chips])#183390848, 0+0 Hold'em No Limit - Level I (10/20) - 2023/06/27 9:30:26 UTC"
53 match = re_GameInfo.search(text)
54 assert match is not None
55 assert match.group("HID") == "183387021"
58def test_re_GameInfo4():
59 text = "SwCPoker Hand #183411552: Omaha Pot Limit (0.02/0.04) - 2023/06/27 14:43:04 UTC"
60 match = re_GameInfo.search(text)
61 assert match is not None
62 assert match.group("HID") == "183411552"
65def test_re_GameInfo52():
66 text = "SwCPoker Hand #183411639: Hold'em No Limit (0.02/0.04) - 2023/06/27 14:47:48 UTC"
67 match = re_GameInfo.search(text)
68 assert match is not None
69 assert match.group("HID") == "183411639"
72re_HandInfo = re.compile(
73 r"""^Table\s'(?P<TABLE>.*?)'\(\d+\)\s(?P<MAX>\d+)-max\s(?:\(Real Money\)\s)?Seat\s\#\d+\sis\sthe\sbutton"""
74)
77def test_re_HandInfo():
78 text = """Table 'No-Rake Micro Stakes #1'(28248) 9-max (Real Money) Seat #7 is the button"""
79 match = re_HandInfo.search(text)
80 assert match is not None
81 assert match.group("TABLE") == """No-Rake Micro Stakes #1"""
82 assert match.group("MAX") == "9"
85def test_re_HandInfo2():
86 text = """Table 'No-Rake Micro Stakes PLO'(24812) 9-max (Real Money) Seat #4 is the button"""
87 match = re_HandInfo.search(text)
88 assert match is not None
89 assert match.group("TABLE") == """No-Rake Micro Stakes PLO"""
90 assert match.group("MAX") == "9"
93def test_re_HandInfo3():
94 text = """Table 'FunTime #2'(183558223) 6-max (Real Money) Seat #3 is the button"""
95 match = re_HandInfo.search(text)
96 assert match is not None
97 assert match.group("TABLE") == """FunTime #2"""
98 assert match.group("MAX") == "6"
101def test_re_HandInfo_mtt():
102 text = """Table '183390848 3'(183387008) 8-max Seat #2 is the button"""
103 match = re_HandInfo.search(text)
104 assert match is not None
105 assert match.group("TABLE") == """183390848 3"""
106 assert match.group("MAX") == "8"
109re_PlayerInfo = re.compile(
110 r"""^Seat\s+(?P<SEAT>\d+):\s+(?P<PNAME>\w+)\s+\((?P<CASH>\d{1,3}(,\d{3})*(\.\d+)?)\sin\schips\)""",
111 re.MULTILINE | re.VERBOSE,
112)
115def test_re_PlayerInfo():
116 text = """Seat 7: cheapsmack (4.75 in chips)"""
117 match = re_PlayerInfo.search(text)
118 assert match is not None
119 assert match.group("SEAT") == """7"""
120 assert match.group("PNAME") == "cheapsmack"
121 assert match.group("CASH") == "4.75"
124def test_re_PlayerInfo2():
125 text = """Seat 8: hero (4 in chips)"""
126 match = re_PlayerInfo.search(text)
127 assert match is not None
128 assert match.group("SEAT") == """8"""
129 assert match.group("PNAME") == "hero"
130 assert match.group("CASH") == "4"
133def test_re_PlayerInfo3():
134 text = """Seat 1: ab21ykd4gqnh (1,200 in chips)"""
135 match = re_PlayerInfo.search(text)
136 assert match is not None
137 assert match.group("SEAT") == """1"""
138 assert match.group("PNAME") == "ab21ykd4gqnh"
139 assert match.group("CASH") == "1,200"
142def test_re_PlayerInfo33():
143 text = """Seat 8: _all_in_ (958 in chips)"""
144 match = re_PlayerInfo.search(text)
145 assert match is not None
146 assert match.group("SEAT") == """8"""
147 assert match.group("PNAME") == "_all_in_"
148 assert match.group("CASH") == "958"
151re_ButtonPos = re.compile(r"""Seat\s+\#(?P<BUTTON>\d+)\sis\sthe\sbutton""", re.MULTILINE)
154def test_re_ButtonPos():
155 text = """\ufeffSwCPoker Hand #183411639: Hold'em No Limit (0.02/0.04) - 2023/06/27 14:47:48 UTC\nTable 'No-Rake Micro Stakes #1'(28248) 9-max (Real Money) Seat #7 is the button\nSeat 7: cheapsmack (4.75 in chips)\nSeat 8: edinapoker (4 in chips)\ncheapsmack: posts small blind 0.02\nedinapoker: posts big blind 0.04\n*** HOLE CARDS ***\nDealt to edinapoker [3c 9d]\ncheapsmack: raises 0.06 to 0.08\nedinapoker: folds\nUncalled bet (0.04) returned to cheapsmack\n*** SHOW DOWN ***\ncheapsmack: doesn't show hand\ncheapsmack collected 0.08 from pot\n*** SUMMARY ***\nTotal pot 0.08 | Rake 0 \nSeat 7: cheapsmack (button) (small blind) collected (0.08)\nSeat 8: edinapoker (big blind) folded before Flop"""
156 match = re_ButtonPos.search(text)
157 assert match is not None
158 assert match.group("BUTTON") == "7"
161re_CollectPot = re.compile(
162 r"%(PLYR)s\s+%(BRKTS)s%(BRKTS)s(collected|wins|splits|won)\s+\((?P<POT>\d{1,3}(,\d{3})*(\.\d+)?)\)" % substitutions,
163 re.MULTILINE,
164)
165re_CollectPot2 = re.compile(
166 r"^Seat (?P<SEAT>[0-9]+): %(PLYR)s ((%(BRKTS)s(((((?P<SHOWED>showed|mucked) \[(?P<CARDS>.*)\]( and (lost|(won|collected) \((?P<POT>[.\d]+)\)) with (?P<STRING>.+?)(\s\sand\s(won\s\([.\d]+\)|lost)\swith\s(?P<STRING2>.*))?)?$)|collected\s\((?P<POT2>[.\d]+)\)))|folded ((on the (Flop|Turn|River))|before Flop)))|folded before Flop \(didn't bet\))"
167 % substitutions,
168 re.MULTILINE,
169)
172def test_re_CollectPot2():
173 text = """Seat 7: cheapsmack (button) (small blind) collected (0.08)"""
174 match = re_CollectPot2.search(text)
175 assert match is not None
176 assert match.group("POT") is None
177 assert match.group("POT2") == "0.08"
178 assert match.group("SEAT") == "7"
179 assert match.group("PNAME") == "cheapsmack"
180 assert match.group("SHOWED") is None
181 assert match.group("CARDS") is None
184def test_re_CollectPot3():
185 text = """Seat 4: cerami71 (button) mucked [2h 5c 3d 4h]"""
186 match = re_CollectPot2.search(text)
187 assert match is not None
188 assert match.group("POT") is None
189 assert match.group("POT2") is None
190 assert match.group("SEAT") == "4"
191 assert match.group("PNAME") == "cerami71"
192 assert match.group("SHOWED") == "mucked"
193 assert match.group("CARDS") == "2h 5c 3d 4h"
196def test_re_CollectPot4():
197 text = """Seat 5: GER4SOUL (small blind) showed [5h 5s 6h 3s] and lost with a pair of Fives"""
198 match = re_CollectPot2.search(text)
199 assert match is not None
200 assert match.group("POT") is None
201 assert match.group("POT2") is None
202 assert match.group("SEAT") == "5"
203 assert match.group("PNAME") == "GER4SOUL"
204 assert match.group("SHOWED") == "showed"
205 assert match.group("CARDS") == "5h 5s 6h 3s"
206 assert match.group("STRING") == "a pair of Fives"
209def test_re_CollectPot5():
210 text = """Seat 6: edinapoker (big blind) showed [9h 5d 7c 4d] and won (0.42) with a flush, Ace high"""
211 match = re_CollectPot2.search(text)
212 assert match is not None
213 assert match.group("POT") == "0.42"
214 assert match.group("POT2") is None
215 assert match.group("SEAT") == "6"
216 assert match.group("PNAME") == "edinapoker"
217 assert match.group("SHOWED") == "showed"
218 assert match.group("CARDS") == "9h 5d 7c 4d"
219 assert match.group("STRING") == "a flush, Ace high"
222def test_re_CollectPot6():
223 text = """Seat 4: cerami71 (big blind) folded on the Turn"""
224 match = re_CollectPot2.search(text)
225 assert match is not None
226 assert match.group("POT") is None
227 assert match.group("POT2") is None
228 assert match.group("SEAT") == "4"
229 assert match.group("PNAME") == "cerami71"
230 assert match.group("SHOWED") is None
231 assert match.group("CARDS") is None
232 assert match.group("STRING") is None
235def test_re_CollectPot7():
236 text = """Seat 6: edinapoker (small blind) folded before Flop """
237 match = re_CollectPot2.search(text)
238 assert match is not None
239 assert match.group("POT") is None
240 assert match.group("POT2") is None
241 assert match.group("SEAT") == "6"
242 assert match.group("PNAME") == "edinapoker"
243 assert match.group("SHOWED") is None
244 assert match.group("CARDS") is None
245 assert match.group("STRING") is None
248def test_re_CollectPot8():
249 text = """Seat 4: cerami71 folded before Flop (didn't bet) """
250 match = re_CollectPot2.search(text)
251 assert match is not None
252 assert match.group("POT") is None
253 assert match.group("POT2") is None
254 assert match.group("SEAT") == "4"
255 assert match.group("PNAME") == "cerami71"
256 assert match.group("SHOWED") is None
257 assert match.group("CARDS") is None
258 assert match.group("STRING") is None
261def test_re_CollectPot9():
262 text = """Seat 5: GER4SOUL folded on the Turn """
263 match = re_CollectPot2.search(text)
264 assert match is not None
265 assert match.group("POT") is None
266 assert match.group("POT2") is None
267 assert match.group("SEAT") == "5"
268 assert match.group("PNAME") == "GER4SOUL"
269 assert match.group("SHOWED") is None
270 assert match.group("CARDS") is None
271 assert match.group("STRING") is None
274re_ShowdownAction = re.compile(
275 r"^(?P<PNAME>\w+): (shows \[(?P<CARDS>.*)\]\s\((?P<FHAND>.*?)\)|doesn't show hand|mucks hand)", re.MULTILINE
276)
279def test_re_ShowdownAction():
280 text = """GER4SOUL: shows [5h 5s 6h 3s] (a pair of Fives)"""
281 match = re_ShowdownAction.search(text)
282 assert match is not None
283 assert match.group("CARDS") == "5h 5s 6h 3s"
286re_Action = re.compile(
287 r"""^%(PLYR)s:(?P<ATYPE>\sbets|\schecks|\sraises|\scalls|\sfolds|\sdiscards|\sstands\spat)(?:\s(?P<BET>\d{1,3}(,\d{3})*(\.\d+)?))?(?:\sto\s(?P<POT>\d{1,3}(,\d{3})*(\.\d+)?))?\s*$"""
288 % substitutions,
289 re.MULTILINE | re.VERBOSE,
290)
293def test_re_Action():
294 text = """cheapsmack: raises 0.06 to 0.08"""
295 match = re_Action.search(text)
296 assert match is not None
297 assert match.group("POT") == "0.08"
298 assert match.group("BET") == "0.06"
299 assert match.group("ATYPE") == " raises"
300 assert match.group("PNAME") == "cheapsmack"
303def test_re_Action_checks():
304 text = """GER4SOUL: checks"""
305 match = re_Action.search(text)
306 assert match is not None
307 assert match.group("ATYPE") == " checks"
308 assert match.group("PNAME") == "GER4SOUL"
309 assert match.group("POT") is None # Updated assertion to handle 'POT' being None
310 assert match.group("BET") is None # Updated assertion to handle 'BET' being None
313def test_re_Action_call():
314 text = """edinapoker: calls 0.02"""
315 match = re_Action.search(text)
316 assert match is not None
317 assert match.group("ATYPE") == " calls"
318 assert match.group("PNAME") == "edinapoker"
319 assert match.group("BET") == "0.02"
322re_rake = re.compile(
323 "Total pot (?P<TOTALPOT>\\d{1,3}(,\\d{3})*(\\.\\d+)?)\\s\\|\\sRake\\s(?P<RAKE>\\d{1,3}(,\\d{3})*(\\.\\d+)?)",
324 re.MULTILINE,
325)
328def test_re_rake():
329 text = """Total pot 1,350 | Rake 0"""
330 match = re_rake.search(text)
331 assert match is not None
332 assert match.group("TOTALPOT") == "1,350"
333 assert match.group("RAKE") == "0"
336def test_re_rake2():
337 text = """Total pot 0.57 | Rake 0.03"""
338 match = re_rake.search(text)
339 assert match is not None
340 assert match.group("TOTALPOT") == "0.57"
341 assert match.group("RAKE") == "0.03"