Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions earshot/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ def load(source):
if text.startswith('{'):
return check(json.loads(text))
if os.path.isfile(text):
with open(text, encoding='utf-8-sig') as fh:
return check(json.load(fh))
from .report import read_json
return check(read_json(text))
except json.JSONDecodeError as e:
raise RecipeError(f'the recipe is not valid JSON: {e.msg} at line {e.lineno}, column {e.colno}') from None
book = cookbook()
Expand Down
7 changes: 7 additions & 0 deletions tests/test_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,13 @@ def test_the_command_line_renders_a_file_standard_input_and_says_a_mistake(tmp_p
assert 'thing: a recipe of 2 layers: switch/power_strip, swipe/hand' in capsys.readouterr().out


@pytest.mark.parametrize('encoding', ['utf-8', 'utf-8-sig', 'utf-16'])
def test_load_reads_a_recipe_file_as_windows_tools_write_it(tmp_path, encoding):
f = tmp_path / 'r.json'
f.write_text(json.dumps(rec(TAP, says='a café door'), ensure_ascii=False), encoding=encoding)
assert R.load(str(f))['says'] == 'a café door'


def test_the_recipe_command_prints_the_form_three_examples_and_the_cookbook(capsys):
assert cli.main(['recipe', '--example']) == 0
said = capsys.readouterr().out
Expand Down