ENH: adds expect_element preprocessor

This commit is contained in:
llllllllll
2015-10-19 16:35:03 -04:00
parent a7763673aa
commit 22ffe3fe49
2 changed files with 82 additions and 15 deletions
+22 -1
View File
@@ -6,7 +6,11 @@ from unittest import TestCase
from nose_parameterized import parameterized
from zipline.utils.preprocess import call, preprocess
from zipline.utils.input_validation import expect_types, optional
from zipline.utils.input_validation import (
expect_element,
expect_types,
optional,
)
def noop(func, argname, argvalue):
@@ -225,3 +229,20 @@ class PreprocessTestCase(TestCase):
"type int or NoneType for argument 'a', but got str instead."
).format(modname=foo.__module__)
self.assertEqual(e.exception.args[0], expected_message)
def test_expect_element(self):
@expect_element(a={'a', 'b'})
def f(a):
return a
self.assertEqual(f('a'), 'a')
self.assertEqual(f('b'), 'b')
with self.assertRaises(ValueError) as e:
f('c')
expected_message = (
"{modname}.f() expected a value in {{'a', 'b'}}"
" for argument 'a', but got 'c' instead."
).format(modname=f.__module__)
self.assertEqual(e.exception.args[0], expected_message)