fakeldap
fakeldap copied to clipboard
Returning exceptions
Has consideration been given to allowing tests to pass in an exception to return? E.g.
self.mock_ldap.set_return_value( "simple_bind_s", ("cn=admin,dc=mgb,dc=org", "ldaptest"), ldap.SERVER_DOWN )
I haven't thought about this (though maybe the original maintainer did -- we have mostly done bug fixes and Python version support updates since adopting the project). I would try to follow the patterns of the Python mock
library for this sort of thing; and so I wouldn't conflate a return value (returning an exception object) with raising an exception in the syntax. See https://docs.python.org/3/library/unittest.mock.html ; I think we probably would want to call this side_effect
.
Patches that come with tests are welcome!
Yes, of course. I’ve used that pattern for this type of testing in the past.
Ok, if time allows, I’ll put something together and submit a PR. Thanks!
On Mar 4, 2021, at 7:16 PM, Tim Abbott [email protected] wrote:
I haven't thought about this (though maybe the original maintainer did -- we have mostly done bug fixes and Python version support updates since adopting the project). I would try to follow the patterns of the Python mock library for this sort of thing; and so I wouldn't conflate a return value (returning an exception object) with raising an exception in the syntax. See https://docs.python.org/3/library/unittest.mock.html https://docs.python.org/3/library/unittest.mock.html ; I think we probably would want to call this side_effect.
Patches that come with tests are welcome!
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/zulip/fakeldap/issues/23#issuecomment-791046686, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAK4Q5D3PCD44NPLHRUQVPLTCAPEVANCNFSM4YUCX55A.