[Bf-python] Re: Proposal for Blender Python test suite

ChrisKeith at aol.com ChrisKeith at aol.com
Sun Aug 8 19:59:47 CEST 2004


Hello Willian and all -

>> Sorry for taking long...

No  problem!

>> About rounding floats, it's trivial but we should try  to get the
>> precision defined in a single module file, so we just  have to change one
>> place to try with a different value.

I already tried just rounding, and I'd still end up with values displaying  
like this:
 
1.000000000001
 
I therefore wrote a little series of functions to use "printf"  formatting to 
do the work.
I called the primary function "roundRepr" because it does  (or tries to do) 
the
same thing that "repr" does, but adds "rounding".  We can set the  precision
in the eval call in "roundReprFloat":
 
from types import *
 
def roundReprFloat(v):
return eval("'%1.6f' %  v")
 
def roundSeq(v):
ret = ""
i =  0
for val in  v:
if i >  0:
ret =  ret + ","
ret = ret +  roundRepr(val)
i = i +  1
return ret

def  roundDict(v):
ret = ""
i =  0
for k, val in  v.iteritems():
if i >  0:
ret =  ret + ","
ret = ret + "(" +  roundRepr(k) + ":" + roundRepr(val) +  ")"
i = i +  1
return ret

def  roundRepr(v):
if type(v) is  FloatType:
return  roundReprFloat(v)
elif type(v) is  ListType:
return "[" + roundSeq(v)  + "]"
elif type(v) is  TupleType:
return "(" +  roundSeq(v) + ")"
elif type(v) is  DictType:
return "{" +  roundDict(v) + "}"
else:
return repr(v)

>> The first step is working on the tests themselves, using  'exec' where
>> possible to avoid writing too much.
 
Do you want to start with the ones that are already there?
I had to change a couple of them, but they are in that ZIP file.

>>With an extra script in the dir we can automate the loading  (and packing of
>> all test files inside a .blend), by using  Blender.Text.Load() commands to
>> load all tests at once.  The  script can link all the tests as scene Redraw
>> scriptlinks for  example, then redraw to run the tests (that will write the
>> output  files) and leave Blender.
 
Is there an advantage to doing this over using the -P switch?
 
Thanks,
Chris Keith



More information about the Bf-python mailing list