本文整理汇总了Python中absl.testing.parameterized.named_parameters方法的典型用法代码示例。如果您正苦于以下问题:Python parameterized.named_parameters方法的具体用法?Python parameterized.named_parameters怎么用?Python parameterized.named_parameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类absl.testing.parameterized
的用法示例。
在下文中一共展示了parameterized.named_parameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: named_parameters
# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import named_parameters [as 别名]
def named_parameters(ls):
"""A version that allows an empty param list."""
def noop(_):
def wrapper(self, *args, **kwargs):
self.skipTest("Empty parameter list")
return wrapper
if isinstance(ls, (list, tuple)) and not ls:
return noop
if isinstance(ls, itertools.chain):
try:
first = next(ls)
except StopIteration:
return noop
else:
ls = itertools.chain([first], ls)
return parameterized.named_parameters(ls)
# TODO(wangpeng): Enable all disabled tests in this class
示例2: named_parameters
# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import named_parameters [as 别名]
def named_parameters(*testcases):
"""A decorator for creating parameterized tests.
See the module docstring for a usage example. For every parameter tuple
passed, the first element of the tuple should be a string and will be appended
to the name of the test method. Each parameter dict passed must have a value
for the key "testcase_name", the string representation of that value will be
appended to the name of the test method.
Args:
*testcases: Parameters for the decorated method, either a single iterable,
or a list of tuples or dicts.
Raises:
NoTestsError: Raised when the decorator generates no tests.
Returns:
A test generator to be handled by TestGeneratorMetaclass.
"""
return _parameter_decorator(_NAMED, testcases)
示例3: multiple_named_parameters
# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import named_parameters [as 别名]
def multiple_named_parameters(*param_lists):
result = param_lists[0]
for param_list in param_lists[1:]:
result = [(name1 + ', ' + name2, *args1, *args2)
for name1, *args1 in result
for name2, *args2 in param_list]
return parameterized.named_parameters(*result)
示例4: cross_named_parameters
# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import named_parameters [as 别名]
def cross_named_parameters(*args):
"""Cross a list of lists of dicts suitable for @named_parameters.
Takes a list of lists, where each list is suitable as an input to
@named_parameters, and crosses them, forming a new name for each crossed test
case.
Args:
*args: A list of lists of dicts.
Returns:
A list of dicts.
"""
def _cross_test_cases(parameters_list):
"""Cross a list of test case parameters."""
crossed_parameters = parameters_list[0].copy()
for current_parameters in parameters_list[1:]:
for name, value in current_parameters.items():
if name == 'testcase_name':
crossed_parameters[name] = '{}_{}'.format(
crossed_parameters[name], value)
else:
assert name not in crossed_parameters, name
crossed_parameters[name] = value
return crossed_parameters
return list(map(_cross_test_cases, itertools.product(*args)))
示例5: cross_with_function_handlers
# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import named_parameters [as 别名]
def cross_with_function_handlers(parameters_list):
"""Cross named parameters with all function handlers.
Takes a list of parameters suitable as an input to @named_parameters,
and crosses it with the set of function handlers.
A parameterized test function that uses this should have a parameter named
`function_handler`.
Args:
parameters_list: A list of dicts.
Returns:
A list of dicts.
"""
return cross_named_parameters(parameters_list, FUNCTION_HANDLERS)
示例6: __init__
# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import named_parameters [as 别名]
def __init__(self, test_class_name, new_test_name, original_test_name):
super(DuplicateTestNameError, self).__init__(
'Duplicate parameterized test name in {}: generated test name {!r} '
'(generated from {!r}) already exists. Consider using '
'named_parameters() to give your tests unique names and/or renaming '
'the conflicting test method.'.format(
test_class_name, new_test_name, original_test_name))
示例7: dict_decorator
# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import named_parameters [as 别名]
def dict_decorator(key, value):
"""Sample implementation of a chained decorator.
Sets a single field in a dict on a test with a dict parameter.
Uses the exposed '_ParameterizedTestIter.testcases' field to
modify arguments from previous decorators to allow decorator chains.
Args:
key: key to map to
value: value to set
Returns:
The test decorator
"""
def decorator(test_method):
# If decorating result of another dict_decorator
if isinstance(test_method, abc.Iterable):
actual_tests = []
for old_test in test_method.testcases:
# each test is a ('test_suffix', dict) tuple
new_dict = old_test[1].copy()
new_dict[key] = value
test_suffix = '%s_%s_%s' % (old_test[0], key, value)
actual_tests.append((test_suffix, new_dict))
test_method.testcases = actual_tests
return test_method
else:
test_suffix = ('_%s_%s') % (key, value)
tests_to_make = ((test_suffix, {key: value}),)
# 'test_method' here is the original test method
return parameterized.named_parameters(*tests_to_make)(test_method)
return decorator
示例8: test_duplicate_named_test_fails
# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import named_parameters [as 别名]
def test_duplicate_named_test_fails(self):
with self.assertRaises(parameterized.DuplicateTestNameError):
class _(parameterized.TestCase):
@parameterized.named_parameters(
('Interesting', 0),
('Interesting', 1),
)
def test_something(self, unused_obj):
pass
示例9: test_duplicate_dict_named_test_fails
# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import named_parameters [as 别名]
def test_duplicate_dict_named_test_fails(self):
with self.assertRaises(parameterized.DuplicateTestNameError):
class _(parameterized.TestCase):
@parameterized.named_parameters(
{'testcase_name': 'Interesting', 'unused_obj': 0},
{'testcase_name': 'Interesting', 'unused_obj': 1},
)
def test_dict_something(self, unused_obj):
pass
示例10: test_named_test_with_no_name_fails
# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import named_parameters [as 别名]
def test_named_test_with_no_name_fails(self):
with self.assertRaises(RuntimeError):
class _(parameterized.TestCase):
@parameterized.named_parameters(
(0,),
)
def test_something(self, unused_obj):
pass
示例11: test_named_test_dict_with_no_name_fails
# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import named_parameters [as 别名]
def test_named_test_dict_with_no_name_fails(self):
with self.assertRaises(RuntimeError):
class _(parameterized.TestCase):
@parameterized.named_parameters(
{'unused_obj': 0},
)
def test_something(self, unused_obj):
pass
示例12: test_cases
# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import named_parameters [as 别名]
def test_cases():
return parameterized.named_parameters(
dict(testcase_name='_observation_[5]_action_[3]_batch_1',
observation_shape=[5],
action_shape=[3],
batch_size=1,
seed=12345),
dict(testcase_name='_observation_[3]_action_[5]_batch_2',
observation_shape=[3],
action_shape=[5],
batch_size=2,
seed=98765),
)
示例13: test_cases
# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import named_parameters [as 别名]
def test_cases():
return parameterized.named_parameters(
{
'testcase_name': '_batch1_contextdim10',
'batch_size': 1,
'context_dim': 10,
}, {
'testcase_name': '_batch4_contextdim5',
'batch_size': 4,
'context_dim': 5,
})
示例14: cg_test_cases
# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import named_parameters [as 别名]
def cg_test_cases():
return parameterized.named_parameters(
{
'testcase_name': '_n_1',
'n': 1,
'rhs': 1,
}, {
'testcase_name': '_n_10',
'n': 10,
'rhs': 1,
}, {
'testcase_name': '_n_100',
'n': 100,
'rhs': 5,
})
示例15: test_cases
# 需要导入模块: from absl.testing import parameterized [as 别名]
# 或者: from absl.testing.parameterized import named_parameters [as 别名]
def test_cases():
return parameterized.named_parameters(
{
'testcase_name': '_batch1_numtrainsteps0',
'batch_size': 1,
'actions_from_reward_layer': False,
}, {
'testcase_name': '_batch4_numtrainsteps10',
'batch_size': 4,
'actions_from_reward_layer': True,
})