Repository navigation
Fix iterator handling in ProgressBar (issue 5540) #5546
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
base: develop
Are you sure you want to change the base?
Changes from all commits
312f3e8
fd0a40f
13e5744
ef31cd4
a6d483d
bc13650
d8bf29c
6d13ab8
6233378
58f4063
236e203
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -51,3 +51,25 @@ def test_verbose_disable(self, capsys): | |||||||||
| expected = "" | ||||||||||
| actual = err.strip().split("\r")[-1] | ||||||||||
| assert actual == expected | ||||||||||
|
|
||||||||||
| def test_trajectory_remains_open_when_disabled(self, monkeypatch): | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is fine but it is a bit synthetic. In MAICoS we also tested an Analysis workflow that breaks. https://github.com/atomistic-lab/maicos/pull/614/changes
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, something like your |
||||||||||
| """Ensure early iterator closure leaves the trajectory accessible.""" | ||||||||||
| import MDAnalysis as mda | ||||||||||
| from MDAnalysis.tests.datafiles import PSF, DCD | ||||||||||
|
Comment on lines
+57
to
+58
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imports at top
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is pretty common for LLMs to scope imports in (test) functions when that isn't necessary. Do we really need to scope these imports locally like this?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just made a similar comment — we collect imports at the top unless there's a very good reason to do something else. |
||||||||||
|
|
||||||||||
| def iter_with_yield_from(self): | ||||||||||
| yield from self.iterable | ||||||||||
|
|
||||||||||
| tqdm_class = ProgressBar.__mro__[1] | ||||||||||
| monkeypatch.setattr(tqdm_class, "__iter__", iter_with_yield_from) | ||||||||||
|
Comment on lines
+63
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this work?
Suggested change
|
||||||||||
|
|
||||||||||
| u = mda.Universe(PSF, DCD) | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make the universe a fixture so that you can re-use it for a |
||||||||||
|
|
||||||||||
| progress = ProgressBar(u.trajectory, verbose=False) | ||||||||||
| iterator = iter(progress) | ||||||||||
|
|
||||||||||
| next(iterator) | ||||||||||
| iterator.close() | ||||||||||
|
|
||||||||||
| assert u.trajectory[0].frame == 0 | ||||||||||
| u.trajectory.close() | ||||||||||
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.
add a comment referencing issue and PR and state briefly that we're working around a change in tqdm (and mention the version of the change). When looking at this code, readers should understand why it's necessary.