From 7aa5766cf052d9128b62e47cf6d0e51945efcb8e Mon Sep 17 00:00:00 2001 From: Liang Date: Wed, 28 May 2025 03:27:09 +0000 Subject: [PATCH] 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. --- pybricksdev/compile.py | 2 +- tests/test_compile.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pybricksdev/compile.py b/pybricksdev/compile.py index c37dfb0..fba33b0 100644 --- a/pybricksdev/compile.py +++ b/pybricksdev/compile.py @@ -74,7 +74,7 @@ async def compile_file( ), ) else: - raise ValueError("mpy_version must be 5") + raise ValueError("mpy_version must be 5 or 6") proc.check_returncode() diff --git a/tests/test_compile.py b/tests/test_compile.py index 7b817f4..545ec17 100644 --- a/tests/test_compile.py +++ b/tests/test_compile.py @@ -31,3 +31,18 @@ async def test_compile_file(abi: int): assert int_bits == 31 finally: os.unlink(f.name) + + +@pytest.mark.asyncio +async def test_compile_file_invalid_abi(): + with NamedTemporaryFile("w", delete=False) as f: + try: + f.write("print('test')") + f.close() + + with pytest.raises(ValueError, match="mpy_version must be 5 or 6"): + await compile_file( + os.path.dirname(f.name), os.path.basename(f.name), abi=4 + ) + finally: + os.unlink(f.name)