ENH: adds optionally for preprocessors

This commit is contained in:
Joe Jevnik
2016-01-13 15:26:37 -05:00
parent 220cf1ae4e
commit 5351b60a4c
2 changed files with 61 additions and 1 deletions
+20
View File
@@ -17,6 +17,7 @@ from zipline.utils.input_validation import (
expect_dtypes,
expect_types,
optional,
optionally,
)
@@ -347,3 +348,22 @@ class PreprocessTestCase(TestCase):
# test invalid timezone strings
for tz in invalid:
self.assertRaises(pytz.UnknownTimeZoneError, f, tz)
def test_optionally(self):
error = TypeError('arg must be int')
def preprocessor(func, argname, arg):
if not isinstance(arg, int):
raise error
return arg
@preprocess(a=optionally(preprocessor))
def f(a):
return a
self.assertIs(f(1), 1)
self.assertIsNone(f(None))
with self.assertRaises(TypeError) as e:
f('a')
self.assertIs(e.exception, error)