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

Adding iteration to ProgressBar to make it a more useful utility #10813

Merged
merged 2 commits into from Oct 5, 2017

Conversation

henryiii
Copy link
Contributor

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.

"""Returns current value and increments display by one."""
self.progress += 1
if self.progress < self.total:
return self.progress
Copy link
Contributor

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.

Copy link
Contributor Author

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.

nt.assert_in('{0}/5'.format(i), out)
out, err = capsys.readouterr()
nt.assert_in('5/5', out)

Copy link
Contributor Author

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.

@henryiii
Copy link
Contributor Author

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.

@takluyver
Copy link
Member

I don't think it's the environment that's involved there: it looks like CapturingDisplayPublisher (which is used by capture_output) hasn't been updated with the transient= keyword argument that the regular DisplayPublisher has. I guess you'll need to update that, or use capture_output(display=False) and let it capture the output on stdout.

@henryiii
Copy link
Contributor Author

henryiii commented Sep 27, 2017

I've used the display=False method to make sure this works for IPython 5 or 6, and separately patched the display issue for IPython 5 and 6.

@takluyver
Copy link
Member

@mariusvniekerk @Carreau are you happy with this?

Copy link
Contributor

@mariusvniekerk mariusvniekerk left a comment

Choose a reason for hiding this comment

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

Looks good

@Carreau Carreau added this to the 5.6 milestone Oct 5, 2017
@Carreau
Copy link
Member

Carreau commented Oct 5, 2017

+1, I'm guessing backport to have identical functionality on Python2.

@henryiii
Copy link
Contributor Author

henryiii commented Oct 5, 2017

Yes, it should be in both.

@Carreau Carreau merged commit 36ab971 into ipython:master Oct 5, 2017
lumberbot-app bot pushed a commit that referenced this pull request Oct 5, 2017
takluyver added a commit that referenced this pull request Oct 11, 2017
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.

None yet

4 participants