Add tests for memory leaks and weaken for Issue #81
[bioperl-live.git] / t / RemoteDB / SwissProt.t
blobb5f94e33f897e1be7915424be846de7e30fb9590
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN {
7     use lib '.';
8     use Bio::Root::Test;
10     test_begin(-tests               => 23,
11                -requires_modules    => [qw(IO::String
12                                            LWP::UserAgent
13                                            HTTP::Request::Common)],
14                -requires_networking => 1);
16     use_ok('Bio::DB::SwissProt');
19 ok my $gb = Bio::DB::SwissProt->new(-retrievaltype => 'pipeline',
20                                     -delay         => 0);
22 my %expected_lengths = (
23                         'NDP_MOUSE'   => 131,
24                         'NDP_HUMAN'   => 133,
25                         'BOLA_HAEIN'  => 103,
26                         'YNB3_YEAST'  => 125,
27                         'O39869'      => 56,
28                         'DEGP_CHLTR'  => 497,
29                         'DEGPL_CHLTR' => 497
30                         );
32 my ($seq, $seqio);
34 SKIP: {
35     eval {$seq = $gb->get_Seq_by_id('YNB3_YEAST');};
36     skip "Couldn't connect to SwissProt with Bio::DB::SwissProt.pm. Skipping those tests", 14 if $@;
37     is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
38     is $seq->division, 'YEAST';
40     eval {$seq = $gb->get_Seq_by_acc('P43780');};
41     skip "Couldn't connect to SwissProt with Bio::DB::SwissProt.pm. Skipping those tests", 12 if $@;
42     is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
43     eval {$seq = $gb->get_Seq_by_acc('O39869');};
44     skip "Couldn't connect to SwissProt with Bio::DB::SwissProt.pm. Skipping those tests", 11 if $@;
45     is $seq->length, $expected_lengths{$seq->accession_number}, $seq->accession_number;
46     is $seq->accession_number, 'O39869';
47     is $seq->division, '9PICO';
49     # test for bug #958
50     eval {$seq = $gb->get_Seq_by_id('P18584');};
51     skip "Couldn't connect to SwissProt with Bio::DB::SwissProt.pm. Skipping those tests", 8 if $@;
52     ok exists $expected_lengths{$seq->display_id}, 'P18584';
53     is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
54     is $seq->division, 'CHLTR';
56     ok $gb = Bio::DB::SwissProt->new('-retrievaltype' => 'tempfile', '-delay' => 0);
57     eval {$seqio = $gb->get_Stream_by_id(['NDP_MOUSE', 'NDP_HUMAN']);};
58     skip "Couldn't connect to SwissProt with Bio::DB::SwissProt.pm. Skipping those tests", 4 if $@;
59     undef $gb; # testing to see if we can remove gb
60     ok $seq = $seqio->next_seq();
61     is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
62     ok $seq = $seqio->next_seq();
63     is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
66 # test idtracker() method
67 ok $gb = Bio::DB::SwissProt->new(-retrievaltype => 'pipeline',
68                                  -delay         => 0,
69                                  -verbose       => 2);
71 SKIP: {
72     my $map;
73     # check old ID
74     eval {$map = $gb->id_mapper(-from => 'ACC+ID',
75                                 -to   => 'ACC',
76                                 -ids  => [qw(MYOD1_PIG PYRC_YEAST)]
77                                 )};
78     skip("Problem with idtracker(), skipping these tests: $@", 6) if $@;
80     cmp_ok(@{$map->{MYOD1_PIG}}, '>=', 1);
81     is($map->{MYOD1_PIG}[0], 'P49811');
82     cmp_ok(@{$map->{PYRC_YEAST}}, '>=', 1);
83     is($map->{PYRC_YEAST}[0], 'P20051');
85     eval {$map = $gb->id_mapper(-from => 'ACC+ID',
86                                 -to   => 'EMBL',
87                                 -ids  => [qw(PYRC_YEAST)]
88                                 )};
89     skip("Problem with idtracker(), skipping these tests: $@", 2) if $@;
91     cmp_ok(@{$map->{PYRC_YEAST}}, '>=', 2);
92     like($map->{PYRC_YEAST}[0], qr/^[A-Z0-9]/);