Skip to content

Commit

Permalink
fix(writer): use UTF-8 encoding to support non-ASCII characters
Browse files Browse the repository at this point in the history
  • Loading branch information
mostaphaRoudsari committed Sep 6, 2023
1 parent 5157d47 commit 7f2d5d6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion honeybee_idaice/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def model_to_idm(
templates_folder = __here__.joinpath('templates')

# create building file that includes building bodies and a reference to the rooms
with bldg_file.open('w') as bldg:
with bldg_file.open('w', encoding='UTF-8') as bldg:
header = ';IDA 4.80002 Data UTF-8\n' \
f'(DOCUMENT-HEADER :TYPE BUILDING :N "{bldg_name}" :MS 4 :CK ((RECENT (WINDEF . "Double Clear Air (WIN7)"))) :PARENT ICE :APP (ICE :VER 4.802))\n'
bldg.write(header)
Expand Down
1 change: 1 addition & 0 deletions tests/assets/single-room.hbjson

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions tests/writer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@ def test_model():
model = Model.from_hbjson(in_file)
outf = model_to_idm(model, out_folder.as_posix(), name='revit_sample_model')
assert outf.exists()


def test_non_ascii():
in_file = './tests/assets/single-room.hbjson'
out_folder = pathlib.Path('./tests/assets/temp')
out_folder.mkdir(parents=True, exist_ok=True)
model = Model.from_hbjson(in_file)
outf = model_to_idm(model, out_folder.as_posix(), name='single-room', debug=True)
assert outf.is_file()
bldg_file = out_folder.joinpath('single-room', 'single-room.idm')
content = bldg_file.read_text(encoding='UTF-8')
assert 'CE-ZONE :N "Wände" :T ZONE' in content

0 comments on commit 7f2d5d6

Please sign in to comment.