Skip to content

Remove redundant self test from Bio.GenBank.Scanner - #1936

Merged
peterjc merged 3 commits into
biopython:masterfrom
svalqui:issue_820_GenBank_Scanner
Feb 27, 2019
Merged

peterjc merged 3 commits into
biopython:masterfrom
svalqui:issue_820_GenBank_Scanner

Conversation

@svalqui

@svalqui svalqui commented Feb 19, 2019

Copy link
Copy Markdown
Contributor

This pull request addresses issue #820

  • I hereby agree to dual licence this and any previous contributions under both
    the Biopython License Agreement AND the BSD 3-Clause License.

  • I have read the CONTRIBUTING.rst file and understand that AppVeyor and
    TravisCI will be used to confirm the Biopython unit tests and flake8 style
    checks pass with these changes.

  • I have added my name to the alphabetical contributors listings in the files
    NEWS.rst and CONTRIB.rst as part of this pull request, am listed
    already, or do not wish to be listed. (This acknowledgement is optional.)

@svalqui
svalqui requested a review from peterjc as a code owner February 19, 2019 22:20
@peterjc

peterjc commented Feb 19, 2019

Copy link
Copy Markdown
Member

Thank you for working on this - the initial pull request is a good start, but I'd like to see some large changes (in terms of lines of code - conceptually the change is small).

Currently we do use EmblScanner and GenBankScanner in Tests/test_GenBank_unittest.py, but only in a slightly artificial way to test parsing first line. We don't directly test the parse_records method nor parse_cds_features method which is done in the self test. That's the bit I think we need to move from the self test into the unittest framework, and your pull request does that :)

However, I don't think we necessarily have to use the same GenBank and EMBL examples to do this - probably many of the existing examples under Tests/GenBank/ which could be used instead?

If there is something interesting about these test files which makes them worth retaining, then I don't see any reason to keep them as text embedded in the Python code, when as part of the main test framework they could more usefully be files under Tests/GenBank/. That way they can be used in other tests more easily.

So, please either remove the embedded files completely (and test using existing GenBank or EMBL test files), or move the embedded files to files on disk.

@svalqui

svalqui commented Feb 19, 2019

Copy link
Copy Markdown
Contributor Author

Ok, no worries I'll review the files available and update.

@codecov

codecov Bot commented Feb 19, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #1936 into master will increase coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1936      +/-   ##
==========================================
+ Coverage   85.02%   85.03%   +<.01%     
==========================================
  Files         310      310              
  Lines       49957    49960       +3     
==========================================
+ Hits        42476    42481       +5     
+ Misses       7481     7479       -2
Impacted Files Coverage Δ
Bio/GenBank/Scanner.py 82.72% <ø> (+0.23%) ⬆️
Bio/motifs/meme.py 80.97% <0%> (ø) ⬆️
Bio/PDB/parse_pdb_header.py 96.27% <0%> (+0.06%) ⬆️

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 d3e7b6f...a90d683. Read the comment docs.

Comment thread Tests/test_GenBank_unittest.py Outdated
if do_features:
l_gb_r = list(self.gb_s.parse_records(handle, do_features=True))
else:
l_gb_r = list(self.gb_s.parse_records(handle, do_features=False))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wouldn't one line instead of four be enough:

l_gb_r = list(self.gb_s.parse_records(handle, do_features= do_features))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, amended.

Comment thread Tests/test_GenBank_unittest.py Outdated
def gb_to_l_r(self, filename, do_features=False):
"""Gb file to Seq list parse records."""

handle = open(filename, 'r')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you use a context manager here please,

with open(filename) as handle:
    # code

not:

handle = open(filename)
# code
handle.close()

Also there is no need to specify the mode since "r" is the default.

Comment thread Tests/test_GenBank_unittest.py Outdated
"""Test EMBL CDS interaction, parse CDS features on embl files."""

# Test parse CDS features on embl_file
handle_embl7046 = open("EMBL/AE017046.embl", "r")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Again, context manager please:

        with open("EMBL/AE017046.embl") as handle:
            embl_s = Scanner.EmblScanner()
            l_cds_f = list(embl_s.parse_cds_features(handle))

Comment thread Tests/test_GenBank_unittest.py Outdated
"""Test EMBL Record interaction on embl files."""

# Test parse records on embl_file
handle_embl7046 = open("EMBL/AE017046.embl", "r")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Again, please use a context manager.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Using context manager for all now; all good, I think is ready now.

@peterjc

peterjc commented Feb 26, 2019

Copy link
Copy Markdown
Member

Are you happy to do a little more polishing? Using context managers is recommend style over explicitly closing file handles.

@peterjc
peterjc merged commit b13faf4 into biopython:master Feb 27, 2019
@peterjc

peterjc commented Feb 27, 2019

Copy link
Copy Markdown
Member

Merged, thank you!

@svalqui
svalqui deleted the issue_820_GenBank_Scanner branch April 1, 2019 02:12
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.

2 participants