File: style.py

package info (click to toggle)
genometools 1.6.6%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 50,576 kB
  • sloc: ansic: 271,876; ruby: 29,930; python: 5,106; sh: 3,083; makefile: 1,213; perl: 219; pascal: 159; haskell: 37; sed: 5
file content (202 lines) | stat: -rw-r--r-- 5,314 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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/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 gt.core import *
from gt.extended import *
from gt.annotationsketch import *
import sys


class TestFailedException(Exception):

    pass


if __name__ == "__main__":
    if len(sys.argv) != 2:
        sys.stderr.write("Usage: " + (sys.argv)[0] + " style_file")
        sys.stderr.write("Load style_file and test style bindings.")
        sys.exit(1)

    stylefile = (sys.argv)[1]

  # create new style object

    style = Style()

  # load style file

    style.load_file(stylefile)

  # clone style file

    clone = style.clone()
    if not clone:
        raise TestFailedException

  # get color

    color = style.get_color("exon", "fill")
    if not color:
        raise TestFailedException

  # set color

    color = Color(0.3, 0.4, 0.3)
    style.set_color("exon", "fill", color)
    color2 = style.get_color("exon", "fill")
    if color2.red != color.red and color2.green != color.green and \
        color2.blue != color.blue:
        raise TestFailedException

  # unset color

    style.unset("exon", "fill")
    color2 = style.get_color("exon", "fill")
    if color2:
        raise TestFailedException

  # get undefined color

    color = style.get_color("undefined", "undefined")
    if color:
        raise TestFailedException

  # get string

    string = style.get_cstr("exon", "style")
    if string != "box":
        raise TestFailedException

  # set string

    style.set_cstr("exon", "style", "line")
    string = style.get_cstr("exon", "style")
    if string != "line":
        raise TestFailedException(string)

  # unset string

    style.unset("exon", "style")
    string = style.get_cstr("exon", "style")
    if string:
        raise TestFailedException

  # get undefined string

    string = style.get_cstr("undefined", "undefined")
    if string:
        raise TestFailedException

  # get number

    num = style.get_num("format", "margins")
    if num != 30:
        raise TestFailedException

  # set number

    style.set_num("format", "margins", 20)
    num = style.get_num("format", "margins")
    if num != 20:
        raise TestFailedException

  # unset number

    style.unset("format", "margins")
    None
    num = style.get_num("format", "margins")
    if num:
        raise TestFailedException

  #get undefined number

    num = style.get_num("undefined", "undefined")
    if num:
        raise TestFailedException

  # get boolean

    bool = style.get_bool("format", "show_grid")
    if bool == False:
        raise TestFailedException

  # get undefined boolean

    bool = style.get_bool("undefined", "undefined")
    if not bool == None:
        raise TestFailedException

  # set boolean

    style.set_bool("format", "show_grid", False)
    bool = style.get_bool("format", "show_grid")
    if bool:
        raise TestFailedException

  # unset boolean

    style.unset("format", "show_grid")
    bool = style.get_bool("format", "show_grid")
    if not bool == None:
        raise TestFailedException

  # serialise style to Lua code

    style.set_num("format", "margins", 20)
    style.set_bool("format", "show_grid", True)
    color = Color(0.3, 0.4, 0.3)
    style.set_color("exon", "fill", color)
    luacode = style.to_str()
    if luacode == None or len(luacode) == 0:
        raise TestFailedException

  # load style from Lua code

    style.load_str(luacode)
    num = style.get_num("format", "margins")
    if num != 20:
        raise TestFailedException
    bool = style.get_bool("format", "show_grid")
    if not bool:
        raise TestFailedException
    color2 = style.get_color("exon", "fill")
    if color2.red != color.red and color2.green != color.green and \
        color2.blue != color.blue:
        raise TestFailedException

  # clone style from existing copy

    style2 = style.clone()
    num = style2.get_num("format", "margins")
    if num != 20:
        raise TestFailedException
    bool = style2.get_bool("format", "show_grid")
    if not bool:
        raise TestFailedException
    color2 = style2.get_color("exon", "fill")
    if color2.red != color.red and color2.green != color.green and \
        color2.blue != color.blue:
        raise TestFailedException
    style2.set_num("format", "margins", 30)
    if style2.get_num("format", "margins") != 30:
        raise TestFailedException
    if style.get_num("format", "margins") == style2.get_num("format",
            "margins"):
        raise TestFailedException