def test_search_commands_sorted(self): command_store = command_store_lib.CommandStore() self.assertEqual(0, command_store.get_num_commands()) command_str = "some command string" command = command_store_lib.Command(command_str, 10.0) command_store.add_command(command) command_str2 = "somelater command string" command2 = command_store_lib.Command(command_str2, 20.0) command_store.add_command(command2) result = command_store.search_commands("some", starts_with=False, sort=True) self.assertEqual(result[0], command2) self.assertEqual(result[1], command)
def test_addCommandToStore(self): command_store = command_store_lib.CommandStore() self.assertEqual(0, command_store.get_num_commands()) command_str = "some command string" command = command_store_lib.Command(command_str) command_store.add_command(command) self.assertTrue(command_store.has_command(command)) self.assertFalse( command_store.has_command( command_store_lib.Command("some other command"))) self.assertEqual(1, command_store.get_num_commands()) self.assertEqual(command, command_store.get_command_by_name(command_str)) self.assertEqual( None, command_store.get_command_by_name("non existent command string"))
def test_command_parseArgs(self): command_str = 'git diff HEAD^ src/b/FragmentOnlyDetector.java' command = command_store_lib.Command(command_str, 1234.1234) self.assertEqual(command.get_primary_command(), 'git') self.assertEqual(command.get_command_args(), ['diff', 'HEAD^', 'src/b/FragmentOnlyDetector.java']) self.assertEqual(1234.1234, command.last_used_time()) command_str = 'git' command = command_store_lib.Command(command_str, 1234.1234) self.assertEqual(command.get_primary_command(), 'git') self.assertEqual(command.get_command_args(), []) self.assertEqual(1234.1234, command.last_used_time()) command._increment_count() self.assertEqual(1234.1234, command.last_used_time()) command._update_time(4321) self.assertEqual(4321, command.last_used_time())
def test_print_commands_whenSingleCommand_shouldPrint(self) -> None: command_str = 'git diff HEAD^ src/b/FragmentOnlyDetector.java' command = command_store_lib.Command(command_str, 1234.1234) command_list = [command] with patch('sys.stdout', new_callable=io.StringIO) as std_out_mock: command_store_lib.print_commands(command_list) expected = command_store_lib._create_indexed_highlighted_print_string( 1, command_str, command) + '\n' self.assertEqual(expected, std_out_mock.getvalue())
def test_update_command_whenAddCommandToStore_shouldSetBackingStore(self) -> None: store = command_store_lib.SqlCommandStore() command = command_store_lib.Command('Some command') store.add_command(command) command_info_str = 'Some Info' command.set_command_info(command_info_str) store.update_command_info(command) result = store.search_commands(['Some'])[0] self.assertEqual(command.get_unique_command_id(), result.get_unique_command_id()) self.assertEqual(command_info_str, result.get_command_info())
def test_print_commands_whenSingleCommandWithHighlights_shouldPrintWithHighlights(self) -> None: command_str = 'git diff' command = command_store_lib.Command(command_str, 1234.1234) command_list = [command] with patch('sys.stdout', new_callable=io.StringIO) as std_out_mock: command_store_lib.print_commands(command_list, ['git']) expected = command_store_lib._create_indexed_highlighted_print_string( 1, command_str, command) + '\n' expected = command_store_lib._highlight_term_in_string(expected, 'git') self.assertEqual(expected, std_out_mock.getvalue())
def test_verifySqldb_shouldSaveAndStore_whenCommandIsAdded(self) -> None: file_name = '' try: file_name = os.path.join(TEST_PATH_DIR, "delete_test_pickle.db") command_store = command_store_lib.SqlCommandStore(file_name) command_str = "git branch" command = command_store_lib.Command(command_str) command_store.add_command(command) command_store = command_store_lib.load_command_store(file_name) self.assertTrue(command_store.has_command(command)) finally: if file_name: os.remove(file_name)
def test_sqlCommandStore_whenAddingItem_shouldReturnTrueWhenSearching(self) -> None: file_path = '' try: file_path = os.path.join(TEST_PATH_DIR, "delete_test_sql_store.db") command_store = command_store_lib.SqlCommandStore(file_path) command_str = "git branch" command = command_store_lib.Command(command_str) command_store.add_command(command) command_store = command_store_lib.load_command_store(file_path) self.assertTrue(command_store.has_command(command)) finally: if file_path: os.remove(file_path)
def test_verifyPickle_shouldSaveAndStore_whenCommandIsAdded(self): file_path = '' try: file_name = os.path.join(TEST_PATH_DIR, "delete_test_pickle.pickle") command_store = command_store_lib.CommandStore() command_str = "git branch" command = command_store_lib.Command(command_str) command_store.add_command(command) command_store_lib.save_command_store(command_store, file_name) command_store = command_store_lib.load_command_store(file_name) self.assertTrue(command_store.has_command(command)) finally: if file_path: os.remove(file_path)
def test_jsonSave_shouldLoadCommandStoreFromJson_whenCommandIsAddedAndStoreSaved( self): file_name = '' try: file_name = os.path.join(TEST_PATH_DIR, "delete_test_json.json") command_store = command_store_lib.CommandStore() command_str = "git branch" command = command_store_lib.Command(command_str) command_store.add_command(command) command_store_lib.save_command_store(command_store, file_name, True) command_store = command_store_lib.load_command_store( file_name, command_store_lib.JSON_STORE) self.assertTrue(command_store.has_command(command)) finally: if file_name: os.remove(file_name)
def test_verifyPickle_withJson(self): use_json = True file_path = '' try: file_path = os.path.join(TEST_PATH_DIR, "delete_test_pickle.pickle") command_store = command_store_lib.CommandStore() command_str = "git branch" command = command_store_lib.Command(command_str) command_store.add_command(command) command_store_lib.save_command_store(command_store, file_path, use_json) command_store = command_store_lib.load_command_store( file_path, command_store_lib.JSON_STORE) self.assertTrue(command_store.has_command(command)) finally: if file_path: os.remove(file_path)
def test_Command_checkConstructor(self) -> None: command = command_store_lib.Command(" git branch") self.assertEqual("git branch", command.get_unique_command_id()) command = command_store_lib.Command("git branch") self.assertEqual("git branch", command.get_unique_command_id())