Class: TestHayesWriter

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



72
73
74
75
76
77
78
79
80
# File 'test/test_plugin/hayes.rb', line 72

def setup
  @writer = ODDB::Interaction::HayesWriter.new
  formatter = ODDB::HtmlFormatter.new(@writer)
  parser = ODDB::HtmlParser.new(formatter)
  target = ODDB::Interaction::HayesPlugin::TARGET
  table = "CYP450-1.html"
  @html = File.read([target, table].join("/"))
  parser.feed(@html)
end

- (Object) test_check_cytochrome



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

def test_check_cytochrome
  result = @writer.check_cytochrome("3A4")
  assert_equal(["3A4"], result) 
  result = @writer.check_cytochrome("2C19")
  assert_equal(["2C19"], result)  
  result = @writer.check_cytochrome("3A5-8")
  #expected = [ "3A5", "3A6", "3A7", "3A8" ]
  expected = ["3A5-8"]
  assert_equal(expected, result)  
end

- (Object) test_check_string



107
108
109
110
111
112
# File 'test/test_plugin/hayes.rb', line 107

def test_check_string
  result = @writer.check_string("foobar")
  assert_equal(true, result)
  result = @writer.check_string([])
  assert_equal(false, result)
end

- (Object) test_create_connection



113
114
115
116
117
118
# File 'test/test_plugin/hayes.rb', line 113

def test_create_connection
  obj = @writer.create_connection("suBstanCe", "inhibits")
  expected = ODDB::Interaction::InhibitorConnection 
  assert_equal(expected, obj.class)
  assert_equal("suBstanCe", obj.name)
end

- (Object) test_handle_cytochrome



119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'test/test_plugin/hayes.rb', line 119

def test_handle_cytochrome
  obj = ODDB::Interaction::InhibitorConnection.new("suBstanCe", 'en')
  obj_two = ODDB::Interaction::InhibitorConnection.new("SubStanCeTwo", "en")
  @writer.handle_cytochrome(["3A5", "3A6"], obj)
  assert_equal(2, @writer.cytochromes.size)
  result = @writer.cytochromes["3A5"].inhibitors.first
  assert_equal(obj, result)
  @writer.handle_cytochrome(["3A5"], obj_two)
  assert_equal(2, @writer.cytochromes.size)
  result = @writer.cytochromes["3A5"].inhibitors.size
  assert_equal(2, result)
  result = @writer.cytochromes["3A5"].inhibitors
  assert_equal([obj, obj_two], result)
end

- (Object) test_handle_functions



133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'test/test_plugin/hayes.rb', line 133

def test_handle_functions
  begin
    @writer.instance_eval "alias :original_handle_substance :handle_substance\nalias :original_handle_row :handle_row\ndef handle_row(row, function)\n@hr_row = row\n@hr_function = function\n\"3A5\"\nend\ndef handle_substance(substance, cyts)\n@hs_substance = substance\n@hs_cyts = cyts\nend\n"
    @writer.current_substance = "SUBstanCe"
    @writer.function = "substrate"
    @writer.handle_functions("foo", nil)
    assert_equal("foo", @writer.hr_row)
    assert_equal("substrate", @writer.hr_function)
    assert_equal("SUBstanCe", @writer.hs_substance)
    assert_equal(["3A5"], @writer.hs_cyts)
  ensure
    @writer.instance_eval "alias :handle_substance :original_handle_substance\nalias :handle_row :original_handle_row\n"
  end
end

- (Object) test_handle_functions2



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'test/test_plugin/hayes.rb', line 164

def test_handle_functions2
  begin
    @writer.instance_eval "alias :original_handle_substance :handle_substance\nalias :original_handle_row :handle_row\ndef handle_row(row, function)\nif(@hr_row)\n@hr_row << row\nelse\n@hr_row = row\nend\nif(@hr_function)\n@hr_function << function\nelse\n@hr_function = function\nend\n\"3A5\"\nend\ndef handle_substance(substance, cyts)\n@hs_substance = substance\n@hs_cyts = cyts\nend\n"
    @writer.current_substance = "subSTANCE"
    @writer.function_one = "inhibits"
    @writer.function_two = "induces"
    @writer.handle_functions("foo", "bar")
    assert_equal("foobar", @writer.hr_row)
    assert_equal("inhibitsinduces", @writer.hr_function)
    assert_equal("subSTANCE", @writer.hs_substance)
    assert_equal(["3A5", "3A5"], @writer.hs_cyts)
  ensure
    @writer.instance_eval "alias :handle_substance :original_handle_substance\nalias :handle_row :original_handle_row\n"
  end
end

- (Object) test_handle_functions3



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'test/test_plugin/hayes.rb', line 204

def test_handle_functions3
  begin
    @writer.instance_eval "alias :original_handle_substance :handle_substance\nalias :original_handle_row :handle_row\ndef handle_row(row, function)\nif(@hr_row)\n@hr_row << row\nelse\n@hr_row = row\nend\nif(@hr_function)\n@hr_function << function\nelse\n@hr_function = function\nend\n\"3A5\"\nend\ndef handle_substance(substance, cyts)\n@hs_substance = substance\n@hs_cyts = cyts\nend\n"
    @writer.current_substance = "subSTANCE"
    @writer.function_one = "inhibits"
    @writer.function_two = "induces"
    @writer.handle_functions("foo", nil)
    assert_equal("foo", @writer.hr_row)
    assert_equal("inhibits", @writer.hr_function)
    assert_equal("subSTANCE", @writer.hs_substance)
    assert_equal(["3A5"], @writer.hs_cyts)
  ensure
    @writer.instance_eval "alias :handle_substance :original_handle_substance\nalias :handle_row :original_handle_row\n"
  end
end

- (Object) test_handle_row



244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'test/test_plugin/hayes.rb', line 244

def test_handle_row
  result = @writer.handle_row("ROU", "funk-zion")
  expected = {
    "ROU"  => "funk-zion",
  }
  assert_equal(expected, result)
  result = @writer.handle_row(["ROU", "rou"], "funk-zion")
  expected = {
    "ROU"  => "funk-zion",
    "rou"  => "funk-zion",
  }
  assert_equal(expected, result)
end

- (Object) test_new_fonthandler



257
258
259
260
261
262
263
264
265
266
267
# File 'test/test_plugin/hayes.rb', line 257

def test_new_fonthandler
  handler = ODDB::HtmlFontHandler.new(Hash["color","#000080"])
  @writer.new_fonthandler(handler)
  assert_equal("start", @writer.category)
  handler = ODDB::HtmlFontHandler.new(Hash["color","Red"])
  @writer.new_fonthandler(handler)
  assert_equal(nil, @writer.category)
  handler = ODDB::HtmlFontHandler.new(Hash["color","Blue"])
  @writer.new_fonthandler(handler)
  assert_equal("start", @writer.category)
end

- (Object) test_parse_substance



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'test/test_plugin/hayes.rb', line 272

def test_parse_substance
  writer = ODDB::Interaction::HayesWriter.new
  formatter = ODDB::HtmlFormatter.new(writer)
  parser = ODDB::HtmlParser.new(formatter)
  target = ODDB::Interaction::HayesPlugin::TARGET
  table = "custom_table-1.html"
  html = File.read([target, table].join("/"))
  parser.feed(html)
  writer.parse_substances
  assert_equal(4, writer.cytochromes.size)
  result = writer.cytochromes["1A1"].substrates.first
  expected = ODDB::Interaction::SubstrateConnection
  assert_equal(expected, result.class)
  assert_equal("SubStanzOne", result.name)
  result = writer.cytochromes["1A2"].substrates
  assert_equal(2, result.size)
  subs = []
  result.each do |sub|; subs.push sub.name; end
  expected = ["SubStanzOne", "SubStanzTwo"]
  assert_equal(expected, subs)
end

- (Object) test_parse_substance2



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'test/test_plugin/hayes.rb', line 293

def test_parse_substance2
  writer = ODDB::Interaction::HayesWriter.new
  formatter = ODDB::HtmlFormatter.new(writer)
  parser = ODDB::HtmlParser.new(formatter)
  target = ODDB::Interaction::HayesPlugin::TARGET
  table = "custom_table-2.html"
  html = File.read([target, table].join("/"))
  parser.feed(html)
  writer.parse_substances
  assert_equal(5, writer.cytochromes.size)
  result = writer.cytochromes["1A6"].inducers.first
  expected = ODDB::Interaction::InducerConnection
  assert_equal(expected, result.class)
  assert_equal("SubStanzTwo", result.name)
  result = writer.cytochromes["1A2"].inhibitors
  assert_equal(2, result.size)
  subs = []
  result.each do |sub|; subs.push sub.name; end
  expected = ["SubStanzOne", "SubStanzThree"]
  assert_equal(expected, subs)
end

- (Object) test_second_hayes_file



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'test/test_plugin/hayes.rb', line 81

def test_second_hayes_file
  writer = ODDB::Interaction::HayesWriter.new
  formatter = ODDB::HtmlFormatter.new(writer)
  parser = ODDB::HtmlParser.new(formatter)
  target = ODDB::Interaction::HayesPlugin::TARGET
  table = "CYP450-2.html"
  html = File.read([target, table].join("/"))
  parser.feed(html)
  cytochromes = writer.extract_data
  #assert_equal(13, cytochromes.size)
  assert_equal(11, cytochromes.size)
  result = cytochromes["2C19"].inhibitors.size
  assert_equal(19, result)
  result = cytochromes["2C19"].inducers.size
  assert_equal(5, result)
end

- (Object) test_send_flowing_data



268
269
270
271
# File 'test/test_plugin/hayes.rb', line 268

def test_send_flowing_data
  #@writer.send_flowing_data(@html)
  #puts @writer.tablehandlers[0].inspect
end