Method to separate unit-test methods and data?
gagsl-py2 at yahoo.com.ar
Mon Jul 6 08:46:33 CEST 2009
En Sun, 05 Jul 2009 15:48:06 -0300, Nick Daly <nick.m.daly at gmail.com>
> none_values = ((-1, None),
> (None, -12.8))
> What I haven't yet figured out how to do though, is properly override
> the default class member values with values from the config file. The
> config file's data is loaded as a string instead of as a list, as I'd
> want. This causes all the tests to fail, as while none_values needs
> to be interpreted as a list, it is instead understood as:
> " ((-1, None),\n (None, -12.8))"
> Does anyone have any solutions for these problems?
You may use a .py file to configure it, instead of your .cfg
> First, is there a
> known and simple way to separate unit-test data and methods into
> separate files?
Just write them in separate files? I didn't quite understand the
> Secondly, if not, is there a simple way to convert
> strings into other base types, like lists, dictionaries, and so forth?
eval(), but I'd just use a .py file
People usually warns against using eval on arbitrary strings, or on
user-supplied data, but in this case it is not worse than
importing/executing the module.
> Or, am I going to have to write my own list-parsing methods? Would
> pickling help? I haven't yet had a chance to look into if or how that
> would work... If there's anything else I can clarify about this
> request, feel free to let me know.
Another alternative would be a .csv file; I use them when the test data
comes from other parties, like a manufacturer's data sheet.
I've never used a pickle to store test data - how do you generate the
pickle contents in the first place? Usually I'd just use *that* code
directly, but I think pickling the resulting objects would be OK is the
process to regenerate them takes a lot of time.
More information about the Python-list