Exemple #1
0
    def _categorize_file_diffs(self, file_diffs):
        """Partition file changes into admissible and inadmissible changes"""
        # TODO move this into a new validator
        candidate_feature_diffs = []
        valid_init_diffs = []
        inadmissible_files = []

        for diff in file_diffs:
            valid, failures = check_from_class(ProjectStructureCheck, diff,
                                               self.project)
            if valid:
                if pathlib.Path(diff.b_path).parts[-1] != '__init__.py':
                    candidate_feature_diffs.append(diff)
                    logger.debug(
                        'Categorized {file} as CANDIDATE FEATURE MODULE'.
                        format(file=diff.b_path))
                else:
                    valid_init_diffs.append(diff)
                    logger.debug(
                        'Categorized {file} as VALID INIT MODULE'.format(
                            file=diff.b_path))
            else:
                inadmissible_files.append(diff)
                logger.debug('Categorized {file} as INADMISSIBLE; '
                             'failures were {failures}'.format(
                                 file=diff.b_path, failures=failures))

        logger.info('Admitted {} candidate feature{} '
                    'and {} __init__ module{} '
                    'and rejected {} file{}'.format(
                        len(candidate_feature_diffs),
                        make_plural_suffix(candidate_feature_diffs),
                        len(valid_init_diffs),
                        make_plural_suffix(valid_init_diffs),
                        len(inadmissible_files),
                        make_plural_suffix(inadmissible_files)))

        return candidate_feature_diffs, valid_init_diffs, inadmissible_files
Exemple #2
0
    def _categorize_file_diffs(
        self, file_diffs: git.DiffIndex
    ) -> Tuple[List[git.Diff], List[git.Diff], List[git.Diff]]:
        """Partition file changes into admissible and inadmissible changes"""
        # TODO move this into a new validator
        candidate_feature_diffs = []
        valid_init_diffs = []
        inadmissible_files = []

        for diff in file_diffs:
            valid, failures, _ = check_from_class(ProjectStructureCheck, diff,
                                                  self.project)
            if valid:
                if pathlib.Path(diff.b_path).parts[-1] != '__init__.py':
                    candidate_feature_diffs.append(diff)
                    logger.debug(f'Categorized {diff.b_path} as '
                                 'CANDIDATE FEATURE MODULE')
                else:
                    valid_init_diffs.append(diff)
                    logger.debug(
                        f'Categorized {diff.b_path} as VALID INIT MODULE')
            else:
                inadmissible_files.append(diff)
                logger.debug(f'Categorized {diff.b_path} as INADMISSIBLE; '
                             f'failures were {failures}')

        logger.info('Admitted {n1} candidate feature{s1} '
                    'and {n2} __init__ module{s2} '
                    'and rejected {n3} file{s3}'.format(
                        n1=len(candidate_feature_diffs),
                        s1=make_plural_suffix(candidate_feature_diffs),
                        n2=len(valid_init_diffs),
                        s2=make_plural_suffix(valid_init_diffs),
                        n3=len(inadmissible_files),
                        s3=make_plural_suffix(inadmissible_files)))

        return candidate_feature_diffs, valid_init_diffs, inadmissible_files
Exemple #3
0
def test_make_plural_suffix_plural():
    objs = ['honda', 'toyota']
    suffix = make_plural_suffix(objs)
    actual = f'car{suffix}'
    expected = 'cars'
    assert actual == expected
Exemple #4
0
def test_make_plural_suffix_singular():
    objs = ['honda']
    suffix = make_plural_suffix(objs)
    actual = f'car{suffix}'
    expected = 'car'
    assert actual == expected
Exemple #5
0
def _log_collect_items(name, items):
    n = len(items)
    s = make_plural_suffix(items)
    logger.info('Collected {n} {name}{s}'.format(n=n, name=name, s=s))
    return items
Exemple #6
0
def _log_collect_items(name: str, items: Sized):
    n = len(items)
    s = make_plural_suffix(items)
    logger.info(f'Collected {n} {name}{s}')
    return items