def __init__( self, raised_exception, expected_exceptions, pattern=None, func=None, description=None, category=None, ): expected_exceptions = make_tuple(expected_exceptions) assert expected_exceptions, "`expected_exceptions` cannot be empty." assert [ issubclass(exc, Exception) for exc in expected_exceptions ], "items in `expected_exceptions` must be subclass of `Exception` ." if func: assert callable(func), "`func` must be a callable." if pattern: assert isinstance( pattern, str), "`pattern` must be of string type, it was: {}".format( type(pattern)) self.raised_exception = raised_exception self.expected_exceptions = expected_exceptions self.pattern = pattern self.func = func # These will be set by `evaluate` self.exception_match = None self.pattern_match = None self.func_match = None super(ExceptionRaised, self).__init__(description=description, category=category)
def _generate_kwarg_list(parameters, args, required_args, default_args): """ Given the 'raw' parameter context, generate the ``list`` of ``kwargs`` that will be used for method generation. Always returns a list of ``OrderedDict``s regardless of the input type(s). """ # Combinatorial parametrization if isinstance(parameters, dict): _check_dict_keys(parameters, args, required_args) default_args = {k: [v] for k, v in default_args.items()} parameters = dict(default_args, **parameters) return _product_of_param_dict(parameters, args) # Normal parametrization elif isinstance(parameters, collections.Iterable): dicts = [] for obj in parameters: if not isinstance(obj, (tuple, list, dict)): if len(required_args) > 1: raise ParametrizationError( "You can use shortcut notation if and only if the" " testcase has 1 required argument, however" " it has {}".format(len(required_args)) ) obj = convert.make_tuple(obj, convert_none=True) if isinstance(obj, (list, tuple)): dicts.append( _dict_from_arg_tuple( obj, args, required_args, default_args ) ) elif isinstance(obj, dict): ordered_dict = collections.OrderedDict.fromkeys(args) ordered_dict.update(dict(default_args, **obj)) dicts.append( _check_dict_keys(ordered_dict, args, required_args) ) return dicts msg = ( '"parameters" should either be a dictionary of iterables with keys ' "matching method arg names or a list of tuples/lists/dicts that have " "corresponding positional/keyword argument values or a list " "of non-tuple, non-dict single arguments (shortcut notation)." ' Invalid type: {} for "{}"' ) raise ParametrizationError(msg.format(type(parameters), parameters))
def __init__(self, sort_type=SortType.ALL): self.sort_types = set(make_tuple(SortType.validate(sort_type))) self.sort_all = SortType.ALL.value in self.sort_types