File: nib_tests.py

package info (click to toggle)
python-bx 0.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,000 kB
  • sloc: python: 17,136; ansic: 2,326; makefile: 24; sh: 8
file content (48 lines) | stat: -rw-r--r-- 1,457 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
"""
Tests for `bx.seq.nib`.
"""

import unittest

from bx.seq import nib

test_nib = "test_data/seq_tests/test.nib"

# Same sequence data as stored in test.nib

valid_seq = (
    "TGGAGGCATTTGTGATTCAATAGATGCAGAAAGAAACCTTCCTAGAGCTG"
    "GCGTTCTCTAACTAAAAGTGGAAAGTTCTGAGGAATGAGGACTGTTATAA"
    "ATCCCACCCCACACCGCACCTTCTCCAGGGAAGTTTCATGGCCGTGAAGA"
    "GGACAGAAAGTGAGAACCAAGATggaactgaataaacaagcttcacactg"
    "ttagtttccccatatgcttaccttcccacagatgccaaccttggaggcct"
    "aagaggcctagaatattatcctttgtctgatcatttctctacaaatttat"
    "tgttctttgttaagatgctacataagcccaaattctaaccacccctttga"
    "gttacccatcatcaagtttctcccatgtg"
)

valid_seq_len = len(valid_seq)


class NIBTestCase(unittest.TestCase):
    def test_get(self):
        nibfile = nib.NibFile(open(test_nib, "rb"))
        # Try all combinations of even / odd boundaries
        check_get(nibfile, 0, 10)
        check_get(nibfile, 1, 10)
        check_get(nibfile, 0, 11)
        check_get(nibfile, 1, 11)
        # Test near end of file also
        check_get(nibfile, valid_seq_len - 10, 10)
        check_get(nibfile, valid_seq_len - 11, 11)
        # Test really short gets
        check_get(nibfile, 0, 0)
        check_get(nibfile, 1, 0)
        check_get(nibfile, 0, 1)
        check_get(nibfile, 1, 1)
        # Test negative length
        self.assertRaises(AssertionError, nibfile.get, 20, -1)


def check_get(nibfile, start, len):
    assert nibfile.get(start, len) == valid_seq[start : start + len]