2011-04-26 23:04:28 +00:00
|
|
|
|
2011-04-27 13:00:50 +00:00
|
|
|
import sys
|
|
|
|
|
2011-04-27 11:30:11 +00:00
|
|
|
from pokedex.db import connect
|
2011-04-26 23:04:28 +00:00
|
|
|
from pokedex.util.movesets import main
|
|
|
|
|
2011-04-27 13:00:50 +00:00
|
|
|
testcase_args = u"""
|
|
|
|
NO muk
|
|
|
|
NO beedrill rage pursuit agility endeavor toxic
|
|
|
|
NO ditto psystrike aeroblast mist-ball judgment
|
|
|
|
OK metapod tackle harden
|
|
|
|
OK lugia aeroblast punishment dive snore
|
|
|
|
OK yanmega bug-bite bug-buzz tackle whirlwind
|
|
|
|
OK crobat brave-bird quick-attack gust zen-headbutt
|
|
|
|
OK bagon defense-curl fire-fang hydro-pump shadow-claw
|
|
|
|
OK volcarona endure toxic fly fire-blast
|
|
|
|
OK hippopotas curse revenge sleep-talk swallow
|
|
|
|
OK hippopotas curse revenge sleep-talk snore
|
|
|
|
OK smeargle bug-bite bug-buzz splash fire-blast
|
|
|
|
NO smeargle bug-bite chatter splash fire-blast
|
|
|
|
NO azurill muddy-water iron-tail scald mimic
|
|
|
|
OK salamence dragon-dance dragon-claw fire-blast earthquake -v platinum
|
|
|
|
OK crawdaunt brick-break rock-slide facade toxic -v platinum
|
|
|
|
NO cleffa tickle wish amnesia splash
|
|
|
|
OK tyrogue pursuit
|
|
|
|
NO happiny softboiled
|
|
|
|
NO mamoswine bite body-slam curse double-edge
|
|
|
|
OK shedinja swords-dance
|
|
|
|
NO shedinja swords-dance screech
|
2011-04-27 15:00:35 +00:00
|
|
|
OK shedinja baton-pass grudge
|
2011-04-27 13:00:50 +00:00
|
|
|
OK shedinja screech double-team fury-cutter x-scissor
|
|
|
|
OK raichu volt-tackle
|
|
|
|
OK raichu surf -v gold
|
|
|
|
OK pikachu volt-tackle thunderbolt bide
|
|
|
|
OK gyarados flail thrash iron-head outrage
|
|
|
|
OK drifblim memento gust thunderbolt pain-split
|
|
|
|
OK crobat nasty-plot brave-bird
|
|
|
|
NO crobat nasty-plot hypnosis
|
|
|
|
OK garchomp double-edge thrash outrage
|
|
|
|
OK nidoking counter disable amnesia head-smash
|
|
|
|
OK aggron stomp smellingsalt screech fire-punch
|
|
|
|
OK tyranitar dragon-dance outrage thunder-wave surf
|
|
|
|
NO butterfree morning-sun harden
|
|
|
|
OK pikachu reversal bide nasty-plot discharge
|
|
|
|
NO pikachu surf charge
|
|
|
|
NO blissey wish counter
|
|
|
|
NO clefairy copycat dynamicpunch
|
|
|
|
"""
|
|
|
|
|
2011-04-26 23:04:28 +00:00
|
|
|
result_map = {'OK': True, 'NO': False}
|
|
|
|
|
|
|
|
def test_cases():
|
2011-04-27 11:30:11 +00:00
|
|
|
session = connect()
|
2011-04-27 13:00:50 +00:00
|
|
|
for argstring in testcase_args.strip().splitlines():
|
2011-04-26 23:04:28 +00:00
|
|
|
def run_test(argstring):
|
2011-04-27 13:00:50 +00:00
|
|
|
args = argstring.split() + ['-q']
|
|
|
|
assert bool(main(args[1:], session=session)) == result_map[args[0]]
|
2011-04-26 23:04:28 +00:00
|
|
|
run_test.description = 'Moveset checker test: ' + argstring.strip()
|
2011-04-27 01:58:15 +00:00
|
|
|
yield run_test, argstring.strip()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2011-04-27 13:00:50 +00:00
|
|
|
# Nose's default profiler, the unmaintained hotshot, sucks.
|
|
|
|
# Use cProfile instead.
|
2011-04-27 01:58:15 +00:00
|
|
|
filename = 'movesets.profile'
|
|
|
|
print 'Profiling the moveset checker'
|
|
|
|
import cProfile
|
2011-04-27 13:00:50 +00:00
|
|
|
ok_fail = [0, 0]
|
|
|
|
def run_case(f, argv):
|
|
|
|
print argv, '...',
|
|
|
|
sys.stdout.flush()
|
|
|
|
try:
|
|
|
|
f(argv)
|
|
|
|
ok_fail[0] += 1
|
|
|
|
print 'ok'
|
|
|
|
except AssertionError:
|
|
|
|
ok_fail[1] += 1
|
|
|
|
print 'FAIL'
|
|
|
|
cases = list(test_cases())
|
|
|
|
cProfile.runctx("[(run_case(f, argv)) for f, argv in cases]",
|
2011-04-27 01:58:15 +00:00
|
|
|
globals(), locals(), filename=filename)
|
2011-04-27 15:00:35 +00:00
|
|
|
if ok_fail[1]:
|
|
|
|
print '*** FAILED ***'
|
|
|
|
print "{0} tests: {1[0]} OK, {1[1]} failed".format(sum(ok_fail), ok_fail)
|
|
|
|
else:
|
|
|
|
print "{0} tests: OK".format(sum(ok_fail), ok_fail)
|
2011-04-27 01:58:15 +00:00
|
|
|
print 'Profile stats saved to', filename
|