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

verdi computer test: fix bug in spurious output test #4316

Merged
merged 1 commit into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 11 additions & 26 deletions aiida/cmdline/commands/cmd_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,35 +76,20 @@ def _computer_test_no_unexpected_output(transport, scheduler, authinfo): # pyli
if retval != 0:
return False, 'The command `echo -n` returned a non-zero return code ({})'.format(retval)

if stdout:
return False, u"""
There is some spurious output in the standard output,
that we report below between the === signs:
=========================================================
template = """
We detected some spurious output in the {} when connecting to the computer, as shown between the bars
=====================================================================================================
{}
=========================================================
Please check that you don't have code producing output in
your ~/.bash_profile (or ~/.bashrc). If you don't want to
remove the code, but just to disable it for non-interactive
shells, see comments in issue #1980 on GitHub:
https://github.com/aiidateam/aiida-core/issues/1890
(and in the AiiDA documentation, linked from that issue)
""".format(stdout)
=====================================================================================================
Please check that you don't have code producing output in your ~/.bash_profile, ~/.bashrc or similar.
If you don't want to remove the code, but just to disable it for non-interactive shells, see comments
in this troubleshooting section of the online documentation: https://bit.ly/2FCRDc5
"""
if stdout:
return False, template.format('stdout', stdout)

if stderr:
return u"""
There is some spurious output in the stderr,
that we report below between the === signs:
=========================================================
{}
=========================================================
Please check that you don't have code producing output in
your ~/.bash_profile (or ~/.bashrc). If you don't want to
remove the code, but just to disable it for non-interactive
shells, see comments in issue #1980 on GitHub:
https://github.com/aiidateam/aiida-core/issues/1890
(and in the AiiDA documentation, linked from that issue)
"""
return False, template.format('stderr', stderr)

return True, None

Expand Down
36 changes: 36 additions & 0 deletions tests/cmdline/commands/test_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,39 @@ def test_interactive(clear_database_before_test, aiida_localhost, non_interactiv
# For now I'm not writing anything in them
assert new_computer.get_prepend_text() == ''
assert new_computer.get_append_text() == ''


@pytest.mark.usefixtures('clear_database_before_test')
def test_computer_test_stderr(run_cli_command, aiida_localhost, monkeypatch):
"""Test `verdi computer test` where tested command returns non-empty stderr."""
from aiida.transports.plugins.local import LocalTransport

aiida_localhost.configure()
stderr = 'spurious output in standard error'

def exec_command_wait(self, command, **kwargs):
return 0, '', stderr

monkeypatch.setattr(LocalTransport, 'exec_command_wait', exec_command_wait)

result = run_cli_command(computer_test, [aiida_localhost.label])
assert 'Warning: 1 out of 5 tests failed' in result.output
assert stderr in result.output


@pytest.mark.usefixtures('clear_database_before_test')
def test_computer_test_stdout(run_cli_command, aiida_localhost, monkeypatch):
"""Test `verdi computer test` where tested command returns non-empty stdout."""
from aiida.transports.plugins.local import LocalTransport

aiida_localhost.configure()
stdout = 'spurious output in standard output'

def exec_command_wait(self, command, **kwargs):
return 0, stdout, ''

monkeypatch.setattr(LocalTransport, 'exec_command_wait', exec_command_wait)

result = run_cli_command(computer_test, [aiida_localhost.label])
assert 'Warning: 1 out of 5 tests failed' in result.output
assert stdout in result.output