mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-08 11:16:58 +08:00
ENH: adds expect_element preprocessor
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user