def launch_merge_tool(self): items = self.conflicts_list.selectedItems() enabled, error_msg = self.is_merge_tool_launchable() if not enabled: return config = GlobalConfig() cmdline = config.find_merge_tool( unicode(self.merge_tools_combo.currentText())) file_id = str(items[0].data(0, QtCore.Qt.UserRole).toString()) if not file_id: # bug https://bugs.launchpad.net/qbzr/+bug/655451 return file_name = self.wt.abspath(self.wt.id2path(file_id)) process = QtCore.QProcess(self) def qprocess_invoker(executable, args, cleanup): def qprocess_error(error): self.show_merge_tool_error(error) cleanup(process.exitCode()) def qprocess_finished(exit_code, exit_status): cleanup(exit_code) self.connect(process, QtCore.SIGNAL("error(QProcess::ProcessError)"), qprocess_error) self.connect(process, QtCore.SIGNAL("finished(int,QProcess::ExitStatus)"), qprocess_finished) process.start(executable, args) mergetools.invoke(cmdline, file_name, qprocess_invoker)
def test_failure(self): def dummy_invoker(exe, args, cleanup): self._exe = exe self._args = args cleanup(1) return 1 retcode = mergetools.invoke('tool {result}', 'test.txt', dummy_invoker) self.assertEqual(1, retcode) self.assertEqual('tool', self._exe) self.assertEqual(['test.txt'], self._args)
def test_success(self): def dummy_invoker(exe, args, cleanup): self._exe = exe self._args = args cleanup(0) return 0 retcode = mergetools.invoke('tool {result}', 'test.txt', dummy_invoker) self.assertEqual(0, retcode) self.assertEqual('tool', self._exe) self.assertEqual(['test.txt'], self._args)
def test_invoke_expands_exe_path(self): self.overrideEnv('PATH', os.path.dirname(sys.executable)) def dummy_invoker(exe, args, cleanup): self._exe = exe self._args = args cleanup(0) return 0 command = '%s {result}' % os.path.basename(sys.executable) retcode = mergetools.invoke(command, 'test.txt', dummy_invoker) self.assertEqual(0, retcode) self.assertEqual(sys.executable, self._exe) self.assertEqual(['test.txt'], self._args)
def test_success_tempfile(self): def dummy_invoker(exe, args, cleanup): self._exe = exe self._args = args self.assertPathExists(args[0]) f = open(args[0], 'wt') f.write('temp stuff') f.close() cleanup(0) return 0 retcode = mergetools.invoke('tool {this_temp}', 'test.txt', dummy_invoker) self.assertEqual(0, retcode) self.assertEqual('tool', self._exe) self.assertPathDoesNotExist(self._args[0]) self.assertFileEqual('temp stuff', 'test.txt')
def test_failure_tempfile(self): def dummy_invoker(exe, args, cleanup): self._exe = exe self._args = args self.assertPathExists(args[0]) self.log(repr(args)) f = open(args[0], 'wt') self.log(repr(f)) f.write('temp stuff') f.close() cleanup(1) return 1 retcode = mergetools.invoke('tool {this_temp}', 'test.txt', dummy_invoker) self.assertEqual(1, retcode) self.assertEqual('tool', self._exe) self.assertFileEqual('stuff', 'test.txt')