def test_delete_whenExists_shouldDeleteFromStore(self): file_name = os.path.join(TEST_FILES_PATH, "test_input.txt") self.assertTrue(os.path.isfile(file_name)) store = command_store_lib.CommandStore() command_store_lib.read_history_file(store, file_name, "doesntmatter", None, False) self.assertTrue(store.has_command_by_name("vim somefile.txt")) self.assertIsNotNone(store.delete_command('vim somefile.txt')) self.assertFalse(store.has_command_by_name("vim somefile.txt"))
def test_delete_command_from_store_with_exit_input_should_not_delete(self): store = command_store_lib.CommandStore() command = Command("testing delete this command") store.add_command(command) self.assertEqual(store.get_num_commands(), 1) interactive = InteractiveCommandExecutor() self.set_input('quit') self.assertFalse(interactive.delete_interaction(store, [command])) self.assertEqual(store.get_num_commands(), 1) self.reset_input()
def test_search_commands(self): file_name = os.path.join(TEST_FILES_PATH, "test_input.txt") store = command_store_lib.CommandStore() command_store_lib.read_history_file(store, file_name, "doesntmatter", None, False) matches = store.search_commands(["add"]) self.assertIsNotNone(matches) matches = store.search_commands(["add"], True) self.assertTrue(len(matches) == 0) matches = store.search_commands(["subl"], True) self.assertTrue(len(matches) == 1)
def test_delete_command_from_store_with_1_2_should_remove_all(self): store = command_store_lib.CommandStore() command = Command("testing delete this command") command2 = Command("remove this also") self.assertEqual(store.get_num_commands(), 0) store.add_command(command) store.add_command(command2) self.assertEqual(store.get_num_commands(), 2) interactive = InteractiveCommandExecutor() self.set_input('1, 2', 'y') self.assertTrue(interactive.delete_interaction(store, [command, command2])) self.assertEqual(store.get_num_commands(), 0) self.reset_input()
def test_readFile(self): file_name = os.path.join(TEST_FILES_PATH, "test_input.txt") store = command_store_lib.CommandStore() command_store_lib.read_history_file(store, file_name, "doesntmatter", None, False) self.assertTrue(store.has_command_by_name("vim somefile.txt")) self.assertTrue(store.has_command_by_name("rm somefile.txt")) self.assertTrue(store.has_command_by_name("whereis script")) self.assertTrue(store.has_command_by_name("vim /usr/bin/script")) self.assertFalse(store.has_command_by_name("vim somefil")) self.assertEqual( 2, store.get_command_by_name("rm somefile.txt").get_count_seen())
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_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_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_run_when_command_is_executed(self): old_call = subprocess.call store = command_store_lib.CommandStore() command_str = "testing delete this command" command = Command(command_str) command2 = Command("remove this also") test_call = partial(self.subprocess_call_mock, expected=command_str) subprocess.call = test_call self.assertEqual(store.get_num_commands(), 0) store.add_command(command) store.add_command(command2) self.assertEqual(store.get_num_commands(), 2) interactive = InteractiveCommandExecutor() self.set_input('1') self.assertTrue(interactive.run([command, command2])) self.reset_input() subprocess.call = old_call
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_ignoreRule_whenFileDoestExist_shouldNotCrash(self): file_name = os.path.join(TEST_FILES_PATH, "test_input.txt") store = command_store_lib.CommandStore() command_store_lib.read_history_file(store, file_name, "doesntmatter", "test_files/fileNotthere.txt", False)
def test_delete_whenDoesntExists_shouldDeleteFromStore(self): store = command_store_lib.CommandStore() self.assertIsNone(store.delete_command('anything'))
def test_CommandStore_isEmpty(self): command_store = command_store_lib.CommandStore() self.assertEqual(0, command_store.get_num_commands())