Coverage for test\test_ipokertofpdb.py: 100%

96 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2024-11-18 00:10 +0000

1import re 

2 

3 

4substitutions = { 

5 "LS": r"\$|\xe2\x82\xac|\xe2\u201a\xac|\u20ac|\xc2\xa3|\£|RSD|", 

6 "PLYR": r"(?P<PNAME>[^\"]+)", 

7 "NUM": r"(?:\d+)|(\d+\s\d+)", 

8 "NUM2": r"\b((?:\d{1,3}(?:\s\d{3})*)|(?:\d+))\b", # Regex pattern for matching numbers with spaces 

9} 

10 

11re_PlayerInfo = re.compile( 

12 r'<player( (seat="(?P<SEAT>[0-9]+)"|name="%(PLYR)s"|chips="(%(LS)s)?(?P<CASH>[%(NUM2)s]+)(%(LS)s)?"|dealer="(?P<BUTTONPOS>(0|1))"|win="(%(LS)s)?(?P<WIN>[%(NUM)s]+)(%(LS)s)?"|bet="(%(LS)s)?(?P<BET>[^"]+)(%(LS)s)?"|addon="\d*"|rebuy="\d*"|merge="\d*"|reg_code="[\d-]*"))+\s*/>' 

13 % substitutions, 

14 re.MULTILINE, 

15) 

16 

17 

18def test_re_PlayerInfo2(): 

19 text = '<player bet="20" reg_code="5105918454" win="0" seat="10" dealer="1" rebuy="0" chips="20" name="clement10s" addon="0"/>' 

20 match = re_PlayerInfo.search(text) 

21 assert match is not None 

22 

23 

24def test_re_PlayerInfo7(): 

25 text = ( 

26 '<player bet="100" reg_code="" win="40" seat="3" dealer="0" rebuy="0" chips="1 480" name="pergerd" addon="0"/>' 

27 ) 

28 match = re_PlayerInfo.search(text) 

29 assert match is not None 

30 assert match.group("SEAT") == "3" 

31 assert match.group("PNAME") == "pergerd" 

32 assert match.group("CASH") == "1 480" 

33 assert match.group("BUTTONPOS") == "0" 

34 assert match.group("WIN") == "40" 

35 assert match.group("BET") == "100" 

36 

37 

38def test_re_PlayerInfo3(): 

39 text = '<player bet="100" reg_code="" win="40" seat="3" dealer="0" rebuy="0" chips="1 480" name="pergerd" addon="0"/><player bet="20" reg_code="5105918454" win="0" seat="10" dealer="1" rebuy="0" chips="20" name="clement10s" addon="0"/>' 

40 m = re_PlayerInfo.finditer(text) 

41 plist = {} 

42 for a in m: 

43 a.groupdict() 

44 plist[a.group("PNAME")] = [int(a.group("SEAT")), (a.group("CASH")), (a.group("WIN")), False] 

45 assert len(plist) == 2 

46 

47 

48def test_re_PlayerInfo8(): 

49 text = ( 

50 '<player bet="740" reg_code="" win="1 480" seat="3" dealer="1" rebuy="0" chips="740" name="pergerd" addon="0"/>' 

51 ) 

52 match = re_PlayerInfo.search(text) 

53 assert match is not None 

54 assert match.group("SEAT") == "3" 

55 assert match.group("PNAME") == "pergerd" 

56 assert match.group("CASH") == "740" 

57 assert match.group("BUTTONPOS") == "1" 

58 assert match.group("WIN") == "1 480" 

59 assert match.group("BET") == "740" 

60 

61 

62re_GameInfoTrny = re.compile( 

63 r""" 

64(?:(<tour(?:nament)?code>(?P<TOURNO>\d+)</tour(?:nament)?code>))| 

65(?:(<tournamentname>(?P<NAME>[^<]*)</tournamentname>))| 

66(?:(<rewarddrawn>(?P<REWARD>[%(NUM2)s%(LS)s]+)</rewarddrawn>))|  

67(?:(<place>(?P<PLACE>.+?)</place>))| 

68(?:(<buyin>(?P<BIAMT>[%(NUM2)s%(LS)s]+)\s\+\s)?(?P<BIRAKE>[%(NUM2)s%(LS)s]+)\s\+\s(?P<BIRAKE2>[%(NUM2)s%(LS)s]+)</buyin>)| 

69(?:(<totalbuyin>(?P<TOTBUYIN>.*)</totalbuyin>))| 

70(?:(<win>(%(LS)s)?(?P<WIN>[%(NUM2)s%(LS)s]+)</win>)) 

71""" 

72 % substitutions, 

73 re.VERBOSE, 

74) 

75 

76 

77re_GameInfoTrny2 = re.compile( 

78 r""" 

79(?:(<tour(?:nament)?code>(?P<TOURNO>\d+)</tour(?:nament)?code>))| 

80(?:(<tournamentname>(?P<NAME>[^<]*)</tournamentname>))| 

81(?:(<place>(?P<PLACE>.+?)</place>))| 

82(?:(<buyin>(?P<BIAMT>[%(NUM2)s%(LS)s]+)\s\+\s)?(?P<BIRAKE>[%(NUM2)s%(LS)s]+)</buyin>)| 

83(?:(<totalbuyin>(?P<TOTBUYIN>[%(NUM2)s%(LS)s]+)</totalbuyin>))| 

84(?:(<win>(%(LS)s)?(?P<WIN>.+?|[%(NUM2)s%(LS)s]+)</win>)) 

85""" 

86 % substitutions, 

87 re.VERBOSE, 

88) 

