-
Notifications
You must be signed in to change notification settings - Fork 109
/
test_pubmed.rb
129 lines (105 loc) · 3.48 KB
/
test_pubmed.rb
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
#
# test/functional/bio/io/test_pubmed.rb - Functional test for Bio::PubMed
#
# Copyright:: Copyright (C) 2009
# Naohisa Goto <ng@bioruby.org>
# License:: The Ruby License
#
# $Id:$
#
require 'pathname'
libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4, 'lib')).cleanpath.to_s
$:.unshift(libpath) unless $:.include?(libpath)
require 'bio/io/pubmed'
require 'bio/db/medline'
require 'test/unit'
module Bio
module FuncTestPubmedCommon
def test_esearch
a = @pm.esearch('agile bioinformatics')
assert_kind_of(Array, a)
assert_operator(a.size, :>=, 3,
'The failure may be caused by changes of NCBI PubMed.')
a.each do |x|
assert_kind_of(String, x)
assert_equal(x.strip, x.to_i.to_s,
'PMID is not an integer value. This suggests that NCBI have changed the PMID policy.')
end
end
def test_esearch_count
a = @pm.esearch('agile bioinformatics',
{ "rettype"=>"count" })
assert_kind_of(Integer, a)
assert_operator(a, :>=, 3,
'The failure may be caused by changes of NCBI PubMed.')
end
def test_esearch_retmax_retstart
a = @pm.esearch('p53', { "retmax" => 10, "retstart" => 20 })
assert_equal(10, a.size,
'The failure may be caused by changes of NCBI PubMed.')
a.each do |x|
assert_kind_of(String, x)
assert_equal(x.strip, x.to_i.to_s,
'PMID is not an integer value. This suggests that NCBI have changed the PMID policy.')
end
a1 = @pm.esearch('p53', { "retmax" => 15, "retstart" => 35 })
a2 = @pm.esearch('p53', { "retmax" => 10, "retstart" => 0 })
assert_equal(35, (a + a1 + a2).sort.uniq.size,
'The failure may be caused by changes of NCBI PubMed.')
a3 = @pm.esearch('p53', { "retmax" => 10 })
assert_equal(a2.sort, a3.sort,
'The failure may be caused by changes of NCBI PubMed.')
end
def check_pubmed_entry(pmid, str)
m = Bio::MEDLINE.new(str)
assert_equal(pmid.to_s, m.pmid)
end
private :check_pubmed_entry
def do_efetch_single(pmid)
a = @pm.efetch(pmid)
assert_kind_of(Array, a)
assert_equal(1, a.size)
check_pubmed_entry(pmid, a[0])
end
private :do_efetch_single
def test_efetch
do_efetch_single(12368254)
end
def test_efetch_str
do_efetch_single("16734914")
end
def test_efetch_multiple
arg = [ 12368254, 18689808, 19304878 ]
a = @pm.efetch(arg)
assert_kind_of(Array, a)
assert_equal(3, a.size)
a.each do |str|
check_pubmed_entry(arg.shift, str)
end
end
def test_efetch_single_xml
arg = 12368254
str = @pm.efetch(arg, { "retmode" => 'xml' })
assert_kind_of(String, str)
assert(str.index(/\<PubmedArticleSet\>/))
end
def test_efetch_multiple_xml
arg = [ "16734914", 16381885, "10592173" ]
str = @pm.efetch(arg, { "retmode" => 'xml' })
assert_kind_of(String, str)
assert(str.index(/\<PubmedArticleSet\>/))
end
end #module FuncTestPubmedCommon
class FuncTestPubmed < Test::Unit::TestCase
include FuncTestPubmedCommon
def setup
@pm = Bio::PubMed.new
end
end #class FuncTestPubmed
class FuncTestPubmedClassMethod < Test::Unit::TestCase
include FuncTestPubmedCommon
def setup
@pm = Bio::PubMed
end
end #class FuncTestPubmedClassMethod
end