Skip to content

SffIO selftest work - #948

Merged
peterjc merged 6 commits into
biopython:masterfrom
vincentdavis:move_SffIO_selftest
Oct 6, 2016
Merged

peterjc merged 6 commits into
biopython:masterfrom
vincentdavis:move_SffIO_selftest

Conversation

@vincentdavis

Copy link
Copy Markdown
Contributor

Not ready to merge. Moved selftest and code for making test files to test_SffIO. Added doctest to main

@codecov-io

codecov-io commented Sep 29, 2016 •

Copy link
Copy Markdown

Current coverage is 80.25% (diff: 0.00%)

Merging #948 into master will increase coverage by 0.11%

@@             master       #948   diff @@
==========================================
  Files           316        316          
  Lines         48502      48435    -67   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          38872      38873     +1   
+ Misses         9630       9562    -68   
  Partials          0          0          

Powered by Codecov. Last update 857c891...8d49ce9

@vincentdavis

Copy link
Copy Markdown
Contributor Author

Converted selftest code to test_self test class/case. Need comments/feedback, I did a quck conversion.
New test_SffIO coverage is 75% up from 57%
cov_test_SffIO_after_selftest_move.pdf

Comment thread Tests/test_SffIO.py Outdated
assert s.letter_annotations["phred_quality"] == q.letter_annotations["phred_quality"]
assert s.id == sT.id == fT.id == qT.id
assert str(sT.seq) == str(fT.seq)
assert sT.letter_annotations["phred_quality"] == qT.letter_annotations["phred_quality"]

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.

You should use self.assertEqual(..., ....) here, although I'm not sure if there is a multiple version for three or four entries.

Comment thread Tests/test_SffIO.py Outdated

def test_read_wrong(self):
filename = "Roche/greek.sff"
try:

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.

Probably you can just use self.assertRaises(ValueError, ReadRocheXmlManifest, handle) here.

Comment thread Tests/test_SffIO.py Outdated
with open(filename, "rb") as handle:
for record in SffIterator(handle):
pass
try:

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.

Probably you can use self.assertRaises(ValueError, next, SffIterator(handle)) here?

Comment thread Tests/test_SffIO.py Outdated
k = list(_sff_do_slow_index(
open("Roche/E3MFGYR02_alt_index_at_end.sff", "rb")))
print("Done")
"""

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.

Can un-indent the final triple quote, but perhaps it would be clearer to put the whole lump of code as:

if False:
    # Ugly code to make test files...
    ...

What do you think? We don't count the test files when calculating coverage so that's not a downside.

Comment thread Bio/SeqIO/SffIO.py
if __name__ == "__main__":
from Bio._utils import run_doctest
run_doctest(verbose=0) No newline at end of file

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.

Extra blank line?

(But putting in the trailing newline at the end of the file is good)

Comment thread Tests/test_SffIO.py Outdated
# print(err)

class TestSelf(unittest.TestCase):
"""

@peterjc peterjc Sep 30, 2016 •

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.

Use a single line as per PEP257,

"""These tests were originally selftests run in SffIO.py"""

See https://www.python.org/dev/peps/pep-0257/#one-line-docstrings

Also there was a spelling error.

If you think if a more meaningful class name, that'd be even better.

@vincentdavis

Copy link
Copy Markdown
Contributor Author

@peterjc Ready for another review.

Comment thread Tests/test_SffIO.py Outdated
"""
These tests were originally seltests run in SffIO.py
"""
""" These tests were originally seltests run in SffIO.py """

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.

The typo is still there, seltests [sic] rather than selftests, but if that's the only remaining issue I'll fix it as part of the merge...

Comment thread Tests/test_SffIO.py Outdated
with open(filename, "rb") as a_handle, open(filename, "rb") as b_handle:
sff = list(SffIterator(a_handle))
sff_trim = list(SffIterator(b_handle, trim=True))

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.

At this point (because we used list), both the iterators should have parsed the entire file, and we can close the handle. That was the goal with the original structure:

        with open(filename, "rb") as handle:
            sff = list(SffIterator(handle))
        with open(filename, "rb") as handle:
            sff_trim = list(SffIterator(handle, trim=True))

Also there is no reason to have the rest of the code indented as part of this with clause.

Comment thread Tests/test_SffIO.py Outdated
w = SffWriter(handle, xml=metadata)
w.write_file(iter(sff))
assert data == handle.getvalue()
with open(filename, "rb") as a_handle, open(filename, "rb") as b_handle:

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, same comment as before - the with clauses should be as small as possible - as per the original.

Comment thread Tests/test_SffIO.py
pass
# print("Checking what happens on re-reading a handle:")
# print(err)
self.assertRaises(ValueError, fileiter, handle)

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.

Do we really need to define fileiter here? Does next(...) or even list(...) work by trying to start iteration through the file?

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.

 with open(filename, "rb") as handle:
    for record in SffIterator(handle):
        pass
    r = SffIterator(handle)
    self.assertRaises(ValueError, next(r), handle)

I the tests fails but I don't understand why, It appears to raise a ValueError.

ERROR: test_read_wrong (test_SffIO.TestSelf)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/vincentdavis/VersionControl/biopython/Tests/test_SffIO.py", line 445, in test_read_wrong
    self.assertRaises(ValueError, next(r), handle)
  File "/Users/vincentdavis/VersionControl/biopython/Bio/SeqIO/SffIO.py", line 904, in SffIterator
    raise ValueError("Not at start of file, offset %i" % handle.tell())
ValueError: Not at start of file, offset 65296

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.

How strange. I'd have to play with that to try to work out why. I presume the original try/except structure would work within the unit test framework, so maybe just use that for now?

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.

OK, last pull leaves this as I have it. @peterjc Thanks for your time reviewing.

Comment thread Tests/test_SffIO.py Outdated
open("Roche/E3MFGYR02_random_10_reads.sff", "rb")))
with open("Roche/E3MFGYR02_alt_index_at_end.sff", "w") as out_handle:
if False:
"""

@peterjc peterjc Oct 3, 2016 •

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.

By putting this within a large if False: block, I meant you could remove the triple-quotes for a multi-line comment. Apologies if I was unclear.

@peterjc

peterjc commented Oct 3, 2016

Copy link
Copy Markdown
Member

Now that the code used to write the test indexes is "live", and not a big comment, it shows up some PEP8 issues. If you want to fix that too, great - otherwise I'll do it (it was my non-standard code in the first place - wink)

@vincentdavis

Copy link
Copy Markdown
Contributor Author

@peterjc I'll let you fix that as you wish or I wonder if it is worth testing the code to help prevent bit rot.

@peterjc

peterjc commented Oct 3, 2016

Copy link
Copy Markdown
Member

The fact it was a big comment meant it escaped the recent PEP8 clean up. Also just looking at the code, it probably needs some work for Python 3 (as it is all about manipulating a binary file). As to testing the code, well maybe: I wanted to record how I created the non-trivial binary test SFF files.

@peterjc
peterjc merged commit 6b2b125 into biopython:master Oct 6, 2016
@peterjc

peterjc commented Oct 6, 2016

Copy link
Copy Markdown
Member

Thank you Vincent :)

@vincentdavis
vincentdavis deleted the move_SffIO_selftest branch October 10, 2016 13:39
MarkusPiotrowski pushed a commit to MarkusPiotrowski/biopython that referenced this pull request Oct 31, 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.

3 participants