Coverage for test\test_ipokertofpdb.py: 91%

97 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-27 18:50 +0000

1import re 

2import pytest 

3 

4 

5substitutions = { 

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

7 

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

9 'NUM': r'(?:\d+)|(\d+\s\d+)', 

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

11} 

12 

13re_PlayerInfo = re.compile(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*/>' % substitutions, re.MULTILINE) 

14 

15 

16 

17def test_re_PlayerInfo2(): 

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

19 match = re_PlayerInfo.search(text) 

20 assert match is not None 

21 

22def test_re_PlayerInfo7(): 

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

24 match = re_PlayerInfo.search(text) 

25 assert match is not None 

26 assert match.group('SEAT') == '3' 

27 assert match.group('PNAME') == 'pergerd' 

28 assert match.group('CASH') == '1 480' 

29 assert match.group('BUTTONPOS') == '0' 

30 assert match.group('WIN') == '40' 

31 assert match.group('BET') == '100' 

32 

33def test_re_PlayerInfo3(): 

34 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"/>' 

35 m = re_PlayerInfo.finditer(text) 

36 plist = {} 

37 for a in m: 

38 ag = a.groupdict() 

39 plist[a.group('PNAME')] = [int(a.group('SEAT')), (a.group('CASH')), 

40 (a.group('WIN')), False] 

41 assert len(plist) == 2 

42 

43 

44def test_re_PlayerInfo8(): 

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

46 match = re_PlayerInfo.search(text) 

47 assert match is not None 

48 assert match.group('SEAT') == '3' 

49 assert match.group('PNAME') == 'pergerd' 

50 assert match.group('CASH') == '740' 

51 assert match.group('BUTTONPOS') == '1' 

52 assert match.group('WIN') == '1 480' 

53 assert match.group('BET') == '740' 

54 

55 

56 

57 

58re_GameInfoTrny = re.compile(r""" 

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

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

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

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

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

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

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

66""" % substitutions, re.VERBOSE) 

67 

68 

69re_GameInfoTrny2 = re.compile(r""" 

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

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

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

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

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

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

76""" % substitutions, re.VERBOSE) 

77 

78 

79def test_re_GameInfoTrny(): 

80 text = """ 

81 <tournamentcode>826763510</tournamentcode> 

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

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

84 <place>2</place> 

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

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

87 <win>0</win> 

88""" 

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

90 

91 assert matches[0].group('TOURNO') == '826763510' 

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

93 assert matches[2].group('REWARD') == '0,80€' 

94 assert matches[3].group('PLACE') == '2' 

95 assert matches[4].group('BIAMT') == '0€' 

96 assert matches[4].group('BIRAKE') == '0,01€' 

97 assert matches[4].group('BIRAKE2') == '0,19€' 

98 assert matches[5].group('TOTBUYIN') == '0,20€' 

99 assert matches[6].group('WIN') == '0' 

100 

101 

102def test_re_GameInfoTrnywin(): 

103 text = """ 

104 <tournamentcode>829730818</tournamentcode> 

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

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

107 <place>1</place> 

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

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

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

111""" 

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

113 

114 assert matches[0].group('TOURNO') == '829730818' 

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

116 assert matches[2].group('REWARD') == '0,40€' 

117 assert matches[3].group('PLACE') == '1' 

118 assert matches[4].group('BIAMT') == '0€' 

119 assert matches[4].group('BIRAKE') == '0,01€' 

120 assert matches[4].group('BIRAKE2') == '0,19€' 

121 assert matches[5].group('TOTBUYIN') == '0,20€' 

122 assert matches[6].group('WIN') == '0,40€' 

123 

124 

125def test_re_GameInfoTrny_red(): 

126 text = """ 

127 <tournamentcode>1061132557</tournamentcode> 

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

129 <place>N/A</place> 

130 <buyin>€0 + €0</buyin> 

131 <totalbuyin>€0</totalbuyin> 

132 <win>N/A</win> 

133""" 

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

135 

136 assert matches[0].group('TOURNO') == '1061132557' 

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

138 

139 assert matches[2].group('PLACE') == 'N/A' 

140 assert matches[3].group('BIAMT') == '€0' 

141 assert matches[3].group('BIRAKE') == '€0' 

142 

143 assert matches[4].group('TOTBUYIN') == '€0' 

144 assert matches[5].group('WIN') == 'N/A' 

145 

146def test_re_GameInfoTrny_red(): 

147 text = """ 

148 <tournamentcode>1067382320</tournamentcode> 

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

150 <place>851</place> 

151 <buyin>€0 + €0</buyin> 

152 <totalbuyin>€0</totalbuyin> 

153 <win>0</win> 

154""" 

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

156 

157 assert matches[0].group('TOURNO') == '1067382320' 

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

159 

160 assert matches[2].group('PLACE') == '851' 

161 assert matches[3].group('BIAMT') == '€0' 

162 assert matches[3].group('BIRAKE') == '€0' 

163 

164 assert matches[4].group('TOTBUYIN') == '€0' 

165 assert matches[5].group('WIN') == '0' 

166 

167 

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

169 

170 

171def test_re_Tourno1(): 

172 text = 'Sit’n’Go Twister 0.20€, 829730819' 

173 match = re_TourNo.search(text) 

174 assert match.group('TOURNO') == '829730819' 

175 

176 

177 

178 

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

180 

181def test_re_cliento1(): 

182 text = '<client_version>23.5.1.13</client_version>' 

183 match = re_client.search(text) 

184 assert match.group('CLIENT') == '23.5.1.13' 

185 

186 

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

188 

189def test_MaxSeats1(): 

190 text = '<tablesize>6</tablesize>' 

191 match = re_MaxSeats.search(text) 

192 assert match.group('SEATS') == '6'