File: sketch-failures.py

package info (click to toggle)
genometools 1.6.1%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 50,412 kB
  • sloc: ansic: 271,241; ruby: 30,339; python: 4,880; sh: 3,193; makefile: 1,194; perl: 219; pascal: 159; haskell: 37; sed: 5
file content (102 lines) | stat: -rw-r--r-- 3,369 bytes parent folder | download | duplicates (8)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2008 Sascha Steinbiss <steinbiss@zbh.uni-hamburg.de>
# Copyright (c) 2008 Center for Bioinformatics, University of Hamburg
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

from ctypes import ArgumentError
from gt.core import *
from gt.extended import *
from gt.annotationsketch import *
import sys
import re


class TestFailedError(Exception):

    pass


if __name__ == "__main__":
    if len(sys.argv) != 2:
        sys.stderr.write("Usage: " + (sys.argv)[0] + " GFF3_file\n")
        sys.stderr.write("Test failures in GFF3 annotation file.")
        sys.exit(1)

    feature_index = FeatureIndexMemory()
    feature_index.add_gff3file((sys.argv)[1])

    seqid = feature_index.get_first_seqid()
    range = feature_index.get_range_for_seqid(seqid)

    style = Style()
    style.set_num("format", "margins", 40)

  # check error reporting in the Diagram class

    try:
        diagram = Diagram.from_index(feature_index, "nonexist", range,
                style)
    except GTError as strerr:
        if -1 == str(strerr).find("feature index does not contain "):
            raise TestFailedError
    else:
        raise TestFailedError
    try:
        diagram = Diagram.from_index(feature_index, seqid, range, 42)
    except TypeError as strerr:
        if -1 == str(strerr).find("must be a Style"):
            raise TestFailedError
    else:
        raise TestFailedError
    try:
        diagram = Diagram.from_index(feature_index, seqid, 42, style)
    except AttributeError as strerr:
        if -1 == str(strerr).find("object has no attribute 'start'"):
            raise TestFailedError
    else:
        raise TestFailedError
    try:
        diagram = Diagram.from_index(42, seqid, range, style)
    except TypeError as strerr:
        if -1 == str(strerr).find("must be a FeatureIndex"):
            raise TestFailedError
    else:
        raise TestFailedError
    diagram = Diagram.from_index(feature_index, seqid, range, style)

  # check error reporting in the Layout class

    try:
        layout = Layout(diagram, 70, style)
    except GTError as strerr:
        if -1 == str(strerr).find("layout width must at least be twice"):
            raise TestFailedError
    else:
        raise TestFailedError
    layout = Layout(diagram, 700, style)
    height = layout.get_height()

  # check error reporting in the CanvasCairoFile class

    try:
        canvas = CanvasCairoFile(12, 700, height, None)
    except TypeError as strerr:
        if -1 == str(strerr).find("must be a Style"):
            raise TestFailedError
    else:
        raise TestFailedError
    canvas = CanvasCairoFile(style, 700, height, None)