96 lines
3.0 KiB
Python
96 lines
3.0 KiB
Python
"""Controller return-code translation.
|
|
|
|
The vendor SDK header defines the auxiliary error block at 30000; everything
|
|
else is the firmware's own number. The point of these tests is that AutoCal
|
|
never invents a meaning for a code it cannot read out of that header.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from orisys_autocal.motion import errors
|
|
|
|
DOCUMENTED = sorted(errors.MESSAGES)
|
|
|
|
|
|
def test_zero_is_success_in_both_languages():
|
|
assert errors.describe(0) == "成功"
|
|
assert errors.describe(0, language="en_US") == "OK"
|
|
|
|
|
|
def test_the_documented_block_is_the_vendor_offset():
|
|
assert errors.ERR_AUX_OFFSET == 30000
|
|
assert DOCUMENTED == [30000, 30001, 30002, 30003, 30004, 30005]
|
|
|
|
|
|
@pytest.mark.parametrize("code", DOCUMENTED)
|
|
def test_every_documented_code_has_both_languages(code):
|
|
zh = errors.describe(code)
|
|
en = errors.describe(code, language="en_US")
|
|
assert zh and en and zh != en
|
|
|
|
|
|
@pytest.mark.parametrize("code", DOCUMENTED)
|
|
def test_no_documented_message_is_empty(code):
|
|
assert errors.describe(code).strip()
|
|
assert errors.describe(code, language="en_US").strip()
|
|
|
|
|
|
def test_an_unknown_code_keeps_its_number():
|
|
"""A guessed meaning on a motion controller is worse than 'unknown'."""
|
|
message = errors.describe(12345)
|
|
assert "12345" in message
|
|
assert message == "错误码 12345"
|
|
|
|
|
|
def test_an_unknown_code_points_at_zdevelop():
|
|
message = errors.describe_with_hint(-1)
|
|
assert "-1" in message
|
|
assert errors.UNKNOWN_HINT in message
|
|
|
|
|
|
def test_a_documented_code_gets_no_hint_appended():
|
|
assert errors.describe_with_hint(30000) == errors.describe(30000)
|
|
|
|
|
|
# ------------------------------------------------- host-library (PC) codes
|
|
|
|
|
|
def test_a_host_library_code_is_not_sent_to_the_firmware_table():
|
|
"""``20008`` is not a controller code: ZDevelop cannot have it.
|
|
|
|
It is what ``ZAux_OpenEth`` returned on the first, transient attempt at the
|
|
bench, and the old text sent the operator to a table that cannot contain it.
|
|
"""
|
|
message = errors.describe_with_hint(20008)
|
|
|
|
assert "20008" in message
|
|
assert errors.UNKNOWN_HINT not in message
|
|
assert "上位机" in message
|
|
assert errors.HOST_LIB_HINT_ZH in message
|
|
|
|
|
|
def test_the_host_library_hint_is_localised():
|
|
zh = errors.describe_with_hint(20008)
|
|
en = errors.describe_with_hint(20008, language="en_US")
|
|
|
|
assert errors.HOST_LIB_HINT_EN in en
|
|
assert zh != en
|
|
|
|
|
|
@pytest.mark.parametrize("code", [20000, 20008, 25000, 29999])
|
|
def test_the_host_library_range_is_recognised(code):
|
|
assert errors.is_host_lib_error(code)
|
|
assert "错误码" not in errors.describe(code)
|
|
|
|
|
|
@pytest.mark.parametrize("code", [19999, 30000, 30005, 12345, 222, 0])
|
|
def test_codes_outside_the_host_range_are_not_labelled_as_library_faults(code):
|
|
assert not errors.is_host_lib_error(code)
|
|
|
|
|
|
def test_a_controller_code_keeps_the_firmware_hint():
|
|
"""222 is firmware (``Other error``), so ZDevelop is still the right pointer."""
|
|
message = errors.describe_with_hint(222)
|
|
assert errors.UNKNOWN_HINT in message
|