mirror of
https://github.com/home-assistant/core.git
synced 2026-04-17 23:53:49 +01:00
Pass encoding to AtomicWriter in write_utf8_file_atomic (#164015)
This commit is contained in:
@@ -83,6 +83,19 @@ def test_write_utf8_file_fails_at_rename_and_remove(
|
||||
assert "File replacement cleanup failed" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.parametrize("func", [write_utf8_file, write_utf8_file_atomic])
|
||||
def test_write_utf8_file_with_non_ascii_content(tmp_path: Path, func) -> None:
|
||||
"""Test files with non-ASCII content can be written even when locale is ASCII."""
|
||||
test_file = tmp_path / "test.json"
|
||||
non_ascii_data = '{"name":"自动化","emoji":"🏠"}'
|
||||
|
||||
with patch("locale.getpreferredencoding", return_value="ascii"):
|
||||
func(test_file, non_ascii_data, False)
|
||||
|
||||
file_text = test_file.read_text(encoding="utf-8")
|
||||
assert file_text == non_ascii_data
|
||||
|
||||
|
||||
def test_write_utf8_file_atomic_fails(tmpdir: py.path.local) -> None:
|
||||
"""Test OSError from write_utf8_file_atomic is rethrown as WriteError."""
|
||||
test_dir = tmpdir.mkdir("files")
|
||||
|
||||
Reference in New Issue
Block a user