Exemple #1
0
 def run_sh(self, args=[]):
     new_args = ["p4runtime-sh", "--grpc-addr", self.grpc_addr] + args
     rc = 0
     stdout = None
     with patch('sys.argv', new_args):
         with patch('sys.stdout', new_callable=StringIO) as mock_stdout:
             # patching input() only works in simple_prompt mode
             # we could also raise EOFError as a side_effect, it seems that it does not required
             # confirmation in simple_prompt mode
             # https://ipython.readthedocs.io/en/stable/config/options/terminal.html#configtrait-TerminalInteractiveShell.simple_prompt
             # the best way to do that is to set IPY_TEST_SIMPLE_PROMPT, but this needs to be
             # done before importing IPython, which we do at the beginning of the file
             # an alternative is to patch the
             # IPython.terminal.interactiveshell.TerminalInteractiveShell object so that the
             # 'simple_prompt' attribute is True.
             with patch('builtins.input', return_value="exit"):
                 try:
                     sh.main()
                 except SystemExit as e:
                     rc = e.code
                 stdout = mock_stdout.getvalue()
     return rc, stdout
Exemple #2
0
from p4runtime_sh.shell import main
main()  # pragma: no cover