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

BUG: allow repeated mol2 writes #2680

Merged
merged 1 commit into from
May 15, 2020

Conversation

tylerjereddy
Copy link
Member

Fixes #2678

Changes made in this Pull Request:

PR Checklist

  • Tests?
  • Docs?
  • CHANGELOG updated?
  • Issue raised/referenced?

@codecov
Copy link

codecov bot commented May 9, 2020

Codecov Report

Merging #2680 into develop will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #2680   +/-   ##
========================================
  Coverage    91.11%   91.11%           
========================================
  Files          175      175           
  Lines        23637    23642    +5     
  Branches      3090     3090           
========================================
+ Hits         21536    21541    +5     
  Misses        1482     1482           
  Partials       619      619           
Impacted Files Coverage Δ
package/MDAnalysis/coordinates/MOL2.py 94.35% <100.00%> (+0.23%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 111224c...97408d7. Read the comment docs.

Copy link
Member

@lilyminium lilyminium left a comment

Choose a reason for hiding this comment

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

The tmpdir fixture seems to make the tempdir module of MDAnalysisTests, but otherwise this looks good, thanks!


def test_mol2_multi_write():
# see: gh-2678
with tempdir.TempDir() as tmpdir:
Copy link
Member

Choose a reason for hiding this comment

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

Maybe use the tmpdir fixture from pytest here?

Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't seem to leave any files behind and there are other uses in our code base--what's the justification for using one over the other?

I had assumed our own solution was there for a reason.

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.e., if testsuite/MDAnalysisTests/tempdir.py shouldn't be used, may it should be removed or deprecated or whatever

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 see it is just copied from other examples in the same module, so if a broader cleanup is in order that's probably a separate task, though I'm happy to change this specific case...

Copy link
Member

Choose a reason for hiding this comment

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

I had assumed our own solution was there for a reason.

Yeah, I'm not sure why it's preferred over the fixture. It looks like a pretty straightforward context manager, although there's a comment that created files might not be deleted on Windows if they're still open. I guess one advantage it has is that you can add a prefix or suffix to the directory name, although I don't think that is ever used in the test suite. There's also a decorator that is used twice. Either way I think pytest's fixture can probably replace all instances of the tempdir module.

I also like with tmpdir.as_cwd() because it's clearer what is happening. You don't need to outfile = os.path.join(str(tmpdir), 'group1.mol2') because you've changed directories, but that's not immediately obvious.

* add a unit test reproduce MDAnalysisgh-2678

* the `encode_block` method of `MOL2Writer` now
restores mutated properties of `molecule` to prevent
the issue
@tylerjereddy tylerjereddy force-pushed the issue_2678_mol2_repeat branch from dd81b27 to 97408d7 Compare May 14, 2020 15:30
@tylerjereddy
Copy link
Member Author

OK, revised to use pytest tmpdir fixture.

I'll open a separate issue for removing the in-house tempdir stuff.

@lilyminium
Copy link
Member

Thank you @tylerjereddy!

@lilyminium lilyminium merged commit 89db3b1 into MDAnalysis:develop May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can only write mol2 file once
2 participants