import pytest
TEST_DATA = {
"a": {
"html": """""",
"atspi_role": "ROLE_LINK",
"axapi_role": "AXLink",
"axapi_subrole": "AXMathRow"
},
"annotation": {
"html": "",
"atspi_role": "ROLE_STATIC",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathText" # FIXME: https://github.com/w3c/mathml-aam/issues/41
},
"annotation-xml": {
"html": "",
"atspi_role": "ROLE_SECTION",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathRow" # FIXME: https://github.com/w3c/mathml-aam/issues/41
},
"maction": {
"html": "",
"atspi_role": "ROLE_SECTION",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathRow" # FIXME: https://github.com/w3c/mathml-aam/issues/41
},
"math": {
"html": "",
"atspi_role": "ROLE_MATH",
"axapi_role": "AXGroup",
"axapi_subrole": "AXDocumentMath"
},
"merror": {
"html": "",
"atspi_role": "ROLE_SECTION",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathRow"
},
"mfrac": {
"html": "",
"atspi_role": "ROLE_MATH_FRACTION",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathFraction"
},
"mi": {
"html": "",
"atspi_role": "ROLE_STATIC",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathIdentifier"
},
"mmultiscripts": {
"html": "",
"atspi_role": "ROLE_SECTION",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathMultiscript"
},
"mn": {
"html": "",
"atspi_role": "ROLE_STATIC",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathNumber"
},
"mo": {
"html": "",
"atspi_role": "ROLE_STATIC",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathOperator"
},
"mover": {
"html": "",
"atspi_role": "ROLE_SECTION",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathUnderOver"
},
"mpadded": {
"html": "",
"atspi_role": "ROLE_SECTION",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathRow" # FIXME: https://github.com/w3c/mathml-aam/issues/41
},
"mphantom": {
"html": "",
"atspi_role": "ROLE_SECTION",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathRow"
},
"mprescripts": {
"html": "",
"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": "",
"atspi_role": "ROLE_MATH_ROOT",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathRoot"
},
"mrow": {
"html": "",
"atspi_role": "ROLE_SECTION",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathRow"
},
"ms": {
"html": """""",
"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": "",
"atspi_role": "ROLE_MATH_ROOT",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathSquareRoot"
},
"mstyle": {
"html": "",
"atspi_role": "ROLE_SECTION",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathRow"
},
"msub": {
"html": "",
"atspi_role": "ROLE_SECTION",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathSubscriptSuperscript"
},
"msubsup": {
"html": "",
"atspi_role": "ROLE_SECTION",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathSubscriptSuperscript"
},
"msup": {
"html": "",
"atspi_role": "ROLE_SECTION",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathSubscriptSuperscript"
},
"mtable": {
"html": "",
"atspi_role": "ROLE_TABLE",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathTable"
},
"mtd": {
"html": "",
"atspi_role": "ROLE_TABLE_CELL",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathTableCell"
},
"mtext": {
"html": "",
"atspi_role": "ROLE_STATIC",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathText"
},
"mtr": {
"html": "",
"atspi_role": "ROLE_TABLE_ROW",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathTableRow"
},
"munder": {
"html": "",
"atspi_role": "ROLE_SECTION",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathUnderOver"
},
"munderover": {
"html": "",
"atspi_role": "ROLE_SECTION",
"axapi_role": "AXGroup",
"axapi_subrole": "AXMathUnderOver"
},
"none": {
"html": "",
"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": "",
"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}'"