Allowances/expectations on properties with setter
dariocc opened this issue · 1 comments
dariocc commented
class Foo(object):
@property
def bar(self):
pass
@bar.setter
def bar(self, value):
pass
def do_bar(foo):
foo.bar = 3
def test_bar_property():
foo = Foo()
allow(foo).bar
do_bar(foo)
Fails with AttributeError
. Besides, it is not possible to validate what was the value passed to the setter (with_args fails cannot be used with properties).
dariocc commented
Please, consider my question in https://stackoverflow.com/questions/54327367/expectation-on-property-getter-setter-in-python-with-doubles were I posted a workaround. The workaround allows doing state testing on the property, but not creating expectation (which would also be useful):
Something like:
allow(foo).bar
expect(foo).bar = 3
expect(foo).bar = 5
do_bar()
Or even better, some syntax that allow to create expectations and allowances on the setter just as for any other method:
allow(foo).bar.setter
expect(foo).bar.setter.with_args(3)
expect(foo).bar.setter.with_args(5)
do_bar()