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

update computer test output #3544

Merged
merged 2 commits into from
Nov 28, 2019
Merged

Conversation

ltalirz
Copy link
Member

@ltalirz ltalirz commented Nov 14, 2019

This PR updates the output of verdi computer test

Old output:
Screenshot 2019-11-14 at 14 05 01

New output:
Screenshot 2019-11-14 at 14 13 02

@ltalirz ltalirz changed the title Computer test echo update computer test output Nov 14, 2019

self.assertEquals(get_job('861352').title, 'Pressure_PBEsol_0')

self.assertEquals(get_job('863554').requested_wallclock_time_seconds, None) # not set
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I noticed is that this time will also be None, if the value could not be parsed.
Perhaps ok, but it means that finding a value None does no longer mean that parsing failed.

@ltalirz ltalirz requested a review from sphuber November 27, 2019 19:24
@sphuber
Copy link
Contributor

sphuber commented Nov 27, 2019

I feel the change you are making to the scheduler parsing is too important to be muffled away in a commit on changing the output format of a computer test function. Would you be willing to separate that in another PR?

@ltalirz
Copy link
Member Author

ltalirz commented Nov 27, 2019

Would you be willing to separate that in another PR?

Done #3586

Copy link
Contributor

@sphuber sphuber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor visual suggestions, but ok to leave it as is if you disagree

@@ -141,11 +142,11 @@ def _computer_create_temp_file(transport, scheduler, authinfo): # pylint: disab

file_content = "Test from 'verdi computer test' on {}".format(datetime.datetime.now().isoformat())
echo.echo('> Creating a temporary file in the work directory...')
echo.echo(' `-> Getting the remote user name...')
echo.echo(' -> Getting the remote user name...')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is nice to put the [OK] on the same line as the first line.
This would go for all other lines as well where there is no other intermediate result but just an ok.
Put the message with ellipses and OK on the same line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this looks nicer and I wanted to do this at first. It's nasty though - what do you do if the test fails?

During test failures, some commands print random stuff, which will then inevitably land on the same line.
For the "echo" statements originating from the command itself one could handle it, but also there you would need to do quite a bit of if/else in order to avoid having stuff printed on the same line that shouldn't be.

I've made the changes here https://github.com/ltalirz/aiida-core/tree/computer-test-echo-nl-false
Let me know what you prefer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it fails, we can still print the error after a [FAILED] right? Or even on the next line if it is multiple lines. But I would imagine something like this:

* Getting job list... [OK]: Found 6 jobs in the queue
* Checking that no spurious output is present... [FAILED]
* Getting the remote user name... [OK]: <ltalirz>
* Retrieving the file and checking its content... [FAILED]: file not found

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, that is if you control everything that happens between printing "..." and the failure.
currently, many of the methods being called here just randomly print stuff (and not just the ones defined inside this file).
I'd have to start capturing all of this - can be done but is quite some work

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can just put the calling blocks in with Capturing() no? If you are ok with it, I will gladly update your other branch to do it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, please go ahead!
you have write acces to my fork already


handle, destfile = tempfile.mkstemp()
os.close(handle)
try:
transport.getfile(remote_file_path, destfile)
with io.open(destfile, encoding='utf8') as dfile:
read_string = dfile.read()
echo.echo(' [Retrieved]')
echo.echo(' [Retrieved]')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe remove this one and just put [OK] instead of [Content OK] on same line.

transport.remove(remote_file_path)
echo.echo(' [Deleted successfully]')
echo.echo(' [Deleted successfully]')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, just [OK] would suffice?

else:
echo.echo('Test completed (all {} tests succeeded)'.format(num_tests))
echo.echo_success('All {} tests succeeded)'.format(num_tests))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the string contains unbalanced closing parens

@sphuber
Copy link
Contributor

sphuber commented Nov 28, 2019

@ltalirz I have updated the branch. I intended to push this to your second "test" branch but accidentally did it to the PR branch. Anyway, I didn't touch your commit, just rebased it so it is up-to-date. The additional commit will make it look as follows:

Success

verdi_computer_test_success

Failed

verdi_computer_test_failed

With traceback

verdi_computer_test_traceback

try:
echo.echo('> Testing connection...')
echo.echo('* Opening connection... ', nl=False)

with transport:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if an error happens here (e.g. configure a wrong username).
It will start printing stuff...

Copy link
Contributor

@sphuber sphuber Nov 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, it will be caught in the outer try-except and that also just prints the error or including the traceback if the option is specified. Example:
verdi_computer_test_connection_failed

num_tests += 1
for test in [_computer_test_no_unexpected_output, _computer_test_get_jobs, _computer_create_temp_file]:

click.secho('[OK]', fg=echo.COLORS['success'], bold=echo.BOLD)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in my 2nd PR I introduced an echo.echo_highlight command that saves one from specifying the bold parameter + one can pass directly 'success'.
Can save some text...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added this to your first commit and then used it in mine.

Copy link
Member Author

@ltalirz ltalirz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me it's anyhow an improvement and good to merge.

@sphuber Since it's my PR, you will need to approve yourself ;-)

ltalirz and others added 2 commits November 28, 2019 14:29
 * fix indentation
 * add color to results of all 3 tests
 * add "success" to final message
 * add `aiida.cmdline.utils.echo.echo_highlight` function
The number of tests is increased and messaging from within each test is
disabled. The tests now return a tuple of a boolean indicating success
or failure and an optional message. This message can be informational in
case of success or an error message. With echo'ing only being performed
in the main function, the output can be given a consistent look. Each
test will have `[OK]` or `[FAILED]` on the same line with an optional
message. Additional lines, such as for the full traceback, are
prepended with newline and two spaces of indentation.
@sphuber
Copy link
Contributor

sphuber commented Nov 28, 2019

For me it's anyhow an improvement and good to merge.

@sphuber Since it's my PR, you will need to approve yourself ;-)

I included echo_highlight to your commit and then used it in mine. If you can confirm once more that you are happy with this I will merge it. Thanks

Copy link
Member Author

@ltalirz ltalirz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sphuber , looks good to me!

@sphuber sphuber self-requested a review November 28, 2019 14:18
Copy link
Contributor

@sphuber sphuber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ltalirz

@sphuber sphuber merged commit e6430f7 into aiidateam:develop Nov 28, 2019
@sphuber sphuber deleted the computer-test-echo branch November 28, 2019 14:19
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.

2 participants