ENH: Include choices in no-output-found errormsg.

This commit is contained in:
Scott Sanderson
2016-05-13 19:42:44 -04:00
parent 2d596dc490
commit 4a513360b6
2 changed files with 11 additions and 6 deletions
+6 -4
View File
@@ -457,14 +457,16 @@ class ObjectIdentityTestCase(TestCase):
errmsg, "'SomeFactor' object has no attribute 'not_an_attr'",
)
mo = MultipleOutputs()
with self.assertRaises(AttributeError) as e:
MultipleOutputs().not_an_attr
mo.not_an_attr
errmsg = str(e.exception)
self.assertEqual(
errmsg,
"Instance of MultipleOutputs has no output called 'not_an_attr'.",
expected = (
"Instance of MultipleOutputs has no output named 'not_an_attr'."
" Possible choices are: ('alpha', 'beta')."
)
self.assertEqual(errmsg, expected)
with self.assertRaises(ValueError) as e:
alpha, beta = GenericCustomFactor()
+5 -2
View File
@@ -1209,8 +1209,11 @@ class CustomFactor(PositiveWindowLengthMixin, CustomTermMixin, Factor):
return RecarrayField(factor=self, attribute=attribute_name)
else:
raise AttributeError(
'Instance of {factor} has no output called {attr!r}.'.format(
factor=type(self).__name__, attr=attribute_name,
'Instance of {factor} has no output named {attr!r}.'
' Possible choices are: {choices}.'.format(
factor=type(self).__name__,
attr=attribute_name,
choices=self.outputs,
)
)