Skip to content

Commit 419a77e

Browse files
committed
Add platform support for accessible relations and relation targets
1 parent eb5f6c8 commit 419a77e

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

wai-aria/tools/atta-atk-atspi.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import json
1717
import os
1818
import pyatspi
19+
import re
1920
import signal
2021
import subprocess
2122
import sys
@@ -264,6 +265,9 @@ def _parse_assertion(self, assertion):
264265
if test_type == "object":
265266
return (self._has_attribute_value, test_value, expected_result), self.SUCCESS
266267

268+
if test_type == "relation":
269+
return (self._has_relation, test_value, expected_result), self.SUCCESS
270+
267271
print("ERROR: Unhandled assertion type: %s" % test_type)
268272
return None, self.FAILURE_INVALID_REQUEST
269273

@@ -585,6 +589,44 @@ def _has_name(self, obj, name_string, expected_result):
585589

586590
return success, self.SUCCESS, actual_name
587591

592+
def _has_relation(self, obj, type_string, target_ids, expected_result=True):
593+
"""Checks if the obj has the specified accessible relation type pointing
594+
to the element(s) with the specified id(s). Test writers may provide all
595+
of the targets in a single assertion or create multiple assertions, each
596+
of which contains a subset of the targets.
597+
598+
Arguments:
599+
- obj: The AtspiAccessible to check
600+
- type_string: A string containing the AtspiRelationType being checked
601+
- target_ids: A string containing the id(s) of the referenced element(s)
602+
- expected_result: A boolean reflecting if the names should match
603+
604+
Returns:
605+
- A boolean reflecting if the actual result is the expected_result
606+
- A string indicating success, or the cause of failure
607+
- A string containing the id(s) of the target(s)
608+
"""
609+
610+
targets = []
611+
relations = obj.getRelationSet()
612+
for r in relations:
613+
string = r.getRelationType().value_name.replace("ATSPI_", "")
614+
if string == type_string:
615+
targets = [r.getTarget(i) for i in range(r.getNTargets())]
616+
break
617+
618+
desired_ids = re.compile("\W+").split(target_ids)
619+
actual_ids = list(map(lambda x: self._get_element_id(x)[0], targets))
620+
not_found = list(filter(lambda x: x not in actual_ids, desired_ids))
621+
622+
result = not not_found
623+
success = result == expected_result
624+
625+
if success == False:
626+
return success, self.FAILURE_RESULTS, actual_ids
627+
628+
return success, self.SUCCESS, actual_ids
629+
588630
def _has_role(self, obj, role_string, expected_result):
589631
"""Checks if the accessible role of obj is role_string.
590632

0 commit comments

Comments
 (0)