Test PYSON statement


Is there way to test some PYSON statement with proteus or tryton-console?
An example somewhere?


What do you want to test?

Domain statement for example : If my writing are correct and understand why if it not correct

If it compiles, it is valid.

It might be valid but not correct for the purpose intended :slight_smile:

Here’s a quick session I did that checks an expression against a record

>>> from trytond.pyson import Eval, PYSONEncoder, PYSONDecoder
>>> from trytond.model.modelstorage import EvalEnvironment
>>> Party = pool.get('party.party')
>>> a = Party(1)
>>> env = EvalEnvironment(a, Party)
>>> b = Eval('name') == 'test'
>>> PYSONDecoder(env).decode(PYSONEncoder().encode(b))

I was almost there, I was just missing the EvalEnvironment, thank you @nicoe.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.