Class: TestFlockhartWriter

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
test/test_plugin/flockhart.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'test/test_plugin/flockhart.rb', line 34

def setup
  @writer = ODDB::Interaction::FlockhartWriter.new 
  @writer2 = ODDB::Interaction::FlockhartWriter.new 
  formatter = ODDB::Interaction::Formatter.new(@writer)
  parser = ODDB::Interaction::Parser.new(formatter)
  target = ODDB::Interaction::FlockhartPlugin::TARGET
  table = "prepared_table.asp"
  @html = File.read([target, table].join("/"))
  parser.feed(@html)
  @writer.cytochromes.store("8/cyto", ODDB::Interaction::Cytochrome.new('cyto'))
  @writer.cytochromes.store("9/3A5", ODDB::Interaction::Cytochrome.new('cyto'))
  @writer.cytochromes.store("9/3A7", ODDB::Interaction::Cytochrome.new('cyto'))
end

- (Object) test_check_string



47
48
49
50
51
52
# File 'test/test_plugin/flockhart.rb', line 47

def test_check_string
  result = @writer2.check_string("test")
  assert_equal(true, result)
  result = @writer2.check_string("test\302\240test")
  assert_equal(false, result)
end

- (Object) test_check_string2



53
54
55
56
57
58
# File 'test/test_plugin/flockhart.rb', line 53

def test_check_string2
  result = @writer2.check_string("=foo")
  assert_equal(false, result)
  result = @writer2.check_string(">bar")
  assert_equal(false, result)
end

- (Object) test_check_string3



59
60
61
62
63
64
65
66
# File 'test/test_plugin/flockhart.rb', line 59

def test_check_string3
  result = @writer2.check_string("foobar => 5OH")
  assert_equal(true, result)
  result = @writer2.check_string("6OH")
  assert_equal(false, result)
  result = @writer2.check_string("3-OH")
  assert_equal(false, result)
end

- (Object) test_clear_string



67
68
69
70
# File 'test/test_plugin/flockhart.rb', line 67

def test_clear_string
  result = @writer2.clear_string("=foo\2402OH4-OH\240bar")
  assert_equal("foobar", result)
end

- (Object) test_create_update_objects



71
72
73
74
75
76
77
# File 'test/test_plugin/flockhart.rb', line 71

def test_create_update_objects
  @writer.type = 'inhibitors'
  @writer.create_update_objects('base_name', {:category => 'categ'}, 8, nil)
  cyt = @writer.cytochromes["8/cyto"]
  assert_equal(1, cyt.inhibitors.size)
  assert_equal('categ', cyt.inhibitors.first.category)
end

- (Object) test_create_update_objects2



78
79
80
81
82
83
84
# File 'test/test_plugin/flockhart.rb', line 78

def test_create_update_objects2
  @writer.type = 'inducers'
  @writer.create_update_objects('base_name', {}, 8, nil)
  cyt = @writer.cytochromes["8/cyto"]
  assert_equal(1, cyt.inducers.size)
  assert_equal(nil, cyt.inducers.first.category)
end

- (Object) test_create_update_objects3



85
86
87
88
89
90
91
92
# File 'test/test_plugin/flockhart.rb', line 85

def test_create_update_objects3
  @writer.type = 'inducers'
  @writer.create_update_objects('base_name', {}, 9, '3A5')
  cyt = @writer.cytochromes["9/3A5"]
  cyt2 = @writer.cytochromes["9/3A7"]
  assert_equal(0, cyt.inducers.size)
  assert_equal(1, cyt2.inducers.size)
end

- (Object) test_extract_data



93
94
95
96
# File 'test/test_plugin/flockhart.rb', line 93

def test_extract_data
  @writer.extract_data
  assert_equal(12, @writer.cytochromes.size)
end

- (Object) test_extract_data2



97
98
99
100
101
102
103
104
105
# File 'test/test_plugin/flockhart.rb', line 97

def test_extract_data2
  @writer.extract_data
  result = @writer.cytochromes["2/2C8"].substrates
  assert_equal(6, result.size)
  result = @writer.cytochromes["2/2C8"].inducers
  assert_equal(1, result.size)
  expected = ODDB::Interaction::InducerConnection
  assert_equal(expected, result.first.class)
end

- (Object) test_extract_data3



106
107
108
109
110
111
112
113
114
# File 'test/test_plugin/flockhart.rb', line 106

def test_extract_data3
  @writer.extract_data
  substrates = @writer.cytochromes["5/2D6"].substrates
  result = []
  substrates.each { |sub|
    result << sub if sub.category == 'antipsychotics'  
  }
  assert_equal(37, result.size)
end

- (Object) test_extract_data4



115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'test/test_plugin/flockhart.rb', line 115

