[PR #1596] [MERGED] fix(labs/tests): open lab files with explicit UTF-8 encoding #9208

Closed
opened 2026-05-03 01:28:23 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/harvard-edge/cs249r_book/pull/1596
Author: @Shashank-Tripathi-07
Created: 4/28/2026
Status: Merged
Merged: 4/28/2026
Merged by: @profvjreddi

Base: devHead: fix/test-static-utf8-encoding


📝 Commits (1)

  • e42cf0d fix(labs/tests): open lab files with explicit UTF-8 encoding

📊 Changes

1 file changed (+1 additions, -1 deletions)

View changed files

📝 labs/tests/test_static.py (+1 -1)

📄 Description

Summary

  • read_source() in test_static.py used open() without specifying an encoding
  • On Windows, the default codec is cp1252, which cannot decode UTF-8 byte sequences like 0x90 (used in em-dash and similar characters present in lab markdown strings)
  • All 33 TestWidgetReturnCompleteness tests failed on Windows with UnicodeDecodeError; passing PYTHONUTF8=1 made them all green
  • Fix: add encoding="utf-8" to the single open() call in read_source()

Root cause

# before
def read_source(lab_path: str) -> str:
    with open(lab_path) as f:  # uses platform default (cp1252 on Windows)
        return f.read()

# after
def read_source(lab_path: str) -> str:
    with open(lab_path, encoding="utf-8") as f:
        return f.read()

Test plan

  • pytest labs/tests/test_static.py -q passes (755 passed, 4 skipped, 1 xfailed) on both Linux and Windows without PYTHONUTF8=1

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/harvard-edge/cs249r_book/pull/1596 **Author:** [@Shashank-Tripathi-07](https://github.com/Shashank-Tripathi-07) **Created:** 4/28/2026 **Status:** ✅ Merged **Merged:** 4/28/2026 **Merged by:** [@profvjreddi](https://github.com/profvjreddi) **Base:** `dev` ← **Head:** `fix/test-static-utf8-encoding` --- ### 📝 Commits (1) - [`e42cf0d`](https://github.com/harvard-edge/cs249r_book/commit/e42cf0d27706ff7f85c950bd710e028d8f12aae7) fix(labs/tests): open lab files with explicit UTF-8 encoding ### 📊 Changes **1 file changed** (+1 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `labs/tests/test_static.py` (+1 -1) </details> ### 📄 Description ## Summary - `read_source()` in `test_static.py` used `open()` without specifying an encoding - On Windows, the default codec is `cp1252`, which cannot decode UTF-8 byte sequences like `0x90` (used in em-dash and similar characters present in lab markdown strings) - All 33 `TestWidgetReturnCompleteness` tests failed on Windows with `UnicodeDecodeError`; passing `PYTHONUTF8=1` made them all green - Fix: add `encoding="utf-8"` to the single `open()` call in `read_source()` ## Root cause ```python # before def read_source(lab_path: str) -> str: with open(lab_path) as f: # uses platform default (cp1252 on Windows) return f.read() # after def read_source(lab_path: str) -> str: with open(lab_path, encoding="utf-8") as f: return f.read() ``` ## Test plan - [ ] `pytest labs/tests/test_static.py -q` passes (755 passed, 4 skipped, 1 xfailed) on both Linux and Windows without `PYTHONUTF8=1` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-03 01:28:23 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/cs249r_book#9208