Beispiel #1
0
    def test_context_manager(self):
        filename = "tests/data/simple.fasta"
        with open(filename, 'rb') as f:
            assert not f.closed
            _ = list(dnaio.open(f))
            assert not f.closed
        assert f.closed

        with FastaReader(filename) as sr:
            tmp_sr = sr
            assert not sr._file.closed
            _ = list(sr)
            assert not sr._file.closed
        assert tmp_sr._file is None
        # Open it a second time
        with FastaReader(filename):
            pass
Beispiel #2
0
 def test_with_comments(self):
     fasta = BytesIO(
         dedent("""
         # a comment
         # another one
         >first_sequence
         SEQUENCE1
         >second_sequence
         SEQUENCE2
         """).encode())
     reads = list(FastaReader(fasta))
     assert reads == simple_fasta
Beispiel #3
0
 def test_wrong_format(self):
     fasta = BytesIO(
         dedent("""# a comment
         # another one
         unexpected
         >first_sequence
         SEQUENCE1
         >second_sequence
         SEQUENCE2
         """).encode())
     with raises(FastaFormatError) as info:
         list(FastaReader(fasta))
     assert info.value.line == 2
Beispiel #4
0
 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'
Beispiel #5
0
 def test_bytesio(self):
     fasta = BytesIO(
         b">first_sequence\nSEQUENCE1\n>second_sequence\nSEQUENCE2\n")
     reads = list(FastaReader(fasta))
     assert reads == simple_fasta
Beispiel #6
0
 def test_file(self):
     with FastaReader("tests/data/simple.fasta") as f:
         reads = list(f)
     assert reads == simple_fasta