def test_keys_mutable_side_effect(): '''Avoid side effects mutating internal keys set.''' template = Template('test', '/single/{variable}') placeholders = template.keys() assert placeholders == set(['variable']) # Mutate returned set. placeholders.add('other') # Newly returned set should be unaffected. placeholders_b = template.keys() assert placeholders_b == set(['variable'])
def test_keys_mutable_side_effect(): '''Avoid side effects mutating internal keys set.''' template = Template('test', '/single/{variable}') placeholders = template.keys() assert placeholders == set(['variable']) # Mutate returned set. placeholders.add('other') # Newly returned set should be unaffected. placeholders_b = template.keys() assert placeholders_b == set(['variable'])
def dict_to_path(data): if not data: raise SpilException('[dict_to_path] Data is empty') data = data.copy() debug('Data: {}'.format(data)) # setting defaults for key in data.keys(): if not data.get(key) and path_defaults.get(key): data[key] = path_defaults.get(key) # adding defaults subtype = get_sidtype(data) # reverse path mapping for key, value in six.iteritems(data): if key == "project": for project, project_sid in path_mapping[key].items(): if os.path.normcase(project_sid) == value: data[key] = project elif value and path_mapping.get(key): mapping = path_mapping.get(key) data[key] = utils.get_key(mapping, value) debug('sidtype: {}'.format(subtype)) pattern = path_templates.get(subtype) debug('pattern: {}'.format(pattern)) if not pattern: raise SpilException( '[dict_to_path] Unable to find pattern for sidtype: "{}" \nGiven data: "{}"' .format(subtype, data)) template = Template(subtype, pattern) template.template_resolver = resolvers debug('template: {}'.format(template)) if not template: raise SpilException('toe') # adding template specific defaults for key in template.keys(): if key not in data.keys() and path_defaults.get(key): data[key] = path_defaults.get(key) debug('data after path_defaults: {}'.format(data)) path = template.format(data) debug('found: {}'.format(path)) return path
def test_extract_placeholders(pattern, expected): '''Extract data from matching path.''' template = Template('test', pattern) placeholders = template.keys() assert sorted(placeholders) == sorted(expected)
def test_keys(pattern, expected): '''Get keys in pattern.''' template = Template('test', pattern) placeholders = template.keys() assert sorted(placeholders) == sorted(expected)
def test_keys(pattern, expected): '''Get keys in pattern.''' template = Template('test', pattern) placeholders = template.keys() assert sorted(placeholders) == sorted(expected)