import pytest TEST_DATA = { "a": { "html": """Link""", "atspi_role": "ROLE_LINK", "axapi_role": "AXLink", "axapi_subrole": "AXMathRow" }, "annotation": { "html": "2\\text{two}", "atspi_role": "ROLE_STATIC", "axapi_role": "AXGroup", "axapi_subrole": "AXMathText" # FIXME: https://github.com/w3c/mathml-aam/issues/41 }, "annotation-xml": { "html": "2two", "atspi_role": "ROLE_SECTION", "axapi_role": "AXGroup", "axapi_subrole": "AXMathRow" # FIXME: https://github.com/w3c/mathml-aam/issues/41 }, "maction": { "html": "A", "atspi_role": "ROLE_SECTION", "axapi_role": "AXGroup", "axapi_subrole": "AXMathRow" # FIXME: https://github.com/w3c/mathml-aam/issues/41 }, "math": { "html": "x", "atspi_role": "ROLE_MATH", "axapi_role": "AXGroup", "axapi_subrole": "AXDocumentMath" }, "merror": { "html": "error", "atspi_role": "ROLE_SECTION", "axapi_role": "AXGroup", "axapi_subrole": "AXMathRow" }, "mfrac": { "html": "ab", "atspi_role": "ROLE_MATH_FRACTION", "axapi_role": "AXGroup", "axapi_subrole": "AXMathFraction" }, "mi": { "html": "x", "atspi_role": "ROLE_STATIC", "axapi_role": "AXGroup", "axapi_subrole": "AXMathIdentifier" }, "mmultiscripts": { "html": "X", "atspi_role": "ROLE_SECTION", "axapi_role": "AXGroup", "axapi_subrole": "AXMathMultiscript" }, "mn": { "html": "2", "atspi_role": "ROLE_STATIC", "axapi_role": "AXGroup", "axapi_subrole": "AXMathNumber" }, "mo": { "html": "+", "atspi_role": "ROLE_STATIC", "axapi_role": "AXGroup", "axapi_subrole": "AXMathOperator" }, "mover": { "html": "a˙", "atspi_role": "ROLE_SECTION", "axapi_role": "AXGroup", "axapi_subrole": "AXMathUnderOver" }, "mpadded": { "html": "x", "atspi_role": "ROLE_SECTION", "axapi_role": "AXGroup", "axapi_subrole": "AXMathRow" # FIXME: https://github.com/w3c/mathml-aam/issues/41 }, "mphantom": { "html": "x", "atspi_role": "ROLE_SECTION", "axapi_role": "AXGroup", "axapi_subrole": "AXMathRow" }, "mprescripts": { "html": "X", "atspi_role": "ROLE_SECTION", "axapi_role": "AXGroup", # FIXME: https://github.com/w3c/mathml-aam/issues/41 "axapi_subrole": "AXEmptyGroup" # FIXME: https://github.com/w3c/mathml-aam/issues/41 }, "mroot": { "html": "x3", "atspi_role": "ROLE_MATH_ROOT", "axapi_role": "AXGroup", "axapi_subrole": "AXMathRoot" }, "mrow": { "html": "a+b", "atspi_role": "ROLE_SECTION", "axapi_role": "AXGroup", "axapi_subrole": "AXMathRow" }, "ms": { "html": """"string"""", "atspi_role": "ROLE_STATIC", "axapi_role": "AXGroup", "axapi_subrole": "AXMathText" # FIXME: https://github.com/w3c/mathml-aam/issues/41 }, "mspace": { "html": "", "atspi_role": "ROLE_SECTION", # FIXME: https://github.com/w3c/mathml-aam/issues/41 "axapi_role": "AXGroup", # FIXME: https://github.com/w3c/mathml-aam/issues/41 "axapi_subrole": "AXEmptyGroup" # FIXME: https://github.com/w3c/mathml-aam/issues/41 }, "msqrt": { "html": "x", "atspi_role": "ROLE_MATH_ROOT", "axapi_role": "AXGroup", "axapi_subrole": "AXMathSquareRoot" }, "mstyle": { "html": "x", "atspi_role": "ROLE_SECTION", "axapi_role": "AXGroup", "axapi_subrole": "AXMathRow" }, "msub": { "html": "x1", "atspi_role": "ROLE_SECTION", "axapi_role": "AXGroup", "axapi_subrole": "AXMathSubscriptSuperscript" }, "msubsup": { "html": "x12", "atspi_role": "ROLE_SECTION", "axapi_role": "AXGroup", "axapi_subrole": "AXMathSubscriptSuperscript" }, "msup": { "html": "x2", "atspi_role": "ROLE_SECTION", "axapi_role": "AXGroup", "axapi_subrole": "AXMathSubscriptSuperscript" }, "mtable": { "html": "1", "atspi_role": "ROLE_TABLE", "axapi_role": "AXGroup", "axapi_subrole": "AXMathTable" }, "mtd": { "html": "1", "atspi_role": "ROLE_TABLE_CELL", "axapi_role": "AXGroup", "axapi_subrole": "AXMathTableCell" }, "mtext": { "html": "text", "atspi_role": "ROLE_STATIC", "axapi_role": "AXGroup", "axapi_subrole": "AXMathText" }, "mtr": { "html": "1", "atspi_role": "ROLE_TABLE_ROW", "axapi_role": "AXGroup", "axapi_subrole": "AXMathTableRow" }, "munder": { "html": "x_", "atspi_role": "ROLE_SECTION", "axapi_role": "AXGroup", "axapi_subrole": "AXMathUnderOver" }, "munderover": { "html": "x_˙", "atspi_role": "ROLE_SECTION", "axapi_role": "AXGroup", "axapi_subrole": "AXMathUnderOver" }, "none": { "html": "X", "atspi_role": "ROLE_SECTION", "axapi_role": "AXGroup", # FIXME: https://github.com/w3c/mathml-aam/issues/41 "axapi_subrole": "AXEmptyGroup" # FIXME: https://github.com/w3c/mathml-aam/issues/41 }, "semantics": { "html": "x", "atspi_role": "ROLE_SECTION", "axapi_role": "AXGroup", "axapi_subrole": "AXMathRow" # FIXME: https://github.com/w3c/mathml-aam/issues/41 } } @pytest.mark.parametrize("element_name", TEST_DATA.keys()) def test_atspi(atspi, session, inline, element_name): data = TEST_DATA[element_name] session.url = inline(data["html"]) node = atspi.find_node("test", session.url) actual_role = atspi.Accessible.get_role(node) role_attr_name = data["atspi_role"].replace("ROLE_", "") expected_role = getattr(atspi.Role, role_attr_name) assert actual_role == expected_role, f"Expected {expected_role}, but got {actual_role}" @pytest.mark.parametrize("element_name", TEST_DATA.keys()) def test_axapi(axapi, session, inline, element_name): data = TEST_DATA[element_name] session.url = inline(data["html"]) node = axapi.find_node("test", session.url) expected_role = data["axapi_role"] role_result = axapi.AXUIElementCopyAttributeValue(node, "AXRole", None) actual_role = role_result[1] if (role_result and len(role_result) > 1) else None assert actual_role == expected_role, f"AXRole mismatch for <{element_name}>. Expected '{data['axapi_role']}', got '{actual_role}'" subrole_result = axapi.AXUIElementCopyAttributeValue(node, "AXSubrole", None) actual_subrole = subrole_result[1] if (subrole_result and len(subrole_result) > 1) else None assert actual_subrole == data["axapi_subrole"], f"AXSubrole mismatch for <{element_name}>. Expected '{data['axapi_subrole']}', got '{actual_subrole}'"