Skip to content

Windows: UnicodeEncodeError in test_creates_only_final_file (cp1252 codec) #402

Description

@Diyaaa-12

While testing PR #395, I found that test_rendering.py::TestRenderTimesheet::test_creates_only_final_file fails locally on Windows with:

UnicodeEncodeError: 'charmap' codec can't encode characters in position 570-575: character maps to

This happens in tuttle/rendering.py at the render_timesheet function, when writing the rendered HTML:

timesheet_file.write(html)

The file write doesn't specify an encoding, so Python defaults to the system locale encoding (cp1252 on Windows) instead of UTF-8, which fails on non-ASCII characters in the rendered template.

This doesn't show up in CI (likely running on Linux/macOS where UTF-8 is the default), but it does reproduce consistently on Windows. Confirmed via git stash that this also fails on main, unrelated to my PR (#395).

Suggested fix: explicitly open the file with encoding="utf-8", e.g.:

with open(path, "w", encoding="utf-8") as timesheet_file:
    ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions