Repository navigation
SffIO selftest work - #948
Conversation
…files to test_SffIO, all commented out. Add dock_test __main__ to file.
Current coverage is 80.25% (diff: 0.00%)@@ 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
|
|
Converted selftest code to test_self test class/case. Need comments/feedback, I did a quck conversion. |
| 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"] |
There was a problem hiding this comment.
You should use self.assertEqual(..., ....) here, although I'm not sure if there is a multiple version for three or four entries.
|
|
||
| def test_read_wrong(self): | ||
| filename = "Roche/greek.sff" | ||
| try: |
There was a problem hiding this comment.
Probably you can just use self.assertRaises(ValueError, ReadRocheXmlManifest, handle) here.
| with open(filename, "rb") as handle: | ||
| for record in SffIterator(handle): | ||
| pass | ||
| try: |
There was a problem hiding this comment.
Probably you can use self.assertRaises(ValueError, next, SffIterator(handle)) here?
| k = list(_sff_do_slow_index( | ||
| open("Roche/E3MFGYR02_alt_index_at_end.sff", "rb"))) | ||
| print("Done") | ||
| """ |
There was a problem hiding this comment.
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.
| if __name__ == "__main__": | ||
| from Bio._utils import run_doctest | ||
| run_doctest(verbose=0) No newline at end of file | ||
|
|
There was a problem hiding this comment.
Extra blank line?
(But putting in the trailing newline at the end of the file is good)
| # print(err) | ||
|
|
||
| class TestSelf(unittest.TestCase): | ||
| """ |
There was a problem hiding this comment.
Use a single line as per PEP257,
"""These tests were originally selftests run in SffIO.py"""
Also there was a spelling error.
If you think if a more meaningful class name, that'd be even better.
|
@peterjc Ready for another review. |
| """ | ||
| These tests were originally seltests run in SffIO.py | ||
| """ | ||
| """ These tests were originally seltests run in SffIO.py """ |
There was a problem hiding this comment.
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...
| 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)) | ||
|
|
There was a problem hiding this comment.
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.
| 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: |
There was a problem hiding this comment.
Again, same comment as before - the with clauses should be as small as possible - as per the original.
| pass | ||
| # print("Checking what happens on re-reading a handle:") | ||
| # print(err) | ||
| self.assertRaises(ValueError, fileiter, handle) |
There was a problem hiding this comment.
Do we really need to define fileiter here? Does next(...) or even list(...) work by trying to start iteration through the file?
There was a problem hiding this comment.
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 65296There was a problem hiding this comment.
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?
There was a problem hiding this comment.
OK, last pull leaves this as I have it. @peterjc Thanks for your time reviewing.
| open("Roche/E3MFGYR02_random_10_reads.sff", "rb"))) | ||
| with open("Roche/E3MFGYR02_alt_index_at_end.sff", "w") as out_handle: | ||
| if False: | ||
| """ |
There was a problem hiding this comment.
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.
|
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) |
|
@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. |
|
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. |
|
Thank you Vincent :) |
Squashed commit from pull request biopython#948. Part of work to address biopython#820.
Not ready to merge. Moved selftest and code for making test files to test_SffIO. Added doctest to main