diff options
-rw-r--r-- | cmd2/cmd2.py | 102 | ||||
-rw-r--r-- | cmd2/pyscript_bridge.py | 2 | ||||
-rwxr-xr-x | examples/async_printing.py | 10 | ||||
-rw-r--r-- | tests/conftest.py | 2 | ||||
-rw-r--r-- | tests/test_autocompletion.py | 26 | ||||
-rw-r--r-- | tests/test_completion.py | 76 |
6 files changed, 109 insertions, 109 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index f5a2b6fa..6a518978 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -427,14 +427,14 @@ class Cmd(cmd.Cmd): self._script_dir = [] # Context manager used to protect critical sections in the main thread from stopping due to a KeyboardInterrupt - self._sigint_protection = utils.ContextFlag() + self.sigint_protection = utils.ContextFlag() # If the current command created a process to pipe to, then this will be a ProcReader object. # Otherwise it will be None. Its used to know when a pipe process can be killed and/or waited upon. self._cur_pipe_proc_reader = None # Used by complete() for readline tab completion - self._completion_matches = [] + self.completion_matches = [] # Used to keep track of whether we are redirecting or piping output self._redirecting = False @@ -537,7 +537,7 @@ class Cmd(cmd.Cmd): # This lock should be acquired before doing any asynchronous changes to the terminal to # ensure the updates to the terminal don't interfere with the input being typed or output # being printed by a command. - self._terminal_lock = threading.RLock() + self.terminal_lock = threading.RLock() # Commands that have been disabled from use. This is to support commands that are only available # during specific states of the application. This dictionary's keys are the command names and its @@ -688,7 +688,7 @@ class Cmd(cmd.Cmd): # Prevent KeyboardInterrupts while in the pager. The pager application will # still receive the SIGINT since it is in the same process group as us. - with self._sigint_protection: + with self.sigint_protection: pipe_proc = subprocess.Popen(pager, shell=True, stdin=subprocess.PIPE) pipe_proc.communicate(msg_str.encode('utf-8', 'replace')) else: @@ -1398,7 +1398,7 @@ class Cmd(cmd.Cmd): # Check if we either had a parsing error or are trying to complete the command token # The latter can happen if " or ' was entered as the command if len(tokens) <= 1: - self._completion_matches = [] + self.completion_matches = [] return None # Text we need to remove from completions later @@ -1456,20 +1456,20 @@ class Cmd(cmd.Cmd): # Attempt tab completion for redirection first, and if that isn't occurring, # call the completer function for the current command - self._completion_matches = self._redirect_complete(text, line, begidx, endidx, compfunc) + self.completion_matches = self._redirect_complete(text, line, begidx, endidx, compfunc) - if self._completion_matches: + if self.completion_matches: # Eliminate duplicates - self._completion_matches = utils.remove_duplicates(self._completion_matches) + self.completion_matches = utils.remove_duplicates(self.completion_matches) self.display_matches = utils.remove_duplicates(self.display_matches) if not self.display_matches: - # Since self.display_matches is empty, set it to self._completion_matches + # Since self.display_matches is empty, set it to self.completion_matches # before we alter them. That way the suggestions will reflect how we parsed # the token being completed and not how readline did. import copy - self.display_matches = copy.copy(self._completion_matches) + self.display_matches = copy.copy(self.completion_matches) # Check if we need to add an opening quote if not unclosed_quote: @@ -1477,7 +1477,7 @@ class Cmd(cmd.Cmd): add_quote = False # This is the tab completion text that will appear on the command line. - common_prefix = os.path.commonprefix(self._completion_matches) + common_prefix = os.path.commonprefix(self.completion_matches) if self.matches_delimited: # Check if any portion of the display matches appears in the tab completion @@ -1490,36 +1490,36 @@ class Cmd(cmd.Cmd): add_quote = True # If there is a tab completion and any match has a space, then add an opening quote - elif common_prefix and any(' ' in match for match in self._completion_matches): + elif common_prefix and any(' ' in match for match in self.completion_matches): add_quote = True if add_quote: # Figure out what kind of quote to add and save it as the unclosed_quote - if any('"' in match for match in self._completion_matches): + if any('"' in match for match in self.completion_matches): unclosed_quote = "'" else: unclosed_quote = '"' - self._completion_matches = [unclosed_quote + match for match in self._completion_matches] + self.completion_matches = [unclosed_quote + match for match in self.completion_matches] # Check if we need to remove text from the beginning of tab completions elif text_to_remove: - self._completion_matches = \ - [match.replace(text_to_remove, '', 1) for match in self._completion_matches] + self.completion_matches = \ + [match.replace(text_to_remove, '', 1) for match in self.completion_matches] # Check if we need to restore a shortcut in the tab completions # so it doesn't get erased from the command line if shortcut_to_restore: - self._completion_matches = \ - [shortcut_to_restore + match for match in self._completion_matches] + self.completion_matches = \ + [shortcut_to_restore + match for match in self.completion_matches] else: # Complete token against anything a user can run - self._completion_matches = self.basic_complete(text, line, begidx, endidx, - self._get_commands_aliases_and_macros_for_completion()) + self.completion_matches = self.basic_complete(text, line, begidx, endidx, + self._get_commands_aliases_and_macros_for_completion()) # Handle single result - if len(self._completion_matches) == 1: + if len(self.completion_matches) == 1: str_to_append = '' # Add a closing quote if needed and allowed @@ -1530,16 +1530,16 @@ class Cmd(cmd.Cmd): if self.allow_appended_space and endidx == len(line): str_to_append += ' ' - self._completion_matches[0] += str_to_append + self.completion_matches[0] += str_to_append # Sort matches if they haven't already been sorted if not self.matches_sorted: - self._completion_matches.sort(key=self.matches_sort_key) + self.completion_matches.sort(key=self.matches_sort_key) self.display_matches.sort(key=self.matches_sort_key) self.matches_sorted = True try: - return self._completion_matches[state] + return self.completion_matches[state] except IndexError: return None @@ -1631,7 +1631,7 @@ class Cmd(cmd.Cmd): self._cur_pipe_proc_reader.send_sigint() # Check if we are allowed to re-raise the KeyboardInterrupt - if not self._sigint_protection: + if not self.sigint_protection: raise KeyboardInterrupt("Got a keyboard interrupt") def precmd(self, statement: Statement) -> Statement: @@ -1700,7 +1700,7 @@ class Cmd(cmd.Cmd): try: # Get sigint protection while we set up redirection - with self._sigint_protection: + with self.sigint_protection: if pyscript_bridge_call: # Start saving command's stdout at this point self.stdout.pause_storage = False @@ -1743,7 +1743,7 @@ class Cmd(cmd.Cmd): self.pfeedback('Elapsed: {}'.format(datetime.datetime.now() - timestart)) finally: # Get sigint protection while we restore stuff - with self._sigint_protection: + with self.sigint_protection: if saved_state is not None: self._restore_output(statement, saved_state) @@ -1765,7 +1765,7 @@ class Cmd(cmd.Cmd): def _run_cmdfinalization_hooks(self, stop: bool, statement: Optional[Statement]) -> bool: """Run the command finalization hooks""" - with self._sigint_protection: + with self.sigint_protection: if not sys.platform.startswith('win') and self.stdout.isatty(): # Before the next command runs, fix any terminal problems like those # caused by certain binary characters having been printed to it. @@ -2147,10 +2147,10 @@ class Cmd(cmd.Cmd): if self.use_rawinput: try: if sys.stdin.isatty(): - # Wrap in try since _terminal_lock may not be locked when this function is called from unit tests + # Wrap in try since terminal_lock may not be locked when this function is called from unit tests try: # A prompt is about to be drawn. Allow asynchronous changes to the terminal. - self._terminal_lock.release() + self.terminal_lock.release() except RuntimeError: pass @@ -2166,7 +2166,7 @@ class Cmd(cmd.Cmd): finally: if sys.stdin.isatty(): # The prompt is gone. Do not allow asynchronous changes to the terminal. - self._terminal_lock.acquire() + self.terminal_lock.acquire() else: if self.stdin.isatty(): # on a tty, print the prompt first, then read the line @@ -2970,7 +2970,7 @@ class Cmd(cmd.Cmd): # Prevent KeyboardInterrupts while in the shell process. The shell process will # still receive the SIGINT since it is in the same process group as us. - with self._sigint_protection: + with self.sigint_protection: # For any stream that is a StdSim, we will use a pipe so we can capture its output proc = subprocess.Popen(expanded_command, stdout=subprocess.PIPE if isinstance(self.stdout, utils.StdSim) else self.stdout, @@ -3490,7 +3490,7 @@ class Cmd(cmd.Cmd): commands_run = 0 try: - with self._sigint_protection: + with self.sigint_protection: # Disable echo while we manually redirect stdout to a StringIO buffer saved_echo = self.echo saved_stdout = self.stdout @@ -3535,7 +3535,7 @@ class Cmd(cmd.Cmd): if stop: break finally: - with self._sigint_protection: + with self.sigint_protection: # Restore altered attributes to their original state self.echo = saved_echo self.stdout = saved_stdout @@ -3655,7 +3655,7 @@ class Cmd(cmd.Cmd): return self.runcmds_plus_hooks(script_commands) finally: - with self._sigint_protection: + with self.sigint_protection: # Check if a script dir was added before an exception occurred if orig_script_dir_count != len(self._script_dir): self._script_dir.pop() @@ -3765,14 +3765,14 @@ class Cmd(cmd.Cmd): To the user it appears as if an alert message is printed above the prompt and their current input text and cursor location is left alone. - IMPORTANT: This function will not print an alert unless it can acquire self._terminal_lock to ensure + IMPORTANT: This function will not print an alert unless it can acquire self.terminal_lock to ensure a prompt is onscreen. Therefore it is best to acquire the lock before calling this function to guarantee the alert prints. :param alert_msg: the message to display to the user :param new_prompt: if you also want to change the prompt that is displayed, then include it here see async_update_prompt() docstring for guidance on updating a prompt - :raises RuntimeError if called while another thread holds _terminal_lock + :raises RuntimeError if called while another thread holds terminal_lock """ if not (vt100_support and self.use_rawinput): return @@ -3781,8 +3781,8 @@ class Cmd(cmd.Cmd): import colorama.ansi as ansi from colorama import Cursor - # Sanity check that can't fail if self._terminal_lock was acquired before calling this function - if self._terminal_lock.acquire(blocking=False): + # Sanity check that can't fail if self.terminal_lock was acquired before calling this function + if self.terminal_lock.acquire(blocking=False): # Figure out what prompt is displaying current_prompt = self.continuation_prompt if self._at_continuation_prompt else self.prompt @@ -3857,10 +3857,10 @@ class Cmd(cmd.Cmd): # Redraw the prompt and input lines rl_force_redisplay() - self._terminal_lock.release() + self.terminal_lock.release() else: - raise RuntimeError("another thread holds _terminal_lock") + raise RuntimeError("another thread holds terminal_lock") def async_update_prompt(self, new_prompt: str) -> None: # pragma: no cover """ @@ -3870,7 +3870,7 @@ class Cmd(cmd.Cmd): it is best to keep the prompt the same width as what's on screen. Otherwise the user's input text will be shifted and the update will not be seamless. - IMPORTANT: This function will not update the prompt unless it can acquire self._terminal_lock to ensure + IMPORTANT: This function will not update the prompt unless it can acquire self.terminal_lock to ensure a prompt is onscreen. Therefore it is best to acquire the lock before calling this function to guarantee the prompt changes. @@ -3879,7 +3879,7 @@ class Cmd(cmd.Cmd): and display immediately after the multiline line command completes. :param new_prompt: what to change the prompt to - :raises RuntimeError if called while another thread holds _terminal_lock + :raises RuntimeError if called while another thread holds terminal_lock """ self.async_alert('', new_prompt) @@ -3887,18 +3887,18 @@ class Cmd(cmd.Cmd): """ Set the terminal window title - IMPORTANT: This function will not set the title unless it can acquire self._terminal_lock to avoid + IMPORTANT: This function will not set the title unless it can acquire self.terminal_lock to avoid writing to stderr while a command is running. Therefore it is best to acquire the lock before calling this function to guarantee the title changes. :param title: the new window title - :raises RuntimeError if called while another thread holds _terminal_lock + :raises RuntimeError if called while another thread holds terminal_lock """ if not vt100_support: return - # Sanity check that can't fail if self._terminal_lock was acquired before calling this function - if self._terminal_lock.acquire(blocking=False): + # Sanity check that can't fail if self.terminal_lock was acquired before calling this function + if self.terminal_lock.acquire(blocking=False): try: import colorama.ansi as ansi sys.stderr.write(ansi.set_title(title)) @@ -3906,10 +3906,10 @@ class Cmd(cmd.Cmd): # Debugging in Pycharm has issues with setting terminal title pass finally: - self._terminal_lock.release() + self.terminal_lock.release() else: - raise RuntimeError("another thread holds _terminal_lock") + raise RuntimeError("another thread holds terminal_lock") def enable_command(self, command: str) -> None: """ @@ -4027,7 +4027,7 @@ class Cmd(cmd.Cmd): signal.signal(signal.SIGINT, self.sigint_handler) # Grab terminal lock before the prompt has been drawn by readline - self._terminal_lock.acquire() + self.terminal_lock.acquire() # Always run the preloop first for func in self._preloop_hooks: @@ -4056,7 +4056,7 @@ class Cmd(cmd.Cmd): # Release terminal lock now that postloop code should have stopped any terminal updater threads # This will also zero the lock count in case cmdloop() is called again - self._terminal_lock.release() + self.terminal_lock.release() # Restore the original signal handler signal.signal(signal.SIGINT, original_sigint_handler) diff --git a/cmd2/pyscript_bridge.py b/cmd2/pyscript_bridge.py index 0638f1fb..01d283ea 100644 --- a/cmd2/pyscript_bridge.py +++ b/cmd2/pyscript_bridge.py @@ -97,7 +97,7 @@ class PyscriptBridge(object): with redirect_stderr(copy_stderr): stop = self._cmd2_app.onecmd_plus_hooks(command, pyscript_bridge_call=True) finally: - with self._cmd2_app._sigint_protection: + with self._cmd2_app.sigint_protection: self._cmd2_app.stdout = copy_cmd_stdout.inner_stream self.stop = stop or self.stop diff --git a/examples/async_printing.py b/examples/async_printing.py index b59d3d6d..3089070f 100755 --- a/examples/async_printing.py +++ b/examples/async_printing.py @@ -48,7 +48,7 @@ class AlerterApp(cmd2.Cmd): def _preloop_hook(self) -> None: """ Start the alerter thread """ - # This runs after cmdloop() acquires self._terminal_lock, which will be locked until the prompt appears. + # This runs after cmdloop() acquires self.terminal_lock, which will be locked until the prompt appears. # Therefore this is the best place to start the alerter thread since there is no risk of it alerting # before the prompt is displayed. You can also start it via a command if its not something that should # be running during the entire application. See do_start_alerts(). @@ -60,7 +60,7 @@ class AlerterApp(cmd2.Cmd): def _postloop_hook(self) -> None: """ Stops the alerter thread """ - # After this function returns, cmdloop() releases self._terminal_lock which could make the alerter + # After this function returns, cmdloop() releases self.terminal_lock which could make the alerter # thread think the prompt is on screen. Therefore this is the best place to stop the alerter thread. # You can also stop it via a command. See do_stop_alerts(). self._stop_thread = True @@ -169,9 +169,9 @@ class AlerterApp(cmd2.Cmd): self._next_alert_time = 0 while not self._stop_thread: - # Always acquire _terminal_lock before printing alerts or updating the prompt + # Always acquire terminal_lock before printing alerts or updating the prompt # To keep the app responsive, do not block on this call - if self._terminal_lock.acquire(blocking=False): + if self.terminal_lock.acquire(blocking=False): # Get any alerts that need to be printed alert_str = self._generate_alert_str() @@ -191,7 +191,7 @@ class AlerterApp(cmd2.Cmd): self.async_update_prompt(new_prompt) # Don't forget to release the lock - self._terminal_lock.release() + self.terminal_lock.release() time.sleep(0.5) diff --git a/tests/conftest.py b/tests/conftest.py index 9af82637..b049dfff 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -168,7 +168,7 @@ def complete_tester(text: str, line: str, begidx: int, endidx: int, app) -> Opti :param endidx: the ending index of the prefix text :param app: the cmd2 app that will run completions :return: The first matched string or None if there are no matches - Matches are stored in app._completion_matches + Matches are stored in app.completion_matches These matches also have been sorted by complete() """ def get_line(): diff --git a/tests/test_autocompletion.py b/tests/test_autocompletion.py index 72c5e72b..4e1ceff0 100644 --- a/tests/test_autocompletion.py +++ b/tests/test_autocompletion.py @@ -77,7 +77,7 @@ def test_autocomp_flags(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is not None and \ - cmd2_app._completion_matches == ['--duration', '--help', '--type', '-d', '-h', '-t'] + cmd2_app.completion_matches == ['--duration', '--help', '--type', '-d', '-h', '-t'] def test_autcomp_hint(cmd2_app, capsys): text = '' @@ -106,7 +106,7 @@ def test_autcomp_flag_comp(cmd2_app, capsys): out, err = capsys.readouterr() assert first_match is not None and \ - cmd2_app._completion_matches == ['--duration '] + cmd2_app.completion_matches == ['--duration '] def test_autocomp_flags_choices(cmd2_app): @@ -117,7 +117,7 @@ def test_autocomp_flags_choices(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is not None and \ - cmd2_app._completion_matches == ['movie', 'show'] + cmd2_app.completion_matches == ['movie', 'show'] def test_autcomp_hint_in_narg_range(cmd2_app, capsys): @@ -160,7 +160,7 @@ def test_autocomp_subcmd_nested(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is not None and \ - cmd2_app._completion_matches == ['add', 'delete', 'list', 'load'] + cmd2_app.completion_matches == ['add', 'delete', 'list', 'load'] def test_autocomp_subcmd_flag_choices_append(cmd2_app): @@ -171,7 +171,7 @@ def test_autocomp_subcmd_flag_choices_append(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is not None and \ - cmd2_app._completion_matches == ['G', 'NC-17', 'PG', 'PG-13', 'R'] + cmd2_app.completion_matches == ['G', 'NC-17', 'PG', 'PG-13', 'R'] def test_autocomp_subcmd_flag_choices_append_exclude(cmd2_app): text = '' @@ -181,7 +181,7 @@ def test_autocomp_subcmd_flag_choices_append_exclude(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is not None and \ - cmd2_app._completion_matches == ['G', 'NC-17', 'R'] + cmd2_app.completion_matches == ['G', 'NC-17', 'R'] def test_autocomp_subcmd_flag_comp_func(cmd2_app): @@ -192,7 +192,7 @@ def test_autocomp_subcmd_flag_comp_func(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is not None and \ - cmd2_app._completion_matches == ['Adam Driver', 'Alec Guinness', 'Andy Serkis', 'Anthony Daniels'] + cmd2_app.completion_matches == ['Adam Driver', 'Alec Guinness', 'Andy Serkis', 'Anthony Daniels'] def test_autocomp_subcmd_flag_comp_list(cmd2_app): @@ -213,7 +213,7 @@ def test_autocomp_subcmd_flag_comp_func_attr(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is not None and \ - cmd2_app._completion_matches == ['Adam Driver', 'Alec Guinness', 'Andy Serkis', 'Anthony Daniels'] + cmd2_app.completion_matches == ['Adam Driver', 'Alec Guinness', 'Andy Serkis', 'Anthony Daniels'] def test_autocomp_subcmd_flag_comp_list_attr(cmd2_app): @@ -244,7 +244,7 @@ def test_autocomp_pos_after_flag(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is not None and \ - cmd2_app._completion_matches == ['John Boyega" '] + cmd2_app.completion_matches == ['John Boyega" '] def test_autocomp_custom_func_list_arg(cmd2_app): @@ -255,7 +255,7 @@ def test_autocomp_custom_func_list_arg(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is not None and \ - cmd2_app._completion_matches == ['SW_CW', 'SW_REB', 'SW_TCW'] + cmd2_app.completion_matches == ['SW_CW', 'SW_REB', 'SW_TCW'] def test_autocomp_custom_func_list_and_dict_arg(cmd2_app): @@ -266,7 +266,7 @@ def test_autocomp_custom_func_list_and_dict_arg(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is not None and \ - cmd2_app._completion_matches == ['S01E02', 'S01E03', 'S02E01', 'S02E03'] + cmd2_app.completion_matches == ['S01E02', 'S01E03', 'S02E01', 'S02E03'] def test_autocomp_custom_func_dict_arg(cmd2_app): @@ -277,7 +277,7 @@ def test_autocomp_custom_func_dict_arg(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is not None and \ - cmd2_app._completion_matches == ['/home/user/another.db', '/home/user/file space.db', '/home/user/file.db'] + cmd2_app.completion_matches == ['/home/user/another.db', '/home/user/file space.db', '/home/user/file.db'] def test_argparse_remainder_flag_completion(cmd2_app): @@ -333,7 +333,7 @@ def test_completion_after_double_dash(cmd2_app): # Since -- is the last token, then it should show flag choices first_match = complete_tester(text, line, begidx, endidx, cmd2_app) - assert first_match is not None and '--help' in cmd2_app._completion_matches + assert first_match is not None and '--help' in cmd2_app.completion_matches # Test -- to end all flag completion text = '--' diff --git a/tests/test_completion.py b/tests/test_completion.py index 96c1ff79..d5d30e51 100644 --- a/tests/test_completion.py +++ b/tests/test_completion.py @@ -112,7 +112,7 @@ def test_complete_command_single(cmd2_app): begidx = endidx - len(text) first_match = complete_tester(text, line, begidx, endidx, cmd2_app) - assert first_match is not None and cmd2_app._completion_matches == ['help '] + assert first_match is not None and cmd2_app.completion_matches == ['help '] def test_complete_empty_arg(cmd2_app): text = '' @@ -123,7 +123,7 @@ def test_complete_empty_arg(cmd2_app): expected = sorted(cmd2_app.get_visible_commands()) first_match = complete_tester(text, line, begidx, endidx, cmd2_app) - assert first_match is not None and cmd2_app._completion_matches == expected + assert first_match is not None and cmd2_app.completion_matches == expected def test_complete_bogus_command(cmd2_app): text = '' @@ -133,7 +133,7 @@ def test_complete_bogus_command(cmd2_app): expected = ['default '] first_match = complete_tester(text, line, begidx, endidx, cmd2_app) - assert first_match is not None and cmd2_app._completion_matches == expected + assert first_match is not None and cmd2_app.completion_matches == expected def test_complete_exception(cmd2_app, capsys): text = '' @@ -163,7 +163,7 @@ def test_complete_macro(base_app, request): expected = [text + 'cript.py', text + 'cript.txt', text + 'cripts' + os.path.sep] first_match = complete_tester(text, line, begidx, endidx, base_app) - assert first_match is not None and base_app._completion_matches == expected + assert first_match is not None and base_app.completion_matches == expected def test_matches_sort_key(cmd2_app): @@ -176,13 +176,13 @@ def test_matches_sort_key(cmd2_app): cmd2_app.matches_sort_key = cmd2.cmd2.ALPHABETICAL_SORT_KEY expected = ['1', '11', '2'] first_match = complete_tester(text, line, begidx, endidx, cmd2_app) - assert first_match is not None and cmd2_app._completion_matches == expected + assert first_match is not None and cmd2_app.completion_matches == expected # Now switch to natural sorting cmd2_app.matches_sort_key = cmd2.cmd2.NATURAL_SORT_KEY expected = ['1', '2', '11'] first_match = complete_tester(text, line, begidx, endidx, cmd2_app) - assert first_match is not None and cmd2_app._completion_matches == expected + assert first_match is not None and cmd2_app.completion_matches == expected def test_cmd2_command_completion_multiple(cmd2_app): @@ -209,7 +209,7 @@ def test_cmd2_help_completion_single(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) # It is at end of line, so extra space is present - assert first_match is not None and cmd2_app._completion_matches == ['help '] + assert first_match is not None and cmd2_app.completion_matches == ['help '] def test_cmd2_help_completion_multiple(cmd2_app): text = 'h' @@ -218,7 +218,7 @@ def test_cmd2_help_completion_multiple(cmd2_app): begidx = endidx - len(text) first_match = complete_tester(text, line, begidx, endidx, cmd2_app) - assert first_match is not None and cmd2_app._completion_matches == ['help', 'history'] + assert first_match is not None and cmd2_app.completion_matches == ['help', 'history'] def test_cmd2_help_completion_nomatch(cmd2_app): @@ -250,7 +250,7 @@ def test_shell_command_completion_shortcut(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is not None and \ - cmd2_app._completion_matches == expected and \ + cmd2_app.completion_matches == expected and \ cmd2_app.display_matches == expected_display def test_shell_command_completion_doesnt_match_wildcards(cmd2_app): @@ -279,7 +279,7 @@ def test_shell_command_completion_multiple(cmd2_app): begidx = endidx - len(text) first_match = complete_tester(text, line, begidx, endidx, cmd2_app) - assert first_match is not None and expected in cmd2_app._completion_matches + assert first_match is not None and expected in cmd2_app.completion_matches def test_shell_command_completion_nomatch(cmd2_app): text = 'zzzz' @@ -309,7 +309,7 @@ def test_shell_command_completion_does_path_completion_when_after_command(cmd2_a begidx = endidx - len(text) first_match = complete_tester(text, line, begidx, endidx, cmd2_app) - assert first_match is not None and cmd2_app._completion_matches == [text + '.py '] + assert first_match is not None and cmd2_app.completion_matches == [text + '.py '] def test_shell_commmand_complete_in_path(cmd2_app, request): test_dir = os.path.dirname(request.module.__file__) @@ -324,7 +324,7 @@ def test_shell_commmand_complete_in_path(cmd2_app, request): # we expect to see the scripts dir among the results expected = os.path.join(test_dir, 'scripts' + os.path.sep) first_match = complete_tester(text, line, begidx, endidx, cmd2_app) - assert first_match is not None and expected in cmd2_app._completion_matches + assert first_match is not None and expected in cmd2_app.completion_matches def test_path_completion_single_end(cmd2_app, request): @@ -382,7 +382,7 @@ def test_default_to_shell_completion(cmd2_app, request): begidx = endidx - len(text) first_match = complete_tester(text, line, begidx, endidx, cmd2_app) - assert first_match is not None and cmd2_app._completion_matches == [text + '.py '] + assert first_match is not None and cmd2_app.completion_matches == [text + '.py '] def test_path_completion_no_text(cmd2_app): @@ -725,7 +725,7 @@ def test_add_opening_quote_basic_no_text(cmd2_app): # The whole list will be returned with no opening quotes added first_match = complete_tester(text, line, begidx, endidx, cmd2_app) - assert first_match is not None and cmd2_app._completion_matches == sorted(food_item_strs) + assert first_match is not None and cmd2_app.completion_matches == sorted(food_item_strs) def test_add_opening_quote_basic_nothing_added(cmd2_app): text = 'P' @@ -734,7 +734,7 @@ def test_add_opening_quote_basic_nothing_added(cmd2_app): begidx = endidx - len(text) first_match = complete_tester(text, line, begidx, endidx, cmd2_app) - assert first_match is not None and cmd2_app._completion_matches == ['Pizza', 'Potato'] + assert first_match is not None and cmd2_app.completion_matches == ['Pizza', 'Potato'] def test_add_opening_quote_basic_quote_added(cmd2_app): text = 'Ha' @@ -744,7 +744,7 @@ def test_add_opening_quote_basic_quote_added(cmd2_app): expected = sorted(['"Ham', '"Ham Sandwich']) first_match = complete_tester(text, line, begidx, endidx, cmd2_app) - assert first_match is not None and cmd2_app._completion_matches == expected + assert first_match is not None and cmd2_app.completion_matches == expected def test_add_opening_quote_basic_single_quote_added(cmd2_app): text = 'Ch' @@ -754,7 +754,7 @@ def test_add_opening_quote_basic_single_quote_added(cmd2_app): expected = ["'Cheese \"Pizza\"' "] first_match = complete_tester(text, line, begidx, endidx, cmd2_app) - assert first_match is not None and cmd2_app._completion_matches == expected + assert first_match is not None and cmd2_app.completion_matches == expected def test_add_opening_quote_basic_text_is_common_prefix(cmd2_app): # This tests when the text entered is the same as the common prefix of the matches @@ -765,7 +765,7 @@ def test_add_opening_quote_basic_text_is_common_prefix(cmd2_app): expected = sorted(['"Ham', '"Ham Sandwich']) first_match = complete_tester(text, line, begidx, endidx, cmd2_app) - assert first_match is not None and cmd2_app._completion_matches == expected + assert first_match is not None and cmd2_app.completion_matches == expected def test_add_opening_quote_delimited_no_text(cmd2_app): text = '' @@ -775,7 +775,7 @@ def test_add_opening_quote_delimited_no_text(cmd2_app): # The whole list will be returned with no opening quotes added first_match = complete_tester(text, line, begidx, endidx, cmd2_app) - assert first_match is not None and cmd2_app._completion_matches == sorted(delimited_strs) + assert first_match is not None and cmd2_app.completion_matches == sorted(delimited_strs) def test_add_opening_quote_delimited_nothing_added(cmd2_app): text = '/ho' @@ -788,7 +788,7 @@ def test_add_opening_quote_delimited_nothing_added(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is not None and \ - cmd2_app._completion_matches == expected_matches and \ + cmd2_app.completion_matches == expected_matches and \ cmd2_app.display_matches == expected_display def test_add_opening_quote_delimited_quote_added(cmd2_app): @@ -802,7 +802,7 @@ def test_add_opening_quote_delimited_quote_added(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is not None and \ - os.path.commonprefix(cmd2_app._completion_matches) == expected_common_prefix and \ + os.path.commonprefix(cmd2_app.completion_matches) == expected_common_prefix and \ cmd2_app.display_matches == expected_display def test_add_opening_quote_delimited_text_is_common_prefix(cmd2_app): @@ -817,7 +817,7 @@ def test_add_opening_quote_delimited_text_is_common_prefix(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is not None and \ - os.path.commonprefix(cmd2_app._completion_matches) == expected_common_prefix and \ + os.path.commonprefix(cmd2_app.completion_matches) == expected_common_prefix and \ cmd2_app.display_matches == expected_display def test_add_opening_quote_delimited_space_in_prefix(cmd2_app): @@ -832,7 +832,7 @@ def test_add_opening_quote_delimited_space_in_prefix(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is not None and \ - os.path.commonprefix(cmd2_app._completion_matches) == expected_common_prefix and \ + os.path.commonprefix(cmd2_app.completion_matches) == expected_common_prefix and \ cmd2_app.display_matches == expected_display def test_no_completer(cmd2_app): @@ -843,7 +843,7 @@ def test_no_completer(cmd2_app): expected = ['default '] first_match = complete_tester(text, line, begidx, endidx, cmd2_app) - assert first_match is not None and cmd2_app._completion_matches == expected + assert first_match is not None and cmd2_app.completion_matches == expected def test_quote_as_command(cmd2_app): text = '' @@ -852,7 +852,7 @@ def test_quote_as_command(cmd2_app): begidx = endidx - len(text) first_match = complete_tester(text, line, begidx, endidx, cmd2_app) - assert first_match is None and not cmd2_app._completion_matches + assert first_match is None and not cmd2_app.completion_matches @pytest.fixture def sc_app(): @@ -869,7 +869,7 @@ def test_cmd2_subcommand_completion_single_end(sc_app): first_match = complete_tester(text, line, begidx, endidx, sc_app) # It is at end of line, so extra space is present - assert first_match is not None and sc_app._completion_matches == ['foo '] + assert first_match is not None and sc_app.completion_matches == ['foo '] def test_cmd2_subcommand_completion_multiple(sc_app): text = '' @@ -878,7 +878,7 @@ def test_cmd2_subcommand_completion_multiple(sc_app): begidx = endidx - len(text) first_match = complete_tester(text, line, begidx, endidx, sc_app) - assert first_match is not None and sc_app._completion_matches == ['bar', 'foo', 'sport'] + assert first_match is not None and sc_app.completion_matches == ['bar', 'foo', 'sport'] def test_cmd2_subcommand_completion_nomatch(sc_app): text = 'z' @@ -899,7 +899,7 @@ def test_cmd2_help_subcommand_completion_single(sc_app): first_match = complete_tester(text, line, begidx, endidx, sc_app) # It is at end of line, so extra space is present - assert first_match is not None and sc_app._completion_matches == ['base '] + assert first_match is not None and sc_app.completion_matches == ['base '] def test_cmd2_help_subcommand_completion_multiple(sc_app): text = '' @@ -908,7 +908,7 @@ def test_cmd2_help_subcommand_completion_multiple(sc_app): begidx = endidx - len(text) first_match = complete_tester(text, line, begidx, endidx, sc_app) - assert first_match is not None and sc_app._completion_matches == ['bar', 'foo', 'sport'] + assert first_match is not None and sc_app.completion_matches == ['bar', 'foo', 'sport'] def test_cmd2_help_subcommand_completion_nomatch(sc_app): @@ -930,7 +930,7 @@ def test_subcommand_tab_completion(sc_app): first_match = complete_tester(text, line, begidx, endidx, sc_app) # It is at end of line, so extra space is present - assert first_match is not None and sc_app._completion_matches == ['Football '] + assert first_match is not None and sc_app.completion_matches == ['Football '] def test_subcommand_tab_completion_with_no_completer(sc_app): @@ -954,7 +954,7 @@ def test_subcommand_tab_completion_space_in_text(sc_app): first_match = complete_tester(text, line, begidx, endidx, sc_app) assert first_match is not None and \ - sc_app._completion_matches == ['Ball" '] and \ + sc_app.completion_matches == ['Ball" '] and \ sc_app.display_matches == ['Space Ball'] #################################################### @@ -1032,7 +1032,7 @@ def test_cmd2_subcmd_with_unknown_completion_single_end(scu_app): print('first_match: {}'.format(first_match)) # It is at end of line, so extra space is present - assert first_match is not None and scu_app._completion_matches == ['foo '] + assert first_match is not None and scu_app.completion_matches == ['foo '] def test_cmd2_subcmd_with_unknown_completion_multiple(scu_app): @@ -1042,7 +1042,7 @@ def test_cmd2_subcmd_with_unknown_completion_multiple(scu_app): begidx = endidx - len(text) first_match = complete_tester(text, line, begidx, endidx, scu_app) - assert first_match is not None and scu_app._completion_matches == ['bar', 'foo', 'sport'] + assert first_match is not None and scu_app.completion_matches == ['bar', 'foo', 'sport'] def test_cmd2_subcmd_with_unknown_completion_nomatch(scu_app): @@ -1064,7 +1064,7 @@ def test_cmd2_help_subcommand_completion_single_scu(scu_app): first_match = complete_tester(text, line, begidx, endidx, scu_app) # It is at end of line, so extra space is present - assert first_match is not None and scu_app._completion_matches == ['base '] + assert first_match is not None and scu_app.completion_matches == ['base '] def test_cmd2_help_subcommand_completion_multiple_scu(scu_app): @@ -1074,7 +1074,7 @@ def test_cmd2_help_subcommand_completion_multiple_scu(scu_app): begidx = endidx - len(text) first_match = complete_tester(text, line, begidx, endidx, scu_app) - assert first_match is not None and scu_app._completion_matches == ['bar', 'foo', 'sport'] + assert first_match is not None and scu_app.completion_matches == ['bar', 'foo', 'sport'] def test_cmd2_help_subcommand_completion_with_flags_before_command(scu_app): text = '' @@ -1083,7 +1083,7 @@ def test_cmd2_help_subcommand_completion_with_flags_before_command(scu_app): begidx = endidx - len(text) first_match = complete_tester(text, line, begidx, endidx, scu_app) - assert first_match is not None and scu_app._completion_matches == ['bar', 'foo', 'sport'] + assert first_match is not None and scu_app.completion_matches == ['bar', 'foo', 'sport'] def test_complete_help_subcommand_with_no_command(scu_app): # No command because not enough tokens @@ -1123,7 +1123,7 @@ def test_subcommand_tab_completion_scu(scu_app): first_match = complete_tester(text, line, begidx, endidx, scu_app) # It is at end of line, so extra space is present - assert first_match is not None and scu_app._completion_matches == ['Football '] + assert first_match is not None and scu_app.completion_matches == ['Football '] def test_subcommand_tab_completion_with_no_completer_scu(scu_app): @@ -1147,5 +1147,5 @@ def test_subcommand_tab_completion_space_in_text_scu(scu_app): first_match = complete_tester(text, line, begidx, endidx, scu_app) assert first_match is not None and \ - scu_app._completion_matches == ['Ball" '] and \ + scu_app.completion_matches == ['Ball" '] and \ scu_app.display_matches == ['Space Ball'] |