Skip to content

Commit

Permalink
refactor: use format_map instead of format
Browse files Browse the repository at this point in the history
  • Loading branch information
kalekundert committed Aug 29, 2021
1 parent 59e972f commit 5cf127c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tests/test_utils.py
Expand Up @@ -63,3 +63,14 @@ def test_list_iadd():

assert l == ["a", int, "c", "d"]

@pytest.mark.parametrize(
'template, data, expected', [
('', {}, ''),
('a', {}, 'a'),
('{a}', {'a': 1}, '1'),
(lambda d: f'{d["a"] + 1}', {'a': 1}, '2'),
],
)
def test_eval_template(template, data, expected):
assert utils.eval_template(template, data) == expected

3 changes: 2 additions & 1 deletion tidyexc/utils.py
Expand Up @@ -57,4 +57,5 @@ def eval_template(template, data):
if callable(template):
return template(data)
else:
return template.format(**data)
return template.format_map(data)

0 comments on commit 5cf127c

Please sign in to comment.