5 os
.environ
['NO_GAIL'] = '1'
6 os
.environ
['NO_AT_BRIDGE'] = '1'
8 import pyatspi
, unittest
, gtk
10 class TestBansheeAccessibity(unittest
.TestCase
):
14 if not self
.__class
__.neried
:
15 self
.neried
= [app
for app
in pyatspi
.Registry
.getDesktop(0) \
16 if getattr(app
, 'name', None) == 'Nereid'][0]
18 if not self
.__class
__.list_views
:
19 self
.list_views
= pyatspi
.findAllDescendants(
20 self
.neried
, lambda x
: getattr(x
, 'name', None) == 'ListView')
22 def testAnchestry(self
):
23 for list_view
in self
.list_views
:
24 self
._parent
_check
(list_view
)
25 for i
, cell
in enumerate(list_view
):
26 self
._parent
_check
(cell
)
28 def testSelectionAndTable(self
):
29 for list_view
in self
.list_views
:
30 tablei
= list_view
.queryTable()
31 selectioni
= list_view
.querySelection()
32 for row
in xrange(tablei
.nRows
):
33 for column
in xrange(tablei
.nColumns
):
34 cell
= tablei
.getAccessibleAt(row
, column
)
35 selectioni
.selectChild(cell
.getIndexInParent())
37 cell
.getState().contains(pyatspi
.STATE_SELECTED
),
38 "Cell does not have selected state (%s)" % cell
)
39 selectioni
.clearSelection()
42 def testTableColumnHeaders(self
):
43 for list_view
in self
.list_views
:
44 tablei
= list_view
.queryTable()
45 for column
in xrange(tablei
.nColumns
):
46 col_acc
= tablei
.getColumnHeader(column
)
48 col_acc
.getRole(), pyatspi
.ROLE_TABLE_COLUMN_HEADER
,
49 "Column header has wrong role (%s)." % col_acc
)
51 col_acc
.getState().contains(pyatspi
.STATE_SELECTABLE
),
52 "Column header should not be selectable (%s)." % col_acc
)
54 def testCellComponentDesktop(self
):
55 self
._testCellComponent
(pyatspi
.DESKTOP_COORDS
)
57 def testCellComponentWindow(self
):
58 self
._testCellComponent
(pyatspi
.WINDOW_COORDS
)
60 def testTableRowColumns(self
):
61 for list_view
in self
.list_views
:
62 tablei
= list_view
.queryTable()
63 for i
, cell
in enumerate(list_view
):
64 if cell
.getRole() != pyatspi
.ROLE_TABLE_CELL
:
66 index
= cell
.getIndexInParent()
69 'Recived index, %d, does not equal %d' % (index
, i
))
71 row
= tablei
.getRowAtIndex(i
)
73 row
, (index
-tablei
.nColumns
)/tablei
.nColumns
,
74 'Row recieved through index, %d, does not equal '
75 'calculated row %d' % \
76 (row
, (index
-tablei
.nColumns
)/tablei
.nColumns
))
78 column
= tablei
.getColumnAtIndex(i
)
79 assert(column
== (index
-tablei
.nColumns
)%tablei
.nColumns
)
80 assert(column
< tablei
.nColumns
)
82 assert(tablei
.getIndexAt(row
, column
) == i
)
83 assert(tablei
.getAccessibleAt(row
, column
) == cell
)
85 def _testCellComponent(self
, coord_type
):
86 for list_view
in self
.list_views
:
87 list_view_bb
= self
._get
_extents
(list_view
, coord_type
)
88 list_view_ci
= list_view
.queryComponent()
89 for cell
in list_view
:
90 if cell
.getState().contains(pyatspi
.STATE_SHOWING
):
91 cell_bb
= self
._get
_extents
(cell
, coord_type
)
93 list_view_bb
.intersect(cell_bb
), cell_bb
,
94 'Cell %s is not completely in rectangle %s.' % \
95 (cell_bb
, list_view_bb
))
96 assert(list_view_bb
.intersect(cell_bb
) == cell_bb
)
98 [(x
,y
) for x
in range(1,4) for y
in range(1,4)]:
99 probe_x
= cell_bb
.x
+ (cell_bb
.width
/4)*n1
100 probe_y
= cell_bb
.y
+ (cell_bb
.height
/4)*n2
101 cell_at_point
= list_view_ci
.getAccessibleAtPoint(
102 probe_x
, probe_y
, coord_type
)
105 'Cell at point, %s, '
106 'does not equal given cell %s' % \
107 (cell_at_point
, cell
))
109 def _get_extents(self
, acc
, coord_type
):
110 ci
= acc
.queryComponent()
111 extents
= ci
.getExtents(coord_type
)
112 return gtk
.gdk
.Rectangle(extents
.x
, extents
.y
,
113 extents
.width
, extents
.height
)
115 def _parent_check(self
, acc
):
117 for i
, child
in enumerate(parent
):
119 assert (i
== acc
.getIndexInParent())
121 raise AssertionError, "child (%s) not in parent (%s)" % (acc
, parent
)
124 if __name__
== '__main__':