2 # -*- coding: utf-8 -*-
4 # Copyright 2010-2011, Carl Gherardi
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ########################################################################
29 from GuiTourneyImport
import SummaryImporter
33 def __init__(self
, sitename
):
39 def error_report(self
, filename
, hand
, stat
, ghash
, testhash
, player
):
40 print "Regression Test Error:"
41 print "\tFile: %s" % filename
42 print "\tStat: %s" % stat
43 print "\tPlayer: %s" % player
44 if filename
in self
.histogram
:
45 self
.histogram
[filename
] += 1
47 self
.histogram
[filename
] = 1
49 if stat
in self
.statcount
:
50 self
.statcount
[stat
] += 1
52 self
.statcount
[stat
] = 1
55 def print_histogram(self
):
56 print "%s:" % self
.site
57 for f
in self
.histogram
:
58 idx
= f
.find('regression')
59 print "(%3d) : %s" %(self
.histogram
[f
], f
[idx
:])
61 def compare(leaf
, importer
, errors
, site
):
63 #print "DEBUG: fileanme: %s" % filename
65 if filename
.endswith('.txt'):
66 # test if there is a .hp version of the file
67 importer
.addImportFileOrDir(filename
, site
= site
)
68 (stored
, errs
) = importer
.runImport()
70 # if os.path.isfile(filename + '.hp') and errs < 1:
72 # hashfilename = filename + '.hp'
74 # in_fh = codecs.open(hashfilename, 'r', 'utf8')
75 # whole_file = in_fh.read()
78 # testhash = eval(whole_file)
80 # hhc = importer.getCachedHHC()
81 # handlist = hhc.getProcessedHands()
82 # #We _really_ only want to deal with a single hand here.
83 # for hand in handlist:
84 # ghash = hand.stats.getHandsPlayers()
86 # #print "DEBUG: player: '%s'" % p
88 # teststat = testhash[p]
91 # #print "pstat[%s][%s]: %s == %s" % (p, stat, pstat[stat], teststat[stat])
93 # if pstat[stat] == teststat[stat]:
94 # # The stats match - continue
97 # # Stats don't match - Doh!
98 # errors.error_report(filename, hand, stat, ghash, testhash, p)
100 # errors.error_report(filename, False, "KeyError: '%s'" % stat, False, False, p)
102 errors
.error_report(filename
, False, "Parse", False, False, False)
104 importer
.clearFileList()
108 def walk_testfiles(dir, function
, importer
, errors
, site
):
109 """Walks a directory, and executes a callback on each file """
110 dir = os
.path
.abspath(dir)
111 for file in [file for file in os
.listdir(dir) if not file in [".",".."]]:
112 nfile
= os
.path
.join(dir,file)
113 if os
.path
.isdir(nfile
):
114 walk_testfiles(nfile
, compare
, importer
, errors
, site
)
116 print "***********************************"
117 compare(nfile
, importer
, errors
, site
)
118 print "***********************************"
124 Configuration
.set_logfile("fpdb-log.txt")
125 (options
, argv
) = Options
.fpdb_options()
127 test_all_sites
= True
129 if options
.usage
== True:
132 single_file_test
= False
135 options
.sitename
= Options
.site_alias(options
.sitename
)
136 if options
.sitename
== False:
139 print "Testing single hand: '%s'" % options
.filename
140 single_file_test
= True
142 print "Only regression testing '%s' files" % (options
.sitename
)
143 test_all_sites
= False
145 config
= Configuration
.Config(file = "HUD_config.test.xml")
146 db
= Database
.Database(config
)
147 sql
= SQL
.Sql(db_server
= 'sqlite')
150 importer
= SummaryImporter(config
, sql
, None)
152 PokerStarsErrors
= FpdbError('PokerStars')
153 FTPErrors
= FpdbError('Full Tilt Poker')
154 #PartyPokerErrors = FpdbError('Party Poker')
155 #BetfairErrors = FpdbError('Betfair')
156 #OnGameErrors = FpdbError('OnGame')
157 #AbsoluteErrors = FpdbError('Absolute Poker')
158 #UltimateBetErrors = FpdbError('Ultimate Bet')
159 #EverleafErrors = FpdbError('Everleaf Poker')
160 MergeErrors
= FpdbError('Merge')
161 #PKRErrors = FpdbError('PKR')
162 iPokerErrors
= FpdbError('iPoker')
163 #WinamaxErrors = FpdbError('Winamax')
166 PokerStarsErrors
, FTPErrors
, #WinamaxErrors,
167 MergeErrors
, iPokerErrors
,
169 #BetfairErrors, OnGameErrors, AbsoluteErrors,
170 #EverleafErrors, PKRErrors,
175 'PokerStars' : False,
176 'Full Tilt Poker' : False,
177 #'PartyPoker' : True,
181 #'UltimateBet' : True,
189 if test_all_sites
== True:
193 sites
[options
.sitename
] = True
195 if sites
['PokerStars'] == True and not single_file_test
:
196 walk_testfiles("regression-test-files/summaries/Stars/", compare
, importer
, PokerStarsErrors
, "PokerStars")
197 elif sites
['PokerStars'] == True and single_file_test
:
198 walk_testfiles(options
.filename
, compare
, importer
, PokerStarsErrors
, "PokerStars")
199 if sites
['Full Tilt Poker'] == True and not single_file_test
:
200 walk_testfiles("regression-test-files/summaries/FTP/", compare
, importer
, FTPErrors
, "Full Tilt Poker")
201 elif sites
['Full Tilt Poker'] == True and single_file_test
:
202 walk_testfiles(options
.filename
, compare
, importer
, FTPErrors
, "Full Tilt Poker")
203 #if sites['PartyPoker'] == True:
204 # walk_testfiles("regression-test-files/cash/PartyPoker/", compare, importer, PartyPokerErrors, "PartyPoker")
205 # walk_testfiles("regression-test-files/tour/PartyPoker/", compare, importer, PartyPokerErrors, "PartyPoker")
206 #if sites['Betfair'] == True:
207 # walk_testfiles("regression-test-files/cash/Betfair/", compare, importer, BetfairErrors, "Betfair")
208 #if sites['OnGame'] == True:
209 # walk_testfiles("regression-test-files/cash/OnGame/", compare, importer, OnGameErrors, "OnGame")
210 #if sites['Absolute'] == True:
211 # walk_testfiles("regression-test-files/cash/Absolute/", compare, importer, AbsoluteErrors, "Absolute")
212 #if sites['UltimateBet'] == True:
213 # walk_testfiles("regression-test-files/cash/UltimateBet/", compare, importer, UltimateBetErrors, "Absolute")
214 #if sites['Everleaf'] == True:
215 # walk_testfiles("regression-test-files/cash/Everleaf/", compare, importer, EverleafErrors, "Everleaf")
216 if sites
['Merge'] == True:
217 walk_testfiles("regression-test-files/cash/Merge/", compare
, importer
, MergeErrors
, "Merge")
218 #if sites['PKR'] == True:
219 # walk_testfiles("regression-test-files/cash/PKR/", compare, importer, PKRErrors, "PKR")
220 if sites
['iPoker'] == True:
221 walk_testfiles("regression-test-files/tour/iPoker/", compare
, importer
, iPokerErrors
, "iPoker")
222 #if sites['Winamax'] == True:
223 # walk_testfiles("regression-test-files/summaries/Winamax/", compare, importer, WinamaxErrors, "Winamax")
227 for i
, site
in enumerate(ErrorsList
):
228 totalerrors
+= ErrorsList
[i
].errorcount
230 print "---------------------"
231 print "Total Errors: %d" % totalerrors
232 print "---------------------"
233 for i
, site
in enumerate(ErrorsList
):
234 ErrorsList
[i
].print_histogram()
236 # Merge the dicts of stats from the various error objects
238 for i
, site
in enumerate(ErrorsList
):
239 tmp
= ErrorsList
[i
].statcount
242 statdict
[stat
] += tmp
[stat
]
244 statdict
[stat
] = tmp
[stat
]
247 print "---------------------"
248 print "Errors by stat:"
249 print "---------------------"
250 #for stat in statdict:
251 # print "(%3d) : %s" %(statdict[stat], stat)
253 sortedstats
= sorted([(value
,key
) for (key
,value
) in statdict
.items()])
254 for num
, stat
in sortedstats
:
255 print "(%3d) : %s" %(num
, stat
)
258 if __name__
== '__main__':