Merge pull request #1204 from quantopian/tell-me-what-my-choices-were

Tell me what my choices were
This commit is contained in:
Scott Sanderson
2016-05-19 18:52:04 -04:00
2 changed files with 13 additions and 9 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()
+7 -5
View File
@@ -1,7 +1,7 @@
"""
factor.py
"""
from functools import partial, wraps
from functools import wraps
from operator import attrgetter
from numbers import Number
@@ -1212,8 +1212,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,
)
)
@@ -1224,8 +1227,7 @@ class CustomFactor(PositiveWindowLengthMixin, CustomTermMixin, Factor):
factor=type(self).__name__,
)
)
RecarrayField_ = partial(RecarrayField, self)
return iter(map(RecarrayField_, self.outputs))
return (RecarrayField(self, attr) for attr in self.outputs)
class RecarrayField(SingleInputMixin, Factor):