def test_extract_data4
  @writer.extract_data
  substrates = @writer.cytochromes["0/1A2"].substrates
  substrates.each { |sub|
    @result = sub if sub.name==nil
  }
  assert_equal(24, substrates.size)
  substrates.each { |sub|
    @result = sub if sub.name.match(/phenacetin/)
  }
  expected = "phenacetin"
  assert_equal(expected, @result.name)
end

- (Object) test_new_fonthandler



128
129
130
131
132
133
134
# File 'test/test_plugin/flockhart.rb', line 128

def test_new_fonthandler
  @writer2.category = "start"
  @writer2.new_font(nil)
  assert_equal(nil, @writer2.category)
  @writer2.new_font([0,0,1,0])
  assert_equal("start", @writer2.category)
end

- (Object) test_parse_array



135
136
137
138
139
140
141
142
143
144
# File 'test/test_plugin/flockhart.rb', line 135

def test_parse_array
  arr = ["one*/*/*two*/*/*3", "foo*/*/*bar*/*/*1.25", "asterix*/*/*obelix*/*/*1.75"]
  result = @writer2.parse_array(arr)
  expected = {
    "one"      => {:category => "two", :auc_factor => "3"},
    "foo"      => {:category => "bar", :auc_factor => "1.25"},
    "asterix"  => {:category => "obelix", :auc_factor => "1.75"},
  } 
  assert_equal(expected, result)
end

- (Object) test_parse_cyt_string



145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'test/test_plugin/flockhart.rb', line 145

def test_parse_cyt_string
  @writer2.parse_cyt_string("inhibitors@/@/@foo", 5)
  result = @writer2.cytochromes
  assert_equal(1, result.size)
  assert_equal('inhibitors', @writer2.type)
  @writer2.parse_cyt_string("inducers@/@/@bar", 6)
  result = @writer2.cytochromes
  assert_equal(2, result.size)
  assert_equal('inducers', @writer2.type)
  @writer2.parse_cyt_string("inhibitors@/@/@foo", 5)
  result = @writer2.cytochromes
  assert_equal(2, result.size)
end

- (Object) test_parse_cyt_string2



158
159
160
161
162
163
# File 'test/test_plugin/flockhart.rb', line 158

def test_parse_cyt_string2
  @writer2.parse_cyt_string("inhibitors@/@/@3A4,5,7", 5)
  result = @writer2.cytochromes
  assert_equal(2, result.size)
  assert_equal('inhibitors', @writer2.type)
end

- (Object) test_parse_cyt_string3



164
165
166
167
168
169
170
# File 'test/test_plugin/flockhart.rb', line 164

def test_parse_cyt_string3
  @writer2.parse_cyt_string("inhibitors@/@/@3A457", 5)
  result = @writer2.cytochromes
  assert_equal(2, result.size)
  assert_equal('inhibitors', @writer2.type)
  assert_equal("3A5-7", @writer2.cytochromes["5/3A5-7"].cyt_name)
end

- (Object) test_parse_string



171
172
173
174
175
176
177
178
179
# File 'test/test_plugin/flockhart.rb', line 171

def test_parse_string
  string = "foo*/*/**/*/*&/&/&bar*/*/**/*/*"
  result = @writer2.parse_string(string)
  expected = {
    "foo"  => {:category => nil, :auc_factor => nil},
    "bar"  => {:category => nil, :auc_factor => nil},
  }
  assert_equal(expected, result)
end

- (Object) test_parse_string2



180
181
182
183
184
185
186
187
188
189
190
# File 'test/test_plugin/flockhart.rb', line 180

def test_parse_string2
  string = "foo*/*/*nil&/&/&bar-/-/-3A4*/*/*nil"
  result1 = @writer2.parse_string(string)
  result2 = @writer2.duplicates
  expected1 = {
    "bar-/-/-3A4"  => {:auc_factor=>nil, :category=>"nil"},
  }
  expected2 = ["foo*/*/*nil"]
  assert_equal(expected1, result1)
  assert_equal(expected2, result2)
end

- (Object) test_send_image



191
192
193
194
# File 'test/test_plugin/flockhart.rb', line 191

def test_send_image
  @writer2.send_image('red.jpg')
  assert_equal("5", @writer2.auc_factor)
end

- (Object) test_write_substance_string



195
196
197
198
199
# File 'test/test_plugin/flockhart.rb', line 195

def test_write_substance_string
  result = @writer2.write_substance_string("instanz")
  expected = "instanz*/*/**/*/*&/&/&"
  assert_equal(expected, result)
end

- (Object) test_write_substance_strng2



200
201
202
203
204
205
206
# File 'test/test_plugin/flockhart.rb', line 200

def test_write_substance_strng2
  @writer2.current_category = "kat"
  @writer2.auc_factor = "5"
  result = @writer2.write_substance_string("instanz")
  expected = "instanz*/*/*kat*/*/*5&/&/&"
  assert_equal(expected, result)
end