def test_display_and_interact_whenSaveAndExecute_shouldDoBoth( self, save_search: Mock, load_interactor: Mock) -> None: results = [Command('grep command'), Command('vim command')] rr = display_and_interact_results(results, 5, 'save_dir', 'history_file', ['grep'], True) self.assertEqual(rr, None) expected_path = os.path.join("save_dir", command_store_lib.DEFAULT_LAST_SAVE_FILE_NAME) save_search.assert_called_once_with(expected_path, results) load_interactor.assert_called_once_with('history_file')
def run_remember_command(save_dir: str, history_file_path: str, query: List[str], search_all: bool, search_starts_with: bool, execute: bool, max_return_count: int) -> Optional[str]: store_file_path = command_store.get_file_path(save_dir) store = command_store.load_command_store(store_file_path) command_store.start_history_processing(store, history_file_path, save_dir, 20) print('Looking for all past commands with: ' + ", ".join(query)) start_time = time.time() result = store.search_commands(query, search_starts_with, search_info=search_all) total_time = time.time() - start_time print("Search time %.5f: seconds" % total_time) return display_and_interact_results( result, max_return_count, save_dir, history_file_path, query, execute)
def run_history_command(save_dir: str, history_file_path: str, directory: str, execute: bool, max_results: int, search_term: str) -> Optional[str]: search_term_list = [search_term] if search_term else [] store_file_path = command_store.get_file_path(save_dir) store = command_store.load_command_store(store_file_path) command_store.start_history_processing(store, history_file_path, save_dir, 1) print(f'Looking for all past commands with: {directory}') start_time = time.time() result = store.get_command_with_context(directory, search_term_list) total_time = time.time() - start_time print("Search time %.5f: seconds" % total_time) return display_and_interact_results( result, max_results, save_dir, history_file_path, None, execute)
def test_display_nd_interact_whenUserChooses1_shouldDo1( self, save_search: Mock, load_interactor: Mock, subprocess_mock: Mock, print_mock: Mock) -> None: command = Command('grep command') results = [command, Command('vim command')] user_input = ['1'] with patch('builtins.input', side_effect=user_input): rr = display_and_interact_results( results, 1, 'save_dir', 'history_file', ['grep'], True) self.assertEqual(rr, None) expected_path = os.path.join("save_dir", command_store_lib.DEFAULT_LAST_SAVE_FILE_NAME) results = results[:1] save_search.assert_called_once_with(expected_path, results) load_interactor.assert_called_once_with('history_file') shell_env = os.getenv('SHELL') call_args = [shell_env, '-i', '-c', command.get_unique_command_id()] subprocess_mock.assert_called_once_with(call_args) print_mock.assert_called_once()