openerp-expert-framework team mailing list archive
-
openerp-expert-framework team
-
Mailing list archive
-
Message #00613
Asserting exceptions in YAML tests
Dear all,
this is a followup to a thread that's been started on the community
mailing-list. Olivier Dony suggested in reply to switch to the
expert-framework list.
Here's an extract of that discussion (toplevel is Olivier) :
> On 08/28/2011 02:19 PM, Georges Racinet wrote:
>> > To say it quickly, I'm thinking of an analog of unittest's assertRaises
>> > (http://docs.python.org/library/unittest.html#unittest.TestCase.assertRaises)
> You're right, there's currently no provision for assertRaises-like tests
> in YAML, except via a custom !python block with a try/except, as you noted. (...)
> That would certainly be a welcome contribution! (...)
I did a quick proof-of-concept to fix ideas. The main decision was
whether this should be a new YAML tag or not.
I found that making a new tag would require some more boiler-plate, and
duplicate most of yaml_import.py's process_python(). Therefore, I
preferred to add an 'assert_raises' option to the existing !python tag.
This has the drawback of adding complexity to process_python(),
especially in the exception handling blocks.
This gives us YAML blocks such as this one :
!python {model: ir.model, assert_raises: lxml.etree.ParseError}: |
from lxml.etree import fromstring
fromstring('definitely not valid xml !')
What do you think of this approach ?
I'm wondering how to unit-test that. Are there plans to unit-test
somehow yaml imports ?
Also, we still have a problem in our use case (cursor rollbacks in
osv.orm) that I'd prefer to discuss later.
Builtin exceptions can be used directly as values for 'assert_raises'.
Other ones (such as lxm.etree.ParseError) go through a resolver that I
borrowed from somewhere eles in the proof-of-concept. It might be useful
to add some frequent OpenObject exceptions for direct use, such as
orm_except and the likes.
The proof-of-concept is at lp:~anybox/openobject-server/assert_raises_poc/
It's not meant to be up to the contribution guidelines, I'd rather drop
it and start over cleanly.
The extract above is actually in the branch in openerp/assert_raises.yml
Regards,
--
Georges Racinet
Anybox SAS, http://anybox.fr
Follow ups