Skip to content

Commit b43b686

Browse files
committed
fix(tests): read and write test model files as UTF-8
`test_value_iteration_parity` wrote its model with `Path.write_text`, which uses the locale encoding. The model contains the `⟂` complementarity symbol (`\u27c2`), so on Windows (cp1252) the write raised `UnicodeEncodeError` and the test failed on py312 and py313. The library already decodes model files as UTF-8 (`dolo.misc.display.read_file_or_url`), so pass `encoding="utf-8"` when writing. Same for the read/write pair in `test_time_iteration_parity`, which was only surviving on ASCII content. Reproduced by forcing an ASCII locale (`LC_ALL=C PYTHONCOERCECLOCALE=0 PYTHONUTF8=0 pytest ...`): it failed before and passes after.
1 parent 2d81019 commit b43b686

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎tests/test_model_v2.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,10 +564,10 @@ def test_time_iteration_parity(tmp_path):
564564
from dolo.algos import time_iteration
565565

566566
# small grid keeps the smoke test fast (~ a few seconds per importer)
567-
src = Path("examples/models/rbc.yaml").read_text()
567+
src = Path("examples/models/rbc.yaml").read_text(encoding="utf-8")
568568
src = src.replace("n: [100, 100]", "n: [5, 5]")
569569
fname = tmp_path / "rbc_small.yaml"
570-
fname.write_text(src)
570+
fname.write_text(src, encoding="utf-8")
571571

572572
old = dolo.yaml_import(str(fname))
573573
new = dolo.yaml_import_v2(str(fname))
@@ -850,7 +850,10 @@ def test_value_iteration_parity(tmp_path):
850850
from dolo.algos.value_iteration import value_iteration
851851

852852
fname = tmp_path / "growth_vi_comp.yaml"
853-
fname.write_text(GROWTH_MODEL_VI)
853+
# `Path.write_text` defaults to the locale encoding, which cannot represent
854+
# the `⟂` complementarity symbol (cp1252 on Windows); the model reader
855+
# (`dolo.misc.display.read_file_or_url`) decodes as UTF-8.
856+
fname.write_text(GROWTH_MODEL_VI, encoding="utf-8")
854857

855858
old = dolo.yaml_import(str(fname))
856859
new = dolo.yaml_import_v2(str(fname))

0 commit comments

Comments
 (0)