forked from iteratedecks/fansiteSubmission
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestRepo.py
More file actions
37 lines (33 loc) · 1.44 KB
/
testRepo.py
File metadata and controls
37 lines (33 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import urllib2
import json
import os
def updateTests(dataDirectory = "", filename = "tests.json", url = "http://haileon.com/SimTyrantJS_ListTestCases"):
fileDest = dataDirectory + filename
print("Getting " + url + " ...")
resp = urllib2.urlopen(url=url)
contents = resp.read()
print("Saving " + fileDest + " ...")
with open(fileDest, 'wb') as f:
f.write(contents)
return contents
def loadTests(forceUpdate = False, dataDirectory = "", filename = "tests.json", url = "http://haileon.com/SimTyrantJS_ListTestCases"):
data = None
if(not forceUpdate):
fileDest = os.path.join(dataDirectory, filename)
if(os.path.exists(fileDest)):
with open(fileDest, 'rb') as f:
data = f.read()
if(data is None):
data = updateTests(dataDirectory, filename, url)
json_data = json.loads(data)
decks = json_data["decks"]
return decks
def printTestFailure(expected, actual, key, comment):
print("TEST FAILED on " + key + " (" + str(expected) + " vs. " + str(actual) + "): " + comment)
def testKey(deck, key, actual, threshold = 8):
if(key in deck):
expected = deck[key]
if((expected == 100 or expected == 0) and expected != actual):
printTestFailure(expected, actual, key, deck["comments"])
elif((expected + threshold) < actual or (expected - threshold) > actual):
printTestFailure(expected, actual, key, deck["comments"])