本文整理匯總了Python中ddt.unpack方法的典型用法代碼示例。如果您正苦於以下問題:Python ddt.unpack方法的具體用法?Python ddt.unpack怎麽用?Python ddt.unpack使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ddt
的用法示例。
在下文中一共展示了ddt.unpack方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _check_output
# 需要導入模塊: import ddt [as 別名]
# 或者: from ddt import unpack [as 別名]
def _check_output(self, inputs, column_values, **extra_values):
"""Compare generated with expected output."""
# Namedtuple objects need to be converted to lists on input.
inputs = [(type(inputval).__name__, list(inputval)) for inputval in inputs]
output = self._get_reducer_output(inputs)
if not isinstance(column_values, list):
column_values = [column_values]
self.assertEquals(len(output), len(column_values), '{0} != {1}'.format(output, column_values))
def record_sort_key(record):
"""Sort function for records, by order then by transaction."""
return record.order_line_item_id, record.transaction_id
sorted_output = sorted([OrderTransactionRecord.from_job_output(output_tuple[0]) for output_tuple in output],
key=record_sort_key)
for record, expected_columns in zip(sorted_output, column_values):
# This reducer does the packing in a different way, converting to TSV *before*
# putting into the output. So unpack that here, and output as a dict,
# so that column names can be used instead of numbers.
output_dict = record._asdict() # pylint: disable=no-member,protected-access
expected_columns.update(**extra_values)
for column_num, expected_value in expected_columns.iteritems():
self.assertEquals(output_dict[column_num], expected_value)
示例2: annotated_data
# 需要導入模塊: import ddt [as 別名]
# 或者: from ddt import unpack [as 別名]
def annotated_data(*args):
class List(list):
pass
new_args = []
for arg in args:
new_arg = List(arg)
new_arg.__name__ = arg[0]
new_args.append(new_arg)
return lambda func: data(*new_args)(unpack(func))
示例3: combine
# 需要導入模塊: import ddt [as 別名]
# 或者: from ddt import unpack [as 別名]
def combine(**kwargs):
"""Decorator to create combinations and tests
@combine(level=[0, 1, 2, 3],
circuit=[a, b, c, d],
dsc='Test circuit {circuit.__name__} with level {level}',
name='{circuit.__name__}_level{level}')
"""
def deco(func):
return data(*generate_cases(docstring=func.__doc__, **kwargs))(unpack(func))
return deco