def ensure_app_has_quit(self): """Terminate as gracefully as possible the application and ensure that it has fully quit before returning""" if model() == "Desktop": # On desktop to cleanly quit an app we just do the # equivalent of clicking on the close button in the window. self.keyboard.press_and_release("Alt+F4") else: # On unity8 at the moment we have no clean way to close the app. # So we ask the shell first to show the home, unfocusing our app, # which will save its state. Then we simply send it a SIGTERM to # force it to quit. # See bug https://bugs.launchpad.net/unity8/+bug/1261720 for more # details. from unity8 import process_helpers pid = process_helpers._get_unity_pid() unity8 = get_proxy_object_for_existing_process(pid=pid) shell = unity8.select_single("Shell") shell.slots.showHome() self.assertThat(shell.focusedApplicationId, Eventually(NotEquals("gallery-app"))) self.app.process.send_signal(signal.SIGTERM) # Either way, we wait for the underlying process to be fully finished. self.app.process.wait() self.assertIsNotNone(self.app.process.returncode)
def _assertUnityReady(): unity_pid = process_helpers._get_unity_pid() unity = get_proxy_object_for_existing_process( pid=unity_pid, emulator_base=UnityEmulatorBase, ) dash = unity.wait_select_single(Dash) home_scope = dash.get_scope('home') home_scope.isLoaded.wait_for(True) home_scope.isCurrent.wait_for(True)
def _create_sensors(self): # Wait for unity to start running. Eventually(Equals(True)).match( lambda: process_helpers.is_job_running('unity8')) # Wait for the sensors fifo file to be created. fifo_path = '/tmp/sensor-fifo-{0}'.format( process_helpers._get_unity_pid()) Eventually(Equals(True)).match( lambda: os.path.exists(fifo_path)) with open(fifo_path, 'w') as fifo: fifo.write('create accel 0 1000 0.1\n') fifo.write('create light 0 10 1\n') fifo.write('create proximity\n')
def __init__(self, pid=None): self.pid = pid or process_helpers._get_unity_pid()