File: test_io.py

package info (click to toggle)
python-airr 1.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 684 kB
  • sloc: python: 2,407; sh: 19; makefile: 10
file content (72 lines) | stat: -rw-r--r-- 2,016 bytes parent folder | download | duplicates (2)
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
62
63
64
65
66
67
68
69
70
71
72
"""
Unit tests for interface
"""
# System imports
import os
import time
import unittest

# Load imports
from airr.io import *

# Paths
test_path = os.path.dirname(os.path.realpath(__file__))
data_path = os.path.join(test_path, 'data')


class TestRearrangementReader(unittest.TestCase):
    def setUp(self):
        print('-------> %s()' % self.id())

        # Test data
        self.data_good = os.path.join(data_path, 'good_rearrangement.tsv')
        self.data_bad = os.path.join(data_path, 'bad_rearrangement.tsv')
        self.data_extra = os.path.join(data_path, 'extra_rearrangement.tsv')

        # Start timer
        self.start = time.time()

    def tearDown(self):
        t = time.time() - self.start
        print('<- %.3f %s()' % (t, self.id()))

    # @unittest.skip('-> validate(): skipped\n')
    def test_validate(self):
        # Good data
        try:
            with open(self.data_good, 'r') as handle:
                reader = RearrangementReader(handle, validate=True)
                for r in reader:
                    pass
        except:
            self.assertTrue(False, 'validate(): good data failed')

        # Bad data
        try:
            with open(self.data_bad, 'r') as handle:
                reader = RearrangementReader(handle, validate=True)
                for r in reader:
                    pass
            self.assertFalse(True, 'validate(): bad data failed')
        except ValidationError:
            pass
        except Exception as inst:
            print(type(inst))
            raise inst

        # Extra data
        try:
            with open(self.data_extra, 'r') as handle:
                reader = RearrangementReader(handle, validate=False)
                for r in reader:
                    pass
            self.assertFalse(True, 'validate(): extra data failed')
        except ValueError:
            pass
        except Exception as inst:
            print(type(inst))
            raise inst


if __name__ == '__main__':
    unittest.main()