Skip to content

Commit e0c8dad

Browse files
1e0ngdlech
authored andcommitted
Fix: Correct ValueError message for invalid ABI version
The error message raised in `pybricksdev.compile.compile_file` when an unsupported ABI version was provided incorrectly stated "mpy_version must be 5". This has been corrected to "mpy_version must be 5 or 6" to accurately reflect the supported ABI versions. A new test case (`test_compile_file_invalid_abi`) has been added to `tests/test_compile.py` to verify that the correct ValueError and message are raised for invalid ABI versions.
1 parent 22ef545 commit e0c8dad

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

pybricksdev/compile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async def compile_file(
7474
),
7575
)
7676
else:
77-
raise ValueError("mpy_version must be 5")
77+
raise ValueError("mpy_version must be 5 or 6")
7878

7979
proc.check_returncode()
8080

tests/test_compile.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,18 @@ async def test_compile_file(abi: int):
3131
assert int_bits == 31
3232
finally:
3333
os.unlink(f.name)
34+
35+
36+
@pytest.mark.asyncio
37+
async def test_compile_file_invalid_abi():
38+
with NamedTemporaryFile("w", delete=False) as f:
39+
try:
40+
f.write("print('test')")
41+
f.close()
42+
43+
with pytest.raises(ValueError, match="mpy_version must be 5 or 6"):
44+
await compile_file(
45+
os.path.dirname(f.name), os.path.basename(f.name), abi=4
46+
)
47+
finally:
48+
os.unlink(f.name)

0 commit comments

Comments
 (0)