Repository navigation
Adding SimpleFastaParser and FastaTwoLineParser unit tests - #1810
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1810 +/- ##
==========================================
+ Coverage 85.33% 85.34% +<.01%
==========================================
Files 301 301
Lines 49197 49195 -2
==========================================
+ Hits 41984 41987 +3
+ Misses 7213 7208 -5
Continue to review full report at Codecov.
|
|
Changed and simplified |
|
What happened to the exceptions for a two-line-per-record FASTA file ending after the |
|
I should have started with: The additional explicit tests are very welcome, thank you. |
|
Thanks Peter, if I understand you correctly, then I think this case still raises an exception. When the file ends on a title/header line starting with For example: This is tested in the new tests I added for Would it be clearer and more explicit to replace the final index check with this? Or did I make a mistake in my logic? |
|
That looks clearer I think (although remove the first assert, just do the raise). |
|
I must have missed this in the original PR, but I focused on the multi-line FASTA parser. Looking at this test case: ins_two_line_edges = [">\nACGT", ">1\n\n",
">1>1\n\n>1\n\n", ""]
outs_two_line_edges = [[("", "ACGT")], [("1", "")],
[("1>1", ""), ("1", "")], []]
...
def test_regular_FastaTwoLineParser(self):
"""Test regular FastaTwoLineParser cases."""
for inp, out in zip(self.ins_two_line, self.outs_two_line):
handle1 = StringIO(inp)
handle2 = StringIO(inp + '\n')
self.assertEqual(list(FastaTwoLineParser(handle1)), out)
self.assertEqual(list(FastaTwoLineParser(handle2)), out)The result of parsing Looking at this now:
Given I've accidentally set a tolerant precedent (which you have sensibly followed), perhaps we should leave it as is, or at most add warnings for these? |
|
Thanks, sorry if my tests added some confusion; you quoted the For this case where the last line is a valid sequence line but lacks a new-line |
|
Also, just to be sure, this is only for the |
|
Yes, the multi-line |
Ah yes, you're quite right. My mistake: ins_two_line = [">1\nACGT", ">1\nACGT",
">1\nACGT\n>2\nACGT"]Yes, what I've picked up on is a pre-existing ambiguity about missing the final new line. |
|
I'll let AppVeyor finish its tests, but this looks OK to merge. The new release will be more rigorous than the current 2-line FASTA parser 👍 |
|
One last thing, should we add a note to these unit test lines like this? |
|
Maybe just open a new issue for a new warning when parsing plain text files without a final new line character? e.g. FASTA, FASTQ, EMBL, GenBank, Swiss, .... The rational here is files in all those file formats can in principle be concatenated to make a larger multi-record file, but that breaks if a child file's final |
|
Merged, thank you! |
Apologies Peter for giving you so many reviewing tasks, but I just wanted to tie up the lose end from PR #1808 while it is fresh in my mind, the extra unit tests.
SimpleFastaParserandFastaTwoLineParserwere previously not tested directly anywhere in the Biopython test suite, this addresses that and includes some non-intuitive edge-cases. Hopefully, it is fairly straightforward.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.rstfile and understand that AppVeyor andTravisCI will be used to confirm the Biopython unit tests and
flake8stylechecks pass with these changes.
I have added my name to the alphabetical contributors listings in the files
NEWS.rstandCONTRIB.rstas part of this pull request, am listedalready, or do not wish to be listed. (This acknowledgement is optional.)