Skip to content

Commit e1d6beb

Browse files
tautschnigkiro-agentkeyboardDrummerCopilot
authored
Fix DictNoneTest Test 6: len() rejection is an error, not a diagnostic (#1035)
Test 6 (len() on a class without __len__) was always broken since its introduction in PR #761 (bb11e70). The test expected processPythonFile to return diagnostics, but the len() rejection throws a TranslationError in PythonToLaurel.lean, which withPythonToLaurel converts to an IO.Error before the diagnostic stage is reached. The test was never caught because: 1. It was authored in an environment without Python, so withPython skipped and #guard_msgs saw empty output (matching the empty docstring). 2. DictNoneTest was not in CI's explicit Python test list in ci.yml, so it was never run in CI either. Fix: catch the IO.Error and verify it contains the expected message, and add DictNoneTest to CI's Python test list. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. --------- Co-authored-by: Kiro <kiro-agent@users.noreply.github.com> Co-authored-by: Remy Willems <rwillems@amazon.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 84c6418 commit e1d6beb

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ jobs:
304304
sudo cp z3-4.13.4-x64-glibc-2.35/bin/z3 /usr/local/bin/
305305
fi
306306
- name: Run PySpec and dispatch tests
307-
run: PYTHON=python PYTHON_TEST=1 lake build StrataTest.Languages.Python.SpecsTest StrataTest.Languages.Python.AnalyzeLaurelTest StrataTest.Languages.Python.Specs.IdentifyOverloadsTest StrataTest.Languages.Python.VerifyPythonTest StrataTest.Languages.Python.PropertySummaryTest
307+
run: PYTHON=python PYTHON_TEST=1 lake build StrataTest.Languages.Python.SpecsTest StrataTest.Languages.Python.AnalyzeLaurelTest StrataTest.Languages.Python.Specs.IdentifyOverloadsTest StrataTest.Languages.Python.VerifyPythonTest StrataTest.Languages.Python.PropertySummaryTest StrataTest.Languages.Python.DictNoneTest
308308
- name: Run test script
309309
run: FAIL_FAST=1 ./scripts/run_cpython_tests.sh ${{ matrix.python_version }}
310310
working-directory: Tools/Python

StrataTest/Languages/Python/DictNoneTest.lean

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ def main() -> None:
9393
throw <| .userError s!"Expected assertion failure for negative indexing on empty list, got: {diags.map (·.message)}"
9494

9595
-- Test 6: len() on a class instance without __len__.
96-
-- This should be rejected as a user error.
96+
-- This should be rejected as a user error during translation (before
97+
-- diagnostics are produced), so processPythonFile throws an IO.Error.
9798
#guard_msgs in
9899
#eval withPython (warnOnSkip := false) fun pythonCmd => do
99100
let program :=
@@ -106,8 +107,10 @@ def main() -> None:
106107
obj: MyObj = MyObj(\"test\")
107108
n: int = len(obj)
108109
"
109-
let diags ← processPythonFile pythonCmd (stringInputContext "test.py" program)
110-
if diags.size == 0 then
111-
throw <| .userError s!"Expected ≥1 diagnostic for len() on Composite, got 0"
110+
match ← (processPythonFile pythonCmd (stringInputContext "test.py" program)).toBaseIO with
111+
| .ok _ => throw <| IO.userError "Expected error for len() on class without __len__"
112+
| .error err =>
113+
unless containsSubstr (toString err) "len() is not supported" do
114+
throw <| IO.userError s!"Unexpected error: {err}"
112115

113116
end Strata.Python.DictNoneTest

0 commit comments

Comments
 (0)