2013-09-15 16:33:43 |
Thomi Richards |
description |
The select_many method raises an exception when it cannot find any objects that match the specified criteria. select_single, however, returns None. This leads to ugly test code like this:
foo = self.app.select_single('SomeWidget')
self.assertThat(foo, NotEquals(None))
bar = foo.select_single('SomeOtherWidget')
self.assertThat(bar, NotEquals(None))
If we made select_single raise the same exception as select_many, these assertion lines wouldn't be needed any more. |
The select_many method returns an empty list when it cannot find any objects that match the specified criteria. This means we get an IndexError exception when test authors write code like this:
thing1, thing2 = app.select_many('Things')
When select_many returns an unexpected number of items, this causes the test to fail (although we should probably be more explicit in the case where nothing was returned.)
select_single, however, returns None. This leads to ugly test code like this:
foo = self.app.select_single('SomeWidget')
self.assertThat(foo, NotEquals(None))
bar = foo.select_single('SomeOtherWidget')
self.assertThat(bar, NotEquals(None))
If we made select_single raise the StateNotFoundError exception, these assertion lines wouldn't be needed any more. |
|