File: test_SeqIO_NibIO.py

package info (click to toggle)
python-biopython 1.85%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 126,372 kB
  • sloc: xml: 1,047,995; python: 332,722; ansic: 16,944; sql: 1,208; makefile: 140; sh: 81
file content (61 lines) | stat: -rw-r--r-- 2,068 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Tests for SeqIO NibIO module."""

import unittest
from io import BytesIO

from Bio import SeqIO


class TestNibReaderWriter(unittest.TestCase):
    def test_read_even(self):
        with open("Nib/test_even.fa") as handle:
            record = SeqIO.read(handle, "fasta")
        sequence = record.seq
        with open("Nib/test_even_bigendian.nib", "rb") as handle:
            record = SeqIO.read(handle, "nib")
        self.assertEqual(sequence, record.seq)
        with open("Nib/test_even_littleendian.nib", "rb") as handle:
            record = SeqIO.read(handle, "nib")
        self.assertEqual(sequence, record.seq)

    def test_read_odd(self):
        with open("Nib/test_odd.fa") as handle:
            record = SeqIO.read(handle, "fasta")
        sequence = record.seq
        with open("Nib/test_odd_bigendian.nib", "rb") as handle:
            record = SeqIO.read(handle, "nib")
        self.assertEqual(sequence, record.seq)
        with open("Nib/test_odd_littleendian.nib", "rb") as handle:
            record = SeqIO.read(handle, "nib")
        self.assertEqual(sequence, record.seq)

    def test_write_even(self):
        with open("Nib/test_even.fa") as handle:
            record = SeqIO.read(handle, "fasta")
        sequence = record.seq
        handle = BytesIO()
        n = SeqIO.write(record, handle, "nib")
        self.assertEqual(n, 1)
        handle.flush()
        handle.seek(0)
        record = SeqIO.read(handle, "nib")
        handle.close()
        self.assertEqual(sequence, record.seq)

    def test_write_odd(self):
        with open("Nib/test_odd.fa") as handle:
            record = SeqIO.read(handle, "fasta")
        sequence = record.seq
        handle = BytesIO()
        n = SeqIO.write(record, handle, "nib")
        self.assertEqual(n, 1)
        handle.flush()
        handle.seek(0)
        record = SeqIO.read(handle, "nib")
        handle.close()
        self.assertEqual(sequence, record.seq)


if __name__ == "__main__":
    runner = unittest.TextTestRunner(verbosity=2)
    unittest.main(testRunner=runner)