Exemplo n.º 1
0
def _process_overrides_param(parser, raw_value, base_path):
    result = {}

    if raw_value is None:
        return result

    for overrides_group in raw_value:
        for filename_from, filename_to in chunked(overrides_group, 2):
            if filename_to is None:
                parser.error("No override specified for file '{0}'".format(filename_from))
            elif result.get(filename_from, filename_to) != filename_to:
                parser.error("Conflicting overrides for file '{0}'".format(filename_from))
            else:
                result[filename_from] = filename_to

    return convert_raw_overrides(result, base_path)
Exemplo n.º 2
0
    def _test_rename_files(self, input_description, rules_text, expected_result, **options):
        files = [FileReference.from_test_repr(file_repr) for file_repr in input_description]
        rule_set = RuleSet.from_source(rules_text)

        rename_params = {key: value for key, value in options.items() if key != 'overrides'}
        renamed_files = rename_files(files, rule_set, **rename_params)

        if 'overrides' in options:
            # Normalize override specification
            overrides = {
                from_path.replace('/', os.sep): to_path.replace('/', os.sep)
                for from_path, to_path in options['overrides'].items()
            }

            renamed_files = apply_rename_overrides(renamed_files, convert_raw_overrides(overrides, None))

        self.assertEquals(
            tuple(f.test_repr() for f in renamed_files),
            expected_result,
        )