File: test_SCOP_Dom.py

package info (click to toggle)
python-biopython 1.78%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 65,756 kB
  • sloc: python: 221,141; xml: 178,777; ansic: 13,369; sql: 1,208; makefile: 131; sh: 70
file content (54 lines) | stat: -rw-r--r-- 1,763 bytes parent folder | download | duplicates (3)
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
# Copyright 2001 by Gavin E. Crooks.  All rights reserved.
# This code is part of the Biopython distribution and governed by its
# license.  Please see the LICENSE file that should have been included
# as part of this package.

"""Unit test for Dom.

This test requires the mini DOM file 'testDom.txt'
"""

import unittest

from Bio.SCOP import Dom


class DomTests(unittest.TestCase):
    def setUp(self):
        self.filename = "./SCOP/testDom.txt"

    def testParse(self):
        """Test if all records in a DOM file are being read."""
        count = 0
        with open(self.filename) as f:
            for record in Dom.parse(f):
                count += 1
        self.assertEqual(count, 10)

    def testStr(self):
        """Test if we can convert each record to a string correctly."""
        with open(self.filename) as f:
            for line in f:
                record = Dom.Record(line)
                # End of line is platform dependent. Strip it off
                self.assertEqual(str(record).rstrip(), line.rstrip())

    def testError(self):
        """Test if a corrupt record raises the appropriate exception."""
        corruptDom = "49xxx268\tsp\tb.1.2.1\t-\n"
        self.assertRaises(ValueError, Dom.Record, corruptDom)

    def testRecord(self):
        """Test one record in detail."""
        recLine = "d7hbib_\t7hbi\tb:\t1.001.001.001.001.001"

        rec = Dom.Record(recLine)
        self.assertEqual(rec.sid, "d7hbib_")
        self.assertEqual(rec.residues.pdbid, "7hbi")
        self.assertEqual(rec.residues.fragments, (("b", "", ""),))
        self.assertEqual(rec.hierarchy, "1.001.001.001.001.001")


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