~ubuntu-branches/ubuntu/saucy/bioperl/saucy-proposed

« back to all changes in this revision

Viewing changes to t/Biblio/Biblio.t

  • Committer: Bazaar Package Importer
  • Author(s): Charles Plessy
  • Date: 2009-03-10 07:19:11 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090310071911-fukqzw54pyb1f0bd
Tags: 1.6.0-2
* Removed patch system (not used):
  - removed instuctions in debian/rules;
  - removed quilt from Build-Depends in debian/control.
* Re-enabled tests:
  - uncommented test command in debian/rules;
  - uncommented previously missing build-dependencies in debian/control.
  - Re-enabled tests and uncommented build-dependencies accordingly.
* Removed libmodule-build-perl and libtest-harness-perl from
  Build-Depends-Indep (provided by perl-modules).
* Better cleaning of empty directories using find -type d -empty -delete
  instead of rmdir in debian/rules (LP: #324001).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*-Perl-*- Test Harness script for Bioperl
 
2
# $Id: Biblio.t 15364 2009-01-13 17:18:10Z cjfields $
 
3
 
 
4
use strict;
 
5
 
 
6
BEGIN { 
 
7
    use lib '.';
 
8
    use Bio::Root::Test;
 
9
    
 
10
    test_begin(-tests => 24);
 
11
        
 
12
        use_ok('Bio::Biblio');
 
13
        use_ok('Bio::Biblio::IO');
 
14
}
 
15
 
 
16
my $testnum;
 
17
my $verbose = test_debug();
 
18
 
 
19
my $testfile = test_input_file('stress_test_medline.xml');
 
20
my $testfile2 = test_input_file('stress_test_pubmed.xml');
 
21
 
 
22
# check 'new...'
 
23
SKIP: {
 
24
    test_skip(-tests => 1, -requires_module => 'SOAP::Lite');
 
25
        ok my $biblio = Bio::Biblio->new(-location => 'http://localhost:4567');
 
26
}
 
27
 
 
28
# check MEDLINE XML parser
 
29
my $io;
 
30
SKIP: {
 
31
        test_skip(-tests => 4, -requires_module => 'XML::Parser');
 
32
    
 
33
    ok defined ($io = Bio::Biblio::IO->new('-format' => 'medlinexml',
 
34
                                                 '-file'   => $testfile,
 
35
                                                 '-result' => 'raw'));
 
36
        
 
37
    print "Reading and parsing MEDLINE XML file...\n" if $verbose;
 
38
    is ($io->next_bibref->{'medlineID'}, 'Text1', 'citation 1');
 
39
    is ($io->next_bibref->{'medlineID'}, 'Text248', 'citation 2');
 
40
    is ($io->next_bibref->{'medlineID'}, 'Text495', 'citation 3');
 
41
}
 
42
 
 
43
SKIP: {
 
44
        test_skip(-tests => 4, -requires_module => 'XML::Parser');      
 
45
        print "Getting citations using callback...\n" if $verbose;
 
46
        my (@ids) = ('Text1', 'Text248', 'Text495');
 
47
        my $callback_used = 'no';
 
48
        $io = Bio::Biblio::IO->new('-format'   => 'medlinexml',
 
49
                                   '-file'     => $testfile,
 
50
                                  #'-result'   => 'medline2ref',  # this is default
 
51
                                   '-callback' => \&callback);
 
52
        
 
53
        is ( $callback_used, 'yes', 'calling callback');
 
54
        
 
55
        sub callback {
 
56
                my $citation = shift;
 
57
                $callback_used = 'yes';
 
58
                is ($citation->{'_identifier'}, shift @ids, 'in callback');
 
59
        }
 
60
}
 
61
 
 
62
SKIP: {
 
63
        test_skip(-tests => 2, -requires_module => 'XML::Parser');
 
64
        
 
65
    $io = Bio::Biblio::IO->new('-format'   => 'medlinexml',
 
66
                                                           '-data'     => <<XMLDATA,
 
67
<MedlineCitationSet>
 
68
<MedlineCitation>
 
69
<MedlineID>12345678</MedlineID>
 
70
<Article><Journal></Journal></Article>
 
71
</MedlineCitation>
 
72
<MedlineCitation>
 
73
<MedlineID>abcdefgh</MedlineID>
 
74
<Article><Journal></Journal></Article>
 
75
</MedlineCitation>
 
76
</MedlineCitationSet>
 
77
XMLDATA
 
78
                                                           '-result'   => 'medline2ref');
 
79
        
 
80
        is ($io->next_bibref->{'_identifier'}, '12345678', 'citation 1');
 
81
        is ($io->next_bibref->{'_identifier'}, 'abcdefgh', 'citation 2');
 
82
}
 
83
 
 
84
SKIP: {
 
85
        test_skip(-tests => 2, -requires_modules => [qw(XML::Parser IO::String)]);
 
86
        
 
87
    print "Reading and parsing XML string handle...\n" if $verbose;
 
88
    my $data = <<XMLDATA;
 
89
<MedlineCitationSet>
 
90
<MedlineCitation>
 
91
<MedlineID>87654321</MedlineID>
 
92
<Article><Journal></Journal></Article>
 
93
</MedlineCitation>
 
94
<MedlineCitation>
 
95
<MedlineID>hgfedcba</MedlineID>
 
96
<Article><Journal></Journal></Article>
 
97
</MedlineCitation>
 
98
</MedlineCitationSet>
 
99
XMLDATA
 
100
    
 
101
        $io = Bio::Biblio::IO->new('-format' => 'medlinexml',
 
102
                                                           '-fh'     => IO::String->new ($data));
 
103
        is (eval { $io->next_bibref->identifier }, '87654321', 'citation 1');
 
104
        is (eval { $io->next_bibref->identifier }, 'hgfedcba', 'citation 2');
 
105
}
 
106
 
 
107
SKIP: {
 
108
        test_skip(-tests => 5, -requires_module => 'XML::Parser');
 
109
        
 
110
    # check PUBMED XML parser
 
111
    ok defined (eval { $io = Bio::Biblio::IO->new('-format' => 'pubmedxml',
 
112
                             '-file'   => $testfile2,
 
113
                             '-result' => 'pubmed2ref') });
 
114
        
 
115
    print "Reading and parsing PUBMED XML file...\n" if $verbose;
 
116
    
 
117
        is ($io->next_bibref->identifier, '11223344', 'citation 1');
 
118
        is ($io->next_bibref->identifier, '21583752', 'citation 2');
 
119
        is ($io->next_bibref->identifier, '21465135', 'citation 3');
 
120
        is ($io->next_bibref->identifier, '21138228', 'citation 4');
 
121
}
 
122
 
 
123
SKIP: {
 
124
    # test for FH
 
125
    my $fh;
 
126
    my @expvals = qw(11223344 21583752 21465135 21138228);
 
127
    print "Testing FH\n" if $verbose;
 
128
    eval { 
 
129
        $fh = Bio::Biblio::IO->newFh('-format' => 'pubmedxml',
 
130
                      '-file'   => $testfile2,
 
131
                      '-result' => 'pubmed2ref');
 
132
        while(<$fh>) {
 
133
            is($_->identifier,shift @expvals, 'filehandle test');
 
134
        }
 
135
    };
 
136
    if( $@) {
 
137
        skip("unable to use pubmedxml",4);
 
138
    }
 
139
}