Coverage for test\test_swc.py: 98%
240 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-27 18:50 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-27 18:50 +0000
1import re
2import pytest
4substitutions = {
5 'PLYR': r'(?P<PNAME>\w+)',
6 'BRKTS': r'(\(button\) |\(small blind\) |\(big blind\) |\(button\) \(small blind\) |\(button\) \(big blind\)| )?',
7 'NUM': r'(.,\d+)|(\d+)', # Regex pattern for matching numbers
8 'NUM2': r'\b((?:\d{1,3}(?:\s\d{3})*)|(?:\d+))\b', # Regex pattern for matching numbers with spaces
9 }
12re_GameInfo = re.compile(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>.*)""",re.VERBOSE)
15def test_re_GameInfo():
16 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'
17 match = re_GameInfo.search(text)
18 assert match is not None
19 assert match.group('HID') == '183314831'
20 assert match.group('TOURNO') == '183316169'
21 assert match.group('TABLE2') == '5 Card Omaha Freeroll [20 Chips]'
22 assert match.group('BUYIN') == '0'
23 assert match.group('BIAMT') == '0'
24 assert match.group('BIRAKE') == '0'
25 assert match.group('GAME') == 'Omaha 5 Cards'
26 assert match.group('LIMIT') == 'Pot Limit'
27 assert match.group('SB') == '10'
28 assert match.group('BB') == '20'
29 assert match.group('DATETIME') == '2023/06/26 19:30:22 UTC'
31def test_re_GameInfo9():
32 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"
33 match = re_GameInfo.search(text)
34 assert match is not None
35 assert match.group('HID') == '194644676'
36 assert match.group('TOURNO') == '194634844'
37 assert match.group('TABLE2') == 'NLH Freeroll [50 Chips]'
38 assert match.group('BUYIN') == '0'
39 assert match.group('BIAMT') == '0'
40 assert match.group('BIRAKE') == '0'
41 assert match.group('GAME') == "Hold'em"
42 assert match.group('LIMIT') == 'No Limit'
43 assert match.group('SB') == '1,000'
44 assert match.group('BB') == '2,000'
45 assert match.group('DATETIME') == '2023/09/22 23:06:25 UTC'
48def test_re_GameInfo3():
49 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'
50 match = re_GameInfo.search(text)
51 assert match is not None
52 assert match.group('HID') == '183387021'
54def test_re_GameInfo4():
55 text = 'SwCPoker Hand #183411552: Omaha Pot Limit (0.02/0.04) - 2023/06/27 14:43:04 UTC'
56 match = re_GameInfo.search(text)
57 assert match is not None
58 assert match.group('HID') == '183411552'
60def test_re_GameInfo52():
61 text = 'SwCPoker Hand #183411639: Hold\'em No Limit (0.02/0.04) - 2023/06/27 14:47:48 UTC'
62 match = re_GameInfo.search(text)
63 assert match is not None
64 assert match.group('HID') == '183411639'
67re_HandInfo = re.compile(r"""^Table\s'(?P<TABLE>.*?)'\(\d+\)\s(?P<MAX>\d+)-max\s(?:\(Real Money\)\s)?Seat\s\#\d+\sis\sthe\sbutton""")
71def test_re_HandInfo():
72 text = """Table 'No-Rake Micro Stakes #1'(28248) 9-max (Real Money) Seat #7 is the button"""
73 match = re_HandInfo.search(text)
74 assert match is not None
75 assert match.group('TABLE') == """No-Rake Micro Stakes #1"""
76 assert match.group('MAX') == "9"
79def test_re_HandInfo2():
80 text = """Table 'No-Rake Micro Stakes PLO'(24812) 9-max (Real Money) Seat #4 is the button"""
81 match = re_HandInfo.search(text)
82 assert match is not None
83 assert match.group('TABLE') == """No-Rake Micro Stakes PLO"""
84 assert match.group('MAX') == "9"
87def test_re_HandInfo3():
88 text = """Table 'FunTime #2'(183558223) 6-max (Real Money) Seat #3 is the button"""
89 match = re_HandInfo.search(text)
90 assert match is not None
91 assert match.group('TABLE') == """FunTime #2"""
92 assert match.group('MAX') == "6"
95def test_re_HandInfo_mtt():
96 text = """Table '183390848 3'(183387008) 8-max Seat #2 is the button"""
97 match = re_HandInfo.search(text)
98 assert match is not None
99 assert match.group('TABLE') == """183390848 3"""
100 assert match.group('MAX') == "8"
104re_PlayerInfo = re.compile(r"""^Seat\s+(?P<SEAT>\d+):\s+(?P<PNAME>\w+)\s+\((?P<CASH>\d{1,3}(,\d{3})*(\.\d+)?)\sin\schips\)""" , re.MULTILINE|re.VERBOSE)
106def test_re_PlayerInfo():
107 text = """Seat 7: cheapsmack (4.75 in chips)"""
108 match = re_PlayerInfo.search(text)
109 assert match is not None
110 assert match.group('SEAT') == """7"""
111 assert match.group('PNAME') == "cheapsmack"
112 assert match.group('CASH') == "4.75"
114def test_re_PlayerInfo2():
115 text = """Seat 8: hero (4 in chips)"""
116 match = re_PlayerInfo.search(text)
117 assert match is not None
118 assert match.group('SEAT') == """8"""
119 assert match.group('PNAME') == "hero"
120 assert match.group('CASH') == "4"
122def test_re_PlayerInfo3():
123 text = """Seat 1: ab21ykd4gqnh (1,200 in chips)"""
124 match = re_PlayerInfo.search(text)
125 assert match is not None
126 assert match.group('SEAT') == """1"""
127 assert match.group('PNAME') == "ab21ykd4gqnh"
128 assert match.group('CASH') == "1,200"
130def test_re_PlayerInfo3():
131 text = """Seat 8: _all_in_ (958 in chips)"""
132 match = re_PlayerInfo.search(text)
133 assert match is not None
134 assert match.group('SEAT') == """8"""
135 assert match.group('PNAME') == "_all_in_"
136 assert match.group('CASH') == "958"
138re_ButtonPos = re.compile(r"""Seat\s+\#(?P<BUTTON>\d+)\sis\sthe\sbutton""",re.MULTILINE)
142def test_re_ButtonPos():
143 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"""
144 match = re_ButtonPos.search(text)
145 assert match is not None
146 assert match.group('BUTTON') == "7"
150re_CollectPot = re.compile(r"%(PLYR)s\s+%(BRKTS)s%(BRKTS)s(collected|wins|splits|won)\s+\((?P<POT>\d{1,3}(,\d{3})*(\.\d+)?)\)" % substitutions, re.MULTILINE)
151re_CollectPot2 = re.compile(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\))" % substitutions, re.MULTILINE)
155def test_re_CollectPot2():
156 text = """Seat 7: cheapsmack (button) (small blind) collected (0.08)"""
157 match = re_CollectPot2.search(text)
158 assert match is not None
159 assert match.group('POT') is None
160 assert match.group('POT2') == "0.08"
161 assert match.group('SEAT') == "7"
162 assert match.group('PNAME') == "cheapsmack"
163 assert match.group('SHOWED') is None
164 assert match.group('CARDS') is None
166def test_re_CollectPot3():
167 text = """Seat 4: cerami71 (button) mucked [2h 5c 3d 4h]"""
168 match = re_CollectPot2.search(text)
169 assert match is not None
170 assert match.group('POT') is None
171 assert match.group('POT2') is None
172 assert match.group('SEAT') == "4"
173 assert match.group('PNAME') == "cerami71"
174 assert match.group('SHOWED') == "mucked"
175 assert match.group('CARDS') == "2h 5c 3d 4h"
178def test_re_CollectPot4():
179 text = """Seat 5: GER4SOUL (small blind) showed [5h 5s 6h 3s] and lost with a pair of Fives"""
180 match = re_CollectPot2.search(text)
181 assert match is not None
182 assert match.group('POT') is None
183 assert match.group('POT2') is None
184 assert match.group('SEAT') == "5"
185 assert match.group('PNAME') == "GER4SOUL"
186 assert match.group('SHOWED') == "showed"
187 assert match.group('CARDS') == "5h 5s 6h 3s"
188 assert match.group('STRING') == "a pair of Fives"
190def test_re_CollectPot5():
191 text = """Seat 6: edinapoker (big blind) showed [9h 5d 7c 4d] and won (0.42) with a flush, Ace high"""
192 match = re_CollectPot2.search(text)
193 assert match is not None
194 assert match.group('POT') == "0.42"
195 assert match.group('POT2') is None
196 assert match.group('SEAT') == "6"
197 assert match.group('PNAME') == "edinapoker"
198 assert match.group('SHOWED') == "showed"
199 assert match.group('CARDS') == "9h 5d 7c 4d"
200 assert match.group('STRING') == "a flush, Ace high"
202def test_re_CollectPot6():
203 text = """Seat 4: cerami71 (big blind) folded on the Turn"""
204 match = re_CollectPot2.search(text)
205 assert match is not None
206 assert match.group('POT') is None
207 assert match.group('POT2') is None
208 assert match.group('SEAT') == "4"
209 assert match.group('PNAME') == "cerami71"
210 assert match.group('SHOWED') is None
211 assert match.group('CARDS') is None
212 assert match.group('STRING') is None
214def test_re_CollectPot7():
215 text = """Seat 6: edinapoker (small blind) folded before Flop """
216 match = re_CollectPot2.search(text)
217 assert match is not None
218 assert match.group('POT') is None
219 assert match.group('POT2') is None
220 assert match.group('SEAT') == "6"
221 assert match.group('PNAME') == "edinapoker"
222 assert match.group('SHOWED') is None
223 assert match.group('CARDS') is None
224 assert match.group('STRING') is None
226def test_re_CollectPot8():
227 text = """Seat 4: cerami71 folded before Flop (didn't bet) """
228 match = re_CollectPot2.search(text)
229 assert match is not None
230 assert match.group('POT') is None
231 assert match.group('POT2') is None
232 assert match.group('SEAT') == "4"
233 assert match.group('PNAME') == "cerami71"
234 assert match.group('SHOWED') is None
235 assert match.group('CARDS') is None
236 assert match.group('STRING') is None
239def test_re_CollectPot9():
240 text = """Seat 5: GER4SOUL folded on the Turn """
241 match = re_CollectPot2.search(text)
242 assert match is not None
243 assert match.group('POT') is None
244 assert match.group('POT2') is None
245 assert match.group('SEAT') == "5"
246 assert match.group('PNAME') == "GER4SOUL"
247 assert match.group('SHOWED') is None
248 assert match.group('CARDS') is None
249 assert match.group('STRING') is None
251re_ShowdownAction = re.compile(r"^(?P<PNAME>\w+): (shows \[(?P<CARDS>.*)\]\s\((?P<FHAND>.*?)\)|doesn't show hand|mucks hand)", re.MULTILINE)
253def test_re_ShowdownAction():
254 text = """GER4SOUL: shows [5h 5s 6h 3s] (a pair of Fives)"""
255 match = re_ShowdownAction.search(text)
256 assert match is not None
257 assert match.group('CARDS') == "5h 5s 6h 3s"
260re_Action = re.compile(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*$""" % substitutions, re.MULTILINE|re.VERBOSE)
266def test_re_Action():
267 text = """cheapsmack: raises 0.06 to 0.08"""
268 match = re_Action.search(text)
269 assert match is not None
270 assert match.group('POT') == "0.08"
271 assert match.group('BET') == "0.06"
272 assert match.group('ATYPE') == " raises"
273 assert match.group('PNAME') == "cheapsmack"
275def test_re_Action_checks():
276 text = """GER4SOUL: checks"""
277 match = re_Action.search(text)
278 assert match is not None
279 assert match.group('ATYPE') == " checks"
280 assert match.group('PNAME') == "GER4SOUL"
281 assert match.group('POT') is None # Updated assertion to handle 'POT' being None
282 assert match.group('BET') is None # Updated assertion to handle 'BET' being None
284def test_re_Action_call():
285 text = """edinapoker: calls 0.02"""
286 match = re_Action.search(text)
287 assert match is not None
288 assert match.group('ATYPE') == " calls"
289 assert match.group('PNAME') == "edinapoker"
290 assert match.group('BET') == '0.02'
293re_rake = re.compile('Total pot (?P<TOTALPOT>\\d{1,3}(,\\d{3})*(\\.\\d+)?)\\s\\|\\sRake\\s(?P<RAKE>\\d{1,3}(,\\d{3})*(\\.\\d+)?)', re.MULTILINE)
296def test_re_rake():
297 text = """Total pot 1,350 | Rake 0"""
298 match = re_rake.search(text)
299 assert match is not None
300 assert match.group('TOTALPOT') == "1,350"
301 assert match.group('RAKE') == "0"
303def test_re_rake2():
304 text = """Total pot 0.57 | Rake 0.03"""
305 match = re_rake.search(text)
306 assert match is not None
307 assert match.group('TOTALPOT') == "0.57"
308 assert match.group('RAKE') == "0.03"