def test_ensure_desktop_dir_exists_creates_dir_when_needed(self): tmp_dir = tempfile.mkdtemp(dir="/tmp") self.addCleanup(rmtree, tmp_dir) desktop_file_dir = os.path.join(tmp_dir, '.local', 'share', 'applications') with patch.object(TempDesktopFile, '_desktop_file_dir', return_value=desktop_file_dir): TempDesktopFile._ensure_desktop_dir_exists() self.assertTrue(os.path.exists(desktop_file_dir))
def test_create_desktop_file_dir_returns_empty_str_when_path_exists(self): desktop_file_dir = tempfile.mkdtemp(dir="/tmp") self.addCleanup(rmtree, desktop_file_dir) self.assertThat( TempDesktopFile._create_desktop_file_dir(desktop_file_dir), Equals(""))
def test_can_launch_normal_app(self): path = self.get_qml_viewer_app_path() fixture = self.useFixture(TempDesktopFile(exec_=path, )) launcher = self.useFixture(NormalApplicationLauncher()) app_proxy = launcher.launch( path, ['--desktop_file_hint=%s' % fixture.get_desktop_file_path()], app_type='qt') self.assertTrue(app_proxy is not None)
def test_ensure_desktop_dir_exists_returns_empty_string_when_exists(self): desktop_file_dir = tempfile.mkdtemp(dir="/tmp") self.addCleanup(rmtree, desktop_file_dir) with patch.object(TempDesktopFile, '_desktop_file_dir', return_value=desktop_file_dir): self.assertThat(TempDesktopFile._ensure_desktop_dir_exists(), Equals(""))
def test_create_desktop_file_dir_returns_path_to_delete(self): tmp_dir = tempfile.mkdtemp(dir="/tmp") self.addCleanup(rmtree, tmp_dir) desktop_file_dir = os.path.join(tmp_dir, '.local', 'share', 'applications') expected_to_remove = os.path.join(tmp_dir, '.local') self.assertThat( TempDesktopFile._create_desktop_file_dir(desktop_file_dir), Equals(expected_to_remove))
def test_create_desktop_file_creates_file_in_correct_place(self): desktop_file_dir = tempfile.mkdtemp(dir="/tmp") self.addCleanup(rmtree, desktop_file_dir) with patch.object(TempDesktopFile, '_desktop_file_dir', return_value=desktop_file_dir): desktop_file = TempDesktopFile._create_desktop_file("") path, head = os.path.split(desktop_file) self.assertThat(path, Equals(desktop_file_dir))
def test_create_desktop_file_writes_correct_data(self): desktop_file_dir = tempfile.mkdtemp(dir="/tmp") self.addCleanup(rmtree, desktop_file_dir) token = self.getUniqueString() with patch.object(TempDesktopFile, '_desktop_file_dir', return_value=desktop_file_dir): desktop_file = TempDesktopFile._create_desktop_file(token) self.assertTrue(desktop_file.endswith('.desktop')) self.assertThat(desktop_file, FileContains(token))
def test_ensure_desktop_dir_exists_returns_path_to_delete(self): tmp_dir = tempfile.mkdtemp(dir="/tmp") self.addCleanup(rmtree, tmp_dir) desktop_file_dir = os.path.join(tmp_dir, '.local', 'share', 'applications') expected_to_remove = os.path.join(tmp_dir, '.local') with patch.object(TempDesktopFile, '_desktop_file_dir', return_value=desktop_file_dir): self.assertThat(TempDesktopFile._ensure_desktop_dir_exists(), Equals(expected_to_remove))
def test_setUp_creates_desktop_file(self): desktop_file_dir = tempfile.mkdtemp(dir="/tmp") self.addCleanup(rmtree, desktop_file_dir) with patch.object(TempDesktopFile, '_desktop_file_dir', return_value=desktop_file_dir): temp_desktop_file = TempDesktopFile() temp_desktop_file.setUp() desktop_file_path = temp_desktop_file.get_desktop_file_path() self.assertTrue(os.path.exists(desktop_file_path)) temp_desktop_file.cleanUp() self.assertFalse(os.path.exists(desktop_file_path))
def start_qml_script(self, script_contents): """Launch a qml script.""" qml_path = mktemp(suffix='.qml') open(qml_path, 'w').write(script_contents) self.addCleanup(os.remove, qml_path) extra_args = '' if platform.model() != "Desktop": # We need to add the desktop-file-hint desktop_file = self.useFixture( TempDesktopFile()).get_desktop_file_path() extra_args = '--desktop_file_hint={hint_file}'.format( hint_file=desktop_file) return self.launch_test_application( "qmlscene", "-qt=qt5", qml_path, extra_args, app_type='qt', )
def launch_test_qml(self): arch = subprocess.check_output( ["dpkg-architecture", "-qDEB_HOST_MULTIARCH"], universal_newlines=True).strip() qml_path = tempfile.mktemp(suffix='.qml') open(qml_path, 'w').write(self.test_qml) self.addCleanup(os.remove, qml_path) extra_args = '' if platform.model() != "Desktop": # We need to add the desktop-file-hint desktop_file = self.useFixture( TempDesktopFile() ).get_desktop_file_path() extra_args = '--desktop_file_hint={hint_file}'.format( hint_file=desktop_file ) return self.launch_test_application( "/usr/lib/" + arch + "/qt5/bin/qmlscene", qml_path, extra_args, emulator_base=EmulatorBase)
def test_can_launch_upstart_app(self): path = self.get_qml_viewer_app_path() fixture = self.useFixture(TempDesktopFile(exec_=path, )) launcher = self.useFixture(UpstartApplicationLauncher()) launcher.launch(fixture.get_desktop_file_id())
def test_desktop_file_dir_returns_expected_directory(self): expected_directory = os.path.join(os.getenv('HOME'), '.local', 'share', 'applications') self.assertThat(TempDesktopFile._desktop_file_dir(), Equals(expected_directory))
def do_parameter_contents_test(self, matcher, **kwargs): fixture = self.useFixture(TempDesktopFile(**kwargs)) self.assertThat( fixture.get_desktop_file_path(), FileContains(matcher=matcher), )
def test_remove_desktop_file_removes_created_path(self): test_created_file = self.getUniqueString() with patch('autopilot.tests.functional.os.remove') as p_remove: TempDesktopFile._remove_desktop_file_components( "", test_created_file) p_remove.assert_called_once_with(test_created_file)
def test_remove_desktop_file_removes_created_file_when_path_exists(self): test_created_path = self.getUniqueString() with patch('autopilot.tests.functional.fixtures.rmtree') as p_rmtree: TempDesktopFile._remove_desktop_file_components( test_created_path, "") p_rmtree.assert_called_once_with(test_created_path)