def _has_correct_input_type(self, feature): '''Check that `input` is a string or iterable of string''' input = feature.input is_str = funcy.isa(str) is_nested_str = funcy.all_fn( funcy.iterable, lambda x: all(map(is_str, x))) assert is_str(input) or is_nested_str(input)
def _categorize_file_diffs(self): '''Partition file changes into admissible and inadmissible changes''' if self.file_diffs is None: raise UnexpectedValidationStateError( 'File changes have not been collected.') logger.info('Categorizing file changes...') self.file_diffs_admissible = [] self.file_diffs_inadmissible = [] def is_appropriate_change_type(diff): '''File change is an addition''' return diff.change_type in \ PullRequestFeatureValidator.APPROPRIATE_CHANGE_TYPES def within_contrib_subdirectory(diff): '''File addition is a subdirectory of project's contrib dir''' path = diff.b_path contrib_relpath = self.contrib_module_path try: return pathlib.Path(contrib_relpath) in \ pathlib.Path(path).parents except Exception: return False def is_appropriate_file_ext(diff): '''File change is a python file''' path = diff.b_path try: for ext in PullRequestFeatureValidator.APPROPRIATE_FILE_EXTS: if path.endswith(ext): return True return False except Exception: return False is_admissible = funcy.all_fn( is_appropriate_change_type, within_contrib_subdirectory, is_appropriate_file_ext, ) for diff in self.file_diffs: if is_admissible(diff): self.file_diffs_admissible.append(diff) logger.debug( 'Categorized {file} as ADMISSIBLE' .format(file=diff.b_path)) else: self.file_diffs_inadmissible.append(diff) logger.debug( 'Categorized {file} as INADMISSIBLE' .format(file=diff.b_path)) logger.info('Admitted {} file(s) and rejected {} file(s)'.format( len(self.file_diffs_admissible), len(self.file_diffs_inadmissible)))
def default(self, obj): ordered_attrs = pipe( partial(map, lambda attr: (attr, getattr(obj, attr))), partial(remove_values, isnone), partial(remove_values, all_fn(isa(list, dict), isempty)), partial(walk_values, iffy(isa(dict), sort_dict)), OrderedDict) if isinstance(obj, Context): return ordered_attrs(['key', 'operator', 'operand', 'match_all']) elif isinstance(obj, Binding): return ordered_attrs(['keys', 'command', 'args', 'context']) else: return super().default(obj)
def check(self, feature): """Check that the feature's `input` is a str or Iterable[str]""" input = feature.input is_str = isa(str) is_nested_str = all_fn(iterable, lambda x: all(is_str, x)) assert is_str(input) or is_nested_str(input)