-
Notifications
You must be signed in to change notification settings - Fork 694
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
Pytest Style: test_log.py #1467
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only 1 change, otherwise good
|
||
|
||
def _assert_in(output, string): | ||
assert_(string in output, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use plain pytest assert
:
assert string in output, "Output '{0}' does not match required format '{1}'.".format(output.replace('\r', '\\r'), string.replace('\r', '\\r')))
@kain88-de Review please. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All occurrences of assert_raises
should be replaced by the pytest equivalent. The deactivated assert_warn
at the end of the file should be reactivated and moved to the pytest idiom.
The tests about the progress bar can probably be refactored as a single parametrized function.
from MDAnalysis.lib.log import _set_verbose | ||
from numpy.testing import assert_, assert_equal, assert_raises |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert_
and assert_raises
should not be used.
|
||
|
||
def test_default_ProgressMeter(buffer, n=101, interval=10): | ||
format = "Step {step:5d}/{numsteps} [{percentage:5.1f}%]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing to do with pytest, but to avoid confusion could you rename this variable template
? Same goes for all subsequent occurrences.
buffer.seek(0) | ||
output = "".join(buffer.readlines()) | ||
_assert_in(output, (format + '\n').format(**{'step': 1, 'numsteps': n, 'percentage': 100./n})) | ||
_assert_in(output, (format + '\n').format(**{'step': n, 'numsteps': n, 'percentage': 100.})) | ||
|
||
|
||
def test__set_verbose(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the below test screams for a mark.parametrize
Someone want's to verify why actually |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not know why the warning tests fail. I check and the function does issue the warning... I'll try to have a deeper look tonight.
_assert_in(output, (template + '\n').format(**{'step': step, 'numsteps': n, 'percentage': percentage})) | ||
|
||
|
||
class TestSetVerbose(object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because there are two methods that basically are testing the same log think. I thought it makes sense to group them. No?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense indeed.
assert string in output, "Output '{0}' does not match required format '{1}'.".format(output.replace('\r', '\\r'), string.replace('\r', '\\r')) | ||
|
||
|
||
def test_default_ProgressMeter(buffer, n=101, interval=10): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test_*_ProgressMeter
functions are basicaly all doing the same thing. They should be parametrized.
|
||
@pytest.fixture() | ||
def buffer(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good that you renamed buf
to buffer
. It was a terrible name, my bad.
This seems to be the answer: https://docs.pytest.org/en/latest/warnings.html#ensuring-function-triggers |
@jbarnoud @kain88-de @richardjgowers
remaining two have (
so there is a change in In the end I think I can only merge |
I still think there is a way to avoid the redundancy, but it may induce some complexity we do not want in the tests. Do not loose time on this. |
So what do we do? Merge only the two cases? Or merge the PR as is? |
If you fix the warning tests, I'll merged as it. |
@jbarnoud Added these lines to the test
Now |
Why not using |
@jbarnoud This is done I think. |
Fixes #
Changes made in this Pull Request:
PR Checklist