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
Adding iteration to ProgressBar to make it a more useful utility #10813
Conversation
"""Returns current value and increments display by one.""" | ||
self.progress += 1 | ||
if self.progress < self.total: | ||
return self.progress |
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.
Increment afterwards, that way you don't need to initialize to - 1.
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.
This is just a function, not a generator, so anything after the return will not run. You have to either have a -1 initial value (which is never printed), or you have to add a new variable to tell the difference between before-iteration 0 and iteration 0. You also really want the final iteration to be 4/5, to match the range, and to provide a visual indication that it's finished by changing to 5/5.
IPython/core/tests/test_display.py
Outdated
nt.assert_in('{0}/5'.format(i), out) | ||
out, err = capsys.readouterr() | ||
nt.assert_in('5/5', out) | ||
|
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.
Oops, I guess this is nose running nose tests, not pytest running nose tests.
The nose project hasn't receive a commit in about a year, I think pytest would be a good idea :) I'll fix this.
Is there a way to test in a normal terminal environment? It seems that the tests run in a environment where display is not supported. |
I don't think it's the environment that's involved there: it looks like |
I've used the |
@mariusvniekerk @Carreau are you happy with this? |
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.
Looks good
+1, I'm guessing backport to have identical functionality on Python2. |
Yes, it should be in both. |
Backport PR #10813 on branch 5.x
As discussed in #10812, this simply adds the ability to iterate over a ProgessBar (no other API changes). Added a test and a mention in the relevant example.