HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-172-31-4-197 6.8.0-1036-aws #38~22.04.1-Ubuntu SMP Fri Aug 22 15:44:33 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //usr/lib/python3.8/site-packages/indicator_keyboard/tests/test_indicator_keyboard.py
import autopilot.introspection.gtk
import os
import pyatspi.registry
import pyatspi.utils
import time
import unity.tests

def print_accessible(root, level=0):
    print level * ' ', root

    for node in root:
        print_accessible(node, level + 1)

def get_accessible_with_name_and_role(root, name, role):
    is_accessible = lambda a: a.name == name and a.get_role_name() == role
    return pyatspi.utils.findDescendant(root, is_accessible, True);

def get_panel_accessible(root):
    return get_accessible_with_name_and_role(root, 'unity-panel-service', 'application')

def is_indicator_accessible(root):
    return root.get_role_name() == 'panel' and \
           len(root) == 1 and \
           root[0].get_role_name() == 'image' and \
           len(root[0]) == 1 and \
           root[0][0].get_role_name() == 'menu' and \
           len(root[0][0]) > 3 and \
           root[0][0][-3].name == 'Character Map' and \
           root[0][0][-3].get_role_name() == 'check menu item' and \
           root[0][0][-2].name == 'Keyboard Layout Chart' and \
           root[0][0][-2].get_role_name() == 'check menu item' and \
           root[0][0][-1].name == 'Text Entry Settings...' and \
           root[0][0][-1].get_role_name() == 'check menu item'

def get_indicator_accessible(root):
    return pyatspi.utils.findDescendant(root, is_indicator_accessible, True)

def get_accessible_index(root, node):
    for i in xrange(len(root)):
        if root[i] == node:
            return i

    return -1

class IndicatorKeyboardTestCase(unity.tests.UnityTestCase):

    def setUp(self):
        super(IndicatorKeyboardTestCase, self).setUp()

        registry = pyatspi.registry.Registry()
        desktop = registry.getDesktop(0)
        panel = get_panel_accessible(desktop)
        self.indicator = get_indicator_accessible(panel)

        # This is needed on systems other than the EN locale
        os.putenv("LC_ALL", "C")
        self.addCleanup(os.unsetenv, "LC_ALL")

    def test_indicator(self):
        print_accessible(self.indicator)