From fee537a48ad70eff0953367c8cdda5431a81cc6b Mon Sep 17 00:00:00 2001 From: Izzy Date: Sun, 29 Nov 2026 04:39:19 -0500 Subject: [PATCH] load recipe files saved as utf-16 --- earshot/recipe.py | 4 ++-- tests/test_recipe.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/earshot/recipe.py b/earshot/recipe.py index 22878eb..271743d 100644 --- a/earshot/recipe.py +++ b/earshot/recipe.py @@ -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() diff --git a/tests/test_recipe.py b/tests/test_recipe.py index 1e2c8e2..5a9d981 100644 --- a/tests/test_recipe.py +++ b/tests/test_recipe.py @@ -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