Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set prompt correctly for zsh #712

Merged
merged 7 commits into from Sep 29, 2023
Merged

Conversation

kbriggs
Copy link
Contributor

@kbriggs kbriggs commented Feb 9, 2022

Fixes #711

pexpect/pxssh.py Outdated Show resolved Hide resolved
pexpect/pxssh.py Outdated Show resolved Hide resolved
Adds support to fakessh to emulate a specific shell with respect to
prompt setting. The shell is specified as a parameter after the
hostname, similar to real ssh taking a command to execute on the remote.
This is slightly awkward when calling pxssh.login() as it means giving
the server parameter as 'hostname shell', but this is only needed for
the unit tests.
When the remote system/user is using zsh as their login shell, `\$` is
not an escape sequence for the prompt, and so self.PROMPT fails to match
because the backslash is included in the received text. The equivalent
escape sequence for zsh is `%(!.#.$)`, so add a self.PROMPT_SET_ZSH using
this sequence.

Fixes pexpect#711
Many zsh users also use the prompt theme system from oh-my-zsh. This
overrides the `PS1` setting, so setting the prompt fails for these
users. Add the `prompt restore` command to disable oh-my-zsh's prompt
and use the set `PS1` value.
@Red-M
Copy link
Member

Red-M commented Feb 9, 2022

I'm not sure why but the tests are not running, can you please confirm that you've locally run the tests and I can confirm later to complete the merge.

@kbriggs
Copy link
Contributor Author

kbriggs commented Feb 9, 2022

I'm not sure why but the tests are not running, can you please confirm that you've locally run the tests and I can confirm later to complete the merge.

The new tests and all existing tests in test_pxssh.py pass locally:

 % virtualenv venv2
created virtual environment CPython3.6.9.final.0-64 in 3622ms
<…>
 % . venv2/bin/activate
 % pip3 install -e .
<…>
Successfully installed pexpect-4.8.0 ptyprocess-0.7.0
 % pip3 install -r requirements-testing.txt
<…>
Installing collected packages: zipp, typing-extensions, pyparsing, importlib-metadata, urllib3, tomli, py, pluggy, packaging, iniconfig, idna, coverage, charset-normalizer, certifi, attrs, requests, pytest, docopt, pytest-cov, pytest-capturelog, coveralls
Successfully installed attrs-21.4.0 certifi-2021.10.8 charset-normalizer-2.0.11 coverage-6.2 coveralls-3.3.1 docopt-0.6.2 idna-3.3 importlib-metadata-4.8.3 iniconfig-1.1.1 packaging-21.3 pluggy-1.0.0 py-1.11.0 pyparsing-3.0.7 pytest-7.0.0 pytest-capturelog-0.7 pytest-cov-3.0.0 requests-2.27.1 tomli-1.2.3 typing-extensions-4.0.1 urllib3-1.26.8 zipp-3.6.0
 % py.test tests/test_pxssh.py
<…>/pexpect/venv2/lib/python3.6/site-packages/_pytest/config/__init__.py:455: PytestConfigWarning: pytest-capturelog plugin has been merged into the core, please remove it from your requirements.
  name.replace("_", "-")
============================= test session starts ==============================
platform linux -- Python 3.6.9, pytest-7.0.0, pluggy-1.0.0
rootdir: <…>/pexpect, configfile: setup.cfg
plugins: capturelog-0.7, cov-3.0.0
collected 21 items

tests/test_pxssh.py .....................                                [100%]

============================= 21 passed in 37.34s ==============================

In a full test suite there's just one unrelated failure in test_replwrap.py, but that also fails locally without these changes so seems to be a separate problem:

 % py.test
<…>/pexpect/venv2/lib/python3.6/site-packages/_pytest/config/__init__.py:455: PytestConfigWarning: pytest-capturelog plugin has been merged into the core, please remove it from your requirements.
  name.replace("_", "-")
============================= test session starts ==============================
platform linux -- Python 3.6.9, pytest-7.0.0, pluggy-1.0.0
rootdir: <…>/pexpect, configfile: setup.cfg
plugins: capturelog-0.7, cov-3.0.0
collected 242 items

