Updated tests for skillgenerator
This commit is contained in:
parent
3573752b6c
commit
b194422599
|
|
@ -1,9 +1,9 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
# Not actually part of the project; just easier to maintain everything here
|
||||
|
||||
import sys,os
|
||||
import sys,os,traceback
|
||||
try:
|
||||
import Blessings
|
||||
except:
|
||||
|
|
@ -25,6 +25,16 @@ except:
|
|||
"cleave":[],"on_hit_c":0,"attribute":0,"encaissement":0,"encaissement_dices":"","encaissement_result":0,
|
||||
"replace":-1,"add_to_all":0,"max_dices":-1,"player_name":""};"""
|
||||
|
||||
## Custom adders:
|
||||
lambda_flat_dices=lambda a: "@flat_dices[@flat_dices]=type({tab+1});\n@nb_flat_dices++;"
|
||||
|
||||
## Custom rerolls:
|
||||
|
||||
categories=['varname','Pretty name','nb_args','type','code','id','default','switch','return']
|
||||
hashedCategories={}
|
||||
for c in range(len(categories)):
|
||||
hashedCategories[categories[c]]=c
|
||||
|
||||
list=[]
|
||||
#list.append(['varname','Pretty name','nb_args','type','code','id','default','switch','return'])
|
||||
list.append(['perfection','Perfection',1,'int','P',0,0,None,None])
|
||||
|
|
@ -51,7 +61,7 @@ list.append(['action','Type d\'Action',1,'str','a',0,'""',None,None])
|
|||
list.append(['flat_dices','Des fixes',1,'int','d',0,"[]",lambda_flat_dices,None])
|
||||
list.append(['on_hit_c','Dégats a l\'impact critique',1,'int','H',0,0,None,None])
|
||||
list.append(['attribute','Caractéristique',1,'int','A',0,0,None,None])
|
||||
list.append(['encaissement','Encaissement',2,'int','S',0,0,,None,None])
|
||||
list.append(['encaissement','Encaissement',2,'int','S',0,0,None,None])
|
||||
list.append(['replace','Des de substitution',1,'int','L',0,-1,None,None])
|
||||
list.append(['add_to_all','Valeur d\'ajout aux des',1,'int','l',0,0,None,None])
|
||||
list.append(['max_dices','Nombre de des max',1,'int','m',0,-1,None,None])
|
||||
|
|
@ -66,19 +76,54 @@ list.append(['encaissement_result','Resultat d\'encaissement',1,'int','',0,0,Non
|
|||
list.append(['technique_result','Dégats technique martiale',1,'int','',0,0,None,None])
|
||||
list.append(['coup_d_results','Coup déchirant results',1,'int','',0,"[]",None,None])
|
||||
|
||||
class whateverWrapper():
|
||||
def __init__(self,table):
|
||||
class megaListWrapper():
|
||||
def __init__(self,table=list):
|
||||
self.table=table
|
||||
self.len=len(table)
|
||||
self.indexes={}
|
||||
for i in range(table):
|
||||
self.indexes[table[i]]=table[i][0]
|
||||
for i in range(len(table)):
|
||||
self.indexes[table[i][0]]=i
|
||||
|
||||
def __get__(self,argument): #Actually return the full line
|
||||
return self.table[self.indexes[argument]]
|
||||
## Custom adders:
|
||||
lambda_flat_dices=lambda_flat_dices a: "@flat_dices[@flat_dices]=type({tab+1});\n@nb_flat_dices++;"
|
||||
def __getitem__(self,argument): #Actually return the full line as a list wrapper
|
||||
return listWrapper(self.table[self.indexes[argument]])
|
||||
|
||||
## Custom rerolls:
|
||||
def __iter__(self):
|
||||
for index,key in self.indexes.items():
|
||||
yield self[index]
|
||||
|
||||
def __len__(self):
|
||||
return self.len
|
||||
|
||||
def pprint(self):
|
||||
for e in self:
|
||||
print(e[0],":",e)
|
||||
|
||||
class listWrapper():
|
||||
def __init__(self,list,index=hashedCategories):
|
||||
self.list=list
|
||||
self.indexes=index
|
||||
|
||||
def pprint(self):
|
||||
print(self.list)
|
||||
|
||||
def asList(self):
|
||||
return self.list
|
||||
|
||||
def __len__(self):
|
||||
return len(self.list)
|
||||
|
||||
def __repr__(self):
|
||||
return str(self.list)
|
||||
|
||||
def __getitem__(self,nb):
|
||||
return self.list[nb]
|
||||
|
||||
def __getattr__(self,index):
|
||||
return self.list[self.indexes[index]]
|
||||
|
||||
def __iter__(self):
|
||||
for e in self.list:
|
||||
yield e
|
||||
|
||||
## Commands
|
||||
def initialise(args):
|
||||
|
|
@ -135,28 +180,62 @@ def check_init(args):
|
|||
else:
|
||||
fails+=1
|
||||
print("Element invalid, {} is not in the test values".format(l))
|
||||
|
||||
if fails:
|
||||
print("{} errors occured")
|
||||
print("{} errors occured".format(fails))
|
||||
else:
|
||||
print("Init: All test sucessfull")
|
||||
print("Init: All test sucessful")
|
||||
return fails
|
||||
|
||||
def reroll(args):
|
||||
reroll="var msg_relance=\"<a class='sheet-rolltemplate-d10fight' href='!crit 0 "
|
||||
|
||||
|
||||
def check_reroll(args):
|
||||
pass
|
||||
|
||||
def check_wrapper(args):
|
||||
fails=0
|
||||
s=len(hashedCategories)
|
||||
|
||||
commands={"init":initialise,"print":pprint,"test_init":check_init}
|
||||
try:
|
||||
wrapper[-1]
|
||||
fails+=1
|
||||
print("Error: Element -1 shouldn't exist")
|
||||
except:
|
||||
pass
|
||||
for ele in wrapper:
|
||||
for c in hashedCategories.keys():
|
||||
if ele.__getattr__(c)!=ele[hashedCategories[c]]:
|
||||
print("Missmatch in {}, {} found, should be {}".format(ele[0],ele[hashedCategories[c]],ele.__getattr__(c)))
|
||||
|
||||
for i in range(s):
|
||||
if wrapper[ele[0]][i]!=ele.asList()[i] or wrapper[ele[0]][i]!=ele[i]:
|
||||
print("Element {} is not identical in all representation {}!={}".format(i,wrapper[ele[0]][i],ele.asList()[i]))
|
||||
fails+=1
|
||||
if fails:
|
||||
print("{} errors occured".format(fails))
|
||||
else:
|
||||
print("Wrapper: All test sucessful")
|
||||
return fails
|
||||
|
||||
|
||||
def test_all(args):
|
||||
check_init(args)
|
||||
check_reroll(args)
|
||||
check_wrapper(args)
|
||||
|
||||
commands={"init":initialise,"print":pprint,
|
||||
"test_init":check_init,"test_wrapper":check_wrapper,
|
||||
"test":test_all}
|
||||
|
||||
if __name__ == '__main__':
|
||||
wrapper=megaListWrapper()
|
||||
try:
|
||||
commands[command](args)
|
||||
except Exception,err:
|
||||
except Exception as err:
|
||||
print("Couldn't execute command "+command)
|
||||
print(err)
|
||||
print(" >",err)
|
||||
traceback.print_tb(sys.exc_info()[2])
|
||||
|
||||
"""
|
||||
var msg_relance="<a class='sheet-rolltemplate-d10fight' href='!crit 0 P "+d_vars.perfection+" I 0 "+d_vars.defense_i_0+" I 1 "+d_vars.defense_i_1+
|
||||
|
|
|
|||
Loading…
Reference in New Issue