Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test(self):
with FastaReader("tests/data/simple.fasta") as f:
reads = list(f)
assert reads == simple_fasta
fasta = StringIO(">first_sequence\nSEQUENCE1\n>second_sequence\nSEQUENCE2\n")
reads = list(FastaReader(fasta))
assert reads == simple_fasta
def test(self):
with FastaReader("tests/data/simple.fasta") as f:
reads = list(f)
assert reads == simple_fasta
fasta = StringIO(">first_sequence\nSEQUENCE1\n>second_sequence\nSEQUENCE2\n")
reads = list(FastaReader(fasta))
assert reads == simple_fasta
def test_fastareader_keeplinebreaks(self):
with FastaReader("tests/data/simple.fasta", keep_linebreaks=True) as f:
reads = list(f)
assert reads[0] == simple_fasta[0]
assert reads[1].sequence == 'SEQUEN\nCE2'
def test_context_manager(self):
filename = "tests/data/simple.fasta"
with open(filename) as f:
assert not f.closed
reads = list(openseq(f))
assert not f.closed
assert f.closed
with FastaReader(filename) as sr:
tmp_sr = sr
assert not sr._file.closed
reads = list(sr)
assert not sr._file.closed
assert tmp_sr._file is None
# Open it a second time
with FastaReader(filename) as sr:
pass
def test_with_comments(self):
fasta = StringIO(dedent(
"""
# a comment
# another one
>first_sequence
SEQUENCE1
>second_sequence
SEQUENCE2
"""))
reads = list(FastaReader(fasta))
assert reads == simple_fasta
def test_wrong_format(self):
fasta = StringIO(dedent(
"""
# a comment
# another one
unexpected
>first_sequence
SEQUENCE1
>second_sequence
SEQUENCE2
"""))
reads = list(FastaReader(fasta))
def test_context_manager(self):
filename = "tests/data/simple.fasta"
with open(filename) as f:
assert not f.closed
reads = list(openseq(f))
assert not f.closed
assert f.closed
with FastaReader(filename) as sr:
tmp_sr = sr
assert not sr._file.closed
reads = list(sr)
assert not sr._file.closed
assert tmp_sr._file is None
# Open it a second time
with FastaReader(filename) as sr:
pass