89 

90 

91def test_re_GameInfoTrny(): 

92 text = """ 

93 <tournamentcode>826763510</tournamentcode> 

94 <tournamentname>Sit’n’Go Twister 0.20€</tournamentname> 

95 <rewarddrawn>0,80€</rewarddrawn> 

96 <place>2</place> 

97 <buyin>0€ + 0,01€ + 0,19€</buyin> 

98 <totalbuyin>0,20€</totalbuyin> 

99 <win>0</win> 

100""" 

101 matches = list(re_GameInfoTrny.finditer(text)) 

102 

103 assert matches[0].group("TOURNO") == "826763510" 

104 assert matches[1].group("NAME") == "Sit’n’Go Twister 0.20€" 

105 assert matches[2].group("REWARD") == "0,80€" 

106 assert matches[3].group("PLACE") == "2" 

107 assert matches[4].group("BIAMT") == "0€" 

108 assert matches[4].group("BIRAKE") == "0,01€" 

109 assert matches[4].group("BIRAKE2") == "0,19€" 

110 assert matches[5].group("TOTBUYIN") == "0,20€" 

111 assert matches[6].group("WIN") == "0" 

112 

113 

114def test_re_GameInfoTrnywin(): 

115 text = """ 

116 <tournamentcode>829730818</tournamentcode> 

117 <tournamentname>Sit’n’Go Twister 0.20€</tournamentname> 

118 <rewarddrawn>0,40€</rewarddrawn> 

119 <place>1</place> 

120 <buyin>0€ + 0,01€ + 0,19€</buyin> 

121 <totalbuyin>0,20€</totalbuyin> 

122 <win>0,40€</win> 

123""" 

124 matches = list(re_GameInfoTrny.finditer(text)) 

125 

126 assert matches[0].group("TOURNO") == "829730818" 

127 assert matches[1].group("NAME") == "Sit’n’Go Twister 0.20€" 

128 assert matches[2].group("REWARD") == "0,40€" 

129 assert matches[3].group("PLACE") == "1" 

130 assert matches[4].group("BIAMT") == "0€" 

131 assert matches[4].group("BIRAKE") == "0,01€" 

132 assert matches[4].group("BIRAKE2") == "0,19€" 

133 assert matches[5].group("TOTBUYIN") == "0,20€" 

134 assert matches[6].group("WIN") == "0,40€" 

135 

136 

137def test_re_GameInfoTrny_red(): 

138 text = """ 

139 <tournamentcode>1061132557</tournamentcode> 

140 <tournamentname>E10 Freebuy Sat 1x30€</tournamentname> 

141 <place>N/A</place> 

142 <buyin>€0 + €0</buyin> 

143 <totalbuyin>€0</totalbuyin> 

144 <win>N/A</win> 

145""" 

146 matches = list(re_GameInfoTrny2.finditer(text)) 

147 

148 assert matches[0].group("TOURNO") == "1061132557" 

149 assert matches[1].group("NAME") == "E10 Freebuy Sat 1x30€" 

150 

151 assert matches[2].group("PLACE") == "N/A" 

152 assert matches[3].group("BIAMT") == "€0" 

153 assert matches[3].group("BIRAKE") == "€0" 

154 

155 assert matches[4].group("TOTBUYIN") == "€0" 

156 assert matches[5].group("WIN") == "N/A" 

157 

158 

159def test_re_GameInfoTrny_red2(): 

160 text = """ 

161 <tournamentcode>1067382320</tournamentcode> 

162 <tournamentname>Series Freebuy Sat 1x125€</tournamentname> 

163 <place>851</place> 

164 <buyin>€0 + €0</buyin> 

165 <totalbuyin>€0</totalbuyin> 

166 <win>0</win> 

167""" 

168 matches = list(re_GameInfoTrny2.finditer(text)) 

169 

170 assert matches[0].group("TOURNO") == "1067382320" 

171 assert matches[1].group("NAME") == "Series Freebuy Sat 1x125€" 

172 

173 assert matches[2].group("PLACE") == "851" 

174 assert matches[3].group("BIAMT") == "€0" 

175 assert matches[3].group("BIRAKE") == "€0" 

176 

177 assert matches[4].group("TOTBUYIN") == "€0" 

178 assert matches[5].group("WIN") == "0" 

179 

180 

181re_TourNo = re.compile(r"(?P<TOURNO>\d+)$") 

182 

183 

184def test_re_Tourno1(): 

185 text = "Sit’n’Go Twister 0.20€, 829730819" 

186 match = re_TourNo.search(text) 

187 assert match.group("TOURNO") == "829730819" 

188 

189 

190re_client = re.compile(r"<client_version>(?P<CLIENT>.*?)</client_version>") 

191 

192 

193def test_re_cliento1(): 

194 text = "<client_version>23.5.1.13</client_version>" 

195 match = re_client.search(text) 

196 assert match.group("CLIENT") == "23.5.1.13" 

197 

198 

199re_MaxSeats = re.compile(r"<tablesize>(?P<SEATS>[0-9]+)</tablesize>", re.MULTILINE) 

200 

201 

202def test_MaxSeats1(): 

203 text = "<tablesize>6</tablesize>" 

204 match = re_MaxSeats.search(text) 

205 assert match.group("SEATS") == "6"