Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

test(portability): pin the encoding on every repo read that leaves it to the locale

Aashishf44ffa329e0b
diff --git a/tests/test_evals.py b/tests/test_evals.py
index 59cbaea2..bf37e060 100644
--- a/tests/test_evals.py
+++ b/tests/test_evals.py
@@ -1305,7 +1305,8 @@ def test_docs_and_the_harness_name_the_same_timing_metrics(monkeypatch):
import pathlib
import re
- page = (pathlib.Path(__file__).resolve().parent.parent / "docs" / "evals.md").read_text()
+ page = (pathlib.Path(__file__).resolve().parent.parent / "docs" / "evals.md").read_text(
+ encoding="utf-8")
batched, _ = _timed_pair(monkeypatch, 8)
published = {metric for metric in batched.overall if metric.endswith("_ms")}
diff --git a/tests/test_runtime_fixes.py b/tests/test_runtime_fixes.py
index 24a92daa..7684bdb0 100644
--- a/tests/test_runtime_fixes.py
+++ b/tests/test_runtime_fixes.py
@@ -426,8 +426,11 @@ def _branch(device):
def _strings(rel):
- """Every string the example carries: the module docstring, the banner, each printed line."""
- with open(os.path.join(ROOT, rel)) as fh:
+ """Every string the example carries: the module docstring, the banner, each printed line.
+
+ UTF-8 explicitly, for the reason recorded at the `EX35` read below.
+ """
+ with open(os.path.join(ROOT, rel), encoding="utf-8") as fh:
tree = ast.parse(fh.read(), filename=rel)
nodes = [n for n in ast.walk(tree) if isinstance(n, ast.Constant) and isinstance(n.value, str)]
nodes.sort(key=lambda n: (n.lineno, n.col_offset))
@@ -502,7 +505,9 @@ check("35/the MPS threshold it states is the module default",
# Read from the agent, and observed in a real forward: the page may not hand-copy the threshold, nor
# relabel `dtype` as though it were the precision a call ran in. That relabeling is how the old
# sentence got printed with a straight face -- `dtype` said float16 while the call ran fp32.
-with open(os.path.join(ROOT, EX35)) as fh:
+# `encoding="utf-8"` because `open()` otherwise takes the runner's locale codec, which is cp1252 on
+# `tests (windows)` and cannot decode the UTF-8 these pages carry (tests/test_portability.py gates it).
+with open(os.path.join(ROOT, EX35), encoding="utf-8") as fh:
example = ast.parse(fh.read(), filename=EX35)
attrs = {n.attr for n in ast.walk(example) if isinstance(n, ast.Attribute)}
calls = {n.func.attr for n in ast.walk(example)
diff --git a/tests/test_truncation.py b/tests/test_truncation.py
index ea458783..2ceb36d0 100644
--- a/tests/test_truncation.py
+++ b/tests/test_truncation.py
@@ -178,7 +178,11 @@ EXAMPLES = (("15", EX15), ("37", EX37))
def _tree(rel):
- with open(os.path.join(ROOT, rel)) as fh:
+ """Parse a repo file. The encoding is pinned because `open()` would otherwise take the runner's
+ locale codec -- cp1252 on `tests (windows)`, which cannot decode examples/37's UTF-8. The gate
+ that keeps every such read pinned lives in tests/test_portability.py.
+ """
+ with open(os.path.join(ROOT, rel), encoding="utf-8") as fh:
return ast.parse(fh.read(), filename=rel)
@@ -262,7 +266,7 @@ for tag, rel in EXAMPLES:
# `build_sequence` call, and the examples' claim has to survive that reformatting or keep its meaning.
CLAMP = re.compile(r"truncate_left[^\n]*?isinstance\(state, ?list\)")
for rel in ("laya/agent.py", "laya/onnx_agent.py"):
- with open(os.path.join(ROOT, rel)) as fh:
+ with open(os.path.join(ROOT, rel), encoding="utf-8") as fh:
src = fh.read()
check_true("clamp/%s clamps from the state's type" % rel, CLAMP.search(src) is not None,
"no `truncate_left = isinstance(state, list)`")