tests/test_FSM.py .                                                      [  0%]
tests/test_ansi.py .........                                             [  4%]
tests/test_async.py .........                                            [  7%]
tests/test_command_list_split.py .                                       [  8%]
tests/test_constructor.py ..                                             [  9%]
tests/test_ctrl_chars.py .....                                           [ 11%]
tests/test_delay.py ..                                                   [ 11%]
tests/test_destructor.py .                                               [ 12%]
tests/test_dotall.py ..                                                  [ 13%]
tests/test_env.py ....                                                   [ 14%]
tests/test_expect.py ........................................            [ 31%]
tests/test_filedescriptor.py .....                                       [ 33%]
tests/test_interact.py ...                                               [ 34%]
tests/test_isalive.py .........                                          [ 38%]
tests/test_log.py ....                                                   [ 40%]
tests/test_misc.py ..............................                        [ 52%]
tests/test_missing_command.py .                                          [ 52%]
tests/test_performance.py ..                                             [ 53%]
tests/test_pickling.py .                                                 [ 54%]
tests/test_popen_spawn.py ...........                                    [ 58%]
tests/test_pxssh.py .....................                                [ 67%]
tests/test_replwrap.py F........                                         [ 71%]
tests/test_repr.py ...                                                   [ 72%]
tests/test_run.py .................                                      [ 79%]
tests/test_screen.py ...........                                         [ 83%]
tests/test_socket.py .............                                       [ 89%]
tests/test_timeout_pattern.py .....                                      [ 91%]
tests/test_unicode.py ...........                                        [ 95%]
tests/test_which.py .......                                              [ 98%]
tests/test_winsize.py ...                                                [100%]

=================================== FAILURES ===================================
__________________________ REPLWrapTestCase.test_bash __________________________

self = <tests.test_replwrap.REPLWrapTestCase testMethod=test_bash>

    def test_bash(self):
        bash = replwrap.bash()
        res = bash.run_command("alias")
>       assert 'alias' in res, res
E       AssertionError:
E       assert 'alias' in ''

<…>/pexpect/tests/test_replwrap.py:29: AssertionError
=============================== warnings summary ===============================
pexpect/ANSI.py:29
  <…>/pexpect/pexpect/ANSI.py:29: UserWarning: pexpect.screen and pexpect.ANSI are deprecated. We recommend using pyte to emulate a terminal screen: https://pypi.python.org/pypi/pyte
    from . import screen
<… several DeprecationWarnings …>
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED tests/test_replwrap.py::REPLWrapTestCase::test_bash - AssertionError:
============ 1 failed, 241 passed, 11 warnings in 210.43s (0:03:30) ============

Restore the sh-then-csh order of attempting to set a unique prompt, add
zsh to the end of the list instead of in the middle.

(Fixes pexpect#712 (comment))
@Red-M
Copy link
Member

Red-M commented Nov 10, 2022

I'll take a full run down of this change on the weekend as I want to get the automated test suite working again for GitHub issues.

@Red-M Red-M closed this Feb 14, 2023
@Red-M Red-M reopened this Feb 14, 2023
@Red-M
Copy link
Member

Red-M commented Feb 14, 2023

I had to close and re-open to get the tests to run. Sorry!

@Red-M
Copy link
Member

Red-M commented Feb 14, 2023

Please fix the issues presented in the tests.
Coverage changes under 1% are fine, do not worry about it.

@kbriggs
Copy link
Contributor Author

kbriggs commented Mar 7, 2023

Please fix the issues presented in the tests.

For some reason the merge commit eae7087 merging master into the PR removed the execute bit from the mode of tests/fakessh/ssh, despite both parent commits still having the execute bit set:

% git diff --summary e7cf54a zsh-login-prompt
 create mode 100644 .github/workflows/ci.yml
 mode change 100755 => 100644 tests/fakessh/ssh
% git diff --summary afb85a7 zsh-login-prompt
 mode change 100755 => 100644 tests/fakessh/ssh

This prevents the test from executing the mock ssh command, so all tests that use it fail.

Merge commit eae7087 somehow removed the execute bit from the mode of
tests/fakessh/ssh, breaking all tests using that mock ssh client.
@kbriggs
Copy link
Contributor Author

kbriggs commented Mar 7, 2023

All pxssh tests are now passing. Remaining test failures in 3.11 and pypy3.9 match existing failures in master.

@Red-M Red-M closed this Mar 13, 2023
@Red-M Red-M reopened this Mar 13, 2023
@Red-M Red-M closed this Apr 2, 2023
@Red-M Red-M reopened this Apr 2, 2023
@Red-M Red-M merged commit eb9c306 into pexpect:master Sep 29, 2023
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pxssh login to zsh: could not set shell prompt
2 participants