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

« back to all changes in this revision

Viewing changes to t/Variation_IO.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-*-
2
 
## Bioperl Test Harness Script for Modules
3
 
## $Id: Variation_IO.t,v 1.20 2005/09/17 02:11:21 bosborne Exp $
4
 
 
5
 
use strict;
6
 
 
7
 
BEGIN {
8
 
        use vars qw($NUMTESTS $error);
9
 
        $error = 0;
10
 
        eval { require Test; };
11
 
        if( $@ ) {
12
 
                use lib 't';
13
 
        }
14
 
        use Test;
15
 
 
16
 
        eval {
17
 
                require Text::Wrap;
18
 
                require XML::Writer;
19
 
        };
20
 
        if ( $@ || $Text::Wrap::VERSION < 98 ) {
21
 
                print STDERR "Skip tests - missing Text::Wrap 98 installed or XML::Writer\n";
22
 
                $error = 1;
23
 
        }
24
 
        $NUMTESTS = 25;
25
 
        plan tests => $NUMTESTS;
26
 
}
27
 
 
28
 
END {
29
 
        foreach ( $Test::ntest..$NUMTESTS) {
30
 
                skip("Cannot complete Variation_IO tests",1);
31
 
        }
32
 
}
33
 
 
34
 
if ($error == 1 ) {
35
 
        exit(0);
36
 
}
37
 
 
38
 
use Bio::Variation::IO;
39
 
use Bio::Root::IO;
40
 
 
41
 
sub fileformat ($) {
42
 
        my ($file) = shift;
43
 
        my $format;
44
 
        if ($file =~ /.*dat$/) {
45
 
                $format = 'flat';
46
 
        }
47
 
        elsif ($file =~ /.*xml$/ ) {
48
 
                $format = 'xml';
49
 
        } else {
50
 
                print "Wrong extension! [$file]";
51
 
                exit;
52
 
        }
53
 
        return $format;
54
 
}
55
 
 
56
 
sub ext ($) {
57
 
        my ($file) = @_;
58
 
        my ($name) = $file =~ /.*.(...)$/;
59
 
        return $name;
60
 
}
61
 
 
62
 
sub filename ($) {
63
 
        my ($file) = @_;
64
 
        my ($name) = $file =~ /(.*)....$/;
65
 
        return $name;
66
 
}
67
 
 
68
 
sub io {
69
 
    my ($t_file, $o_file) = @_; 
70
 
    my $res;
71
 
 
72
 
    my ($t_ext) = ext ($t_file);
73
 
    my ($o_ext) = ext ($o_file);
74
 
    my ($t_format) = fileformat ($t_file);
75
 
    my ($o_format) = fileformat ($o_file);
76
 
    my ($t_name) = filename($t_file);
77
 
    my ($o_name) = filename($o_file);
78
 
 
79
 
    my( $before );
80
 
    {
81
 
        local $/ = undef;
82
 
        local *BEFORE;
83
 
        open BEFORE, "$t_name.$o_ext";
84
 
        $before = <BEFORE>;
85
 
        close BEFORE;
86
 
    }
87
 
 
88
 
    ok $before;#"Error in reading input file [$t_name.$o_ext]";
89
 
 
90
 
    my $in = Bio::Variation::IO->new( -file => $t_file);
91
 
    my  @entries ;
92
 
    while (my $e = $in->next) {
93
 
        push @entries, $e;
94
 
    }
95
 
    my $count = scalar @entries;
96
 
    ok @entries > 0;# "No SeqDiff objects [$count]";
97
 
 
98
 
    my $out = Bio::Variation::IO->new( -FILE => "> $o_file", 
99
 
                                       -FORMAT => $o_format);
100
 
    my $out_ok = 1;
101
 
    foreach my $e (@entries) {
102
 
        $out->write($e) or $out_ok = 0;
103
 
    }
104
 
    undef($out);  # Flush to disk
105
 
    ok $out_ok;#  "error writing variants";
106
 
 
107
 
    my( $after );
108
 
    {
109
 
        local $/ = undef;
110
 
        local *AFTER;
111
 
        open AFTER, $o_file;
112
 
        $after = <AFTER>;
113
 
        close AFTER;
114
 
    }
115
 
 
116
 
    ok $after;# "Error in reading in again the output file [$o_file]";
117
 
    ok $before, $after, "test output file differs from input";
118
 
    print STDERR `diff $t_file $o_file` if $before ne $after;
119
 
    unlink($o_file); 
120
 
}
121
 
 
122
 
io  (Bio::Root::IO->catfile("t","data","mutations.dat"), 
123
 
     Bio::Root::IO->catfile("t","data","mutations.out.dat")); #1..5
124
 
io  (Bio::Root::IO->catfile("t","data","polymorphism.dat"), 
125
 
     Bio::Root::IO->catfile("t","data","polymorphism.out.dat")); #6..10
126
 
 
127
 
eval {
128
 
    require Bio::Variation::IO::xml;
129
 
};
130
 
 
131
 
if( $@ ) {
132
 
    print STDERR
133
 
         "\nThe XML-format conversion requires the CPAN modules ",
134
 
         "XML::Twig, XML::Writer, and IO::String to be installed ",
135
 
         "on your system, which they probably aren't. Skipping these tests.\n";
136
 
    for( $Test::ntest..$NUMTESTS) {
137
 
         skip("No XML::Twig installed", 1);
138
 
    }
139
 
    exit(0);
140
 
}
141
 
 
142
 
eval {
143
 
    if( $XML::Writer::VERSION >= 0.5 ) { 
144
 
        io  (Bio::Root::IO->catfile("t","data","mutations.xml"), 
145
 
             Bio::Root::IO->catfile("t","data","mutations.out.xml")); #10..12
146
 
    } else { 
147
 
        io  (Bio::Root::IO->catfile("t","data","mutations.old.xml"), 
148
 
             Bio::Root::IO->catfile("t","data","mutations.out.xml")); #10..12
149
 
    }
150
 
};
151
 
 
152
 
eval {
153
 
    if( $XML::Writer::VERSION >= 0.5 ) { 
154
 
        io  (Bio::Root::IO->catfile("t","data","polymorphism.xml"), 
155
 
             Bio::Root::IO->catfile("t","data","polymorphism.out.xml")); #13..14
156
 
    } else { 
157
 
        io  (Bio::Root::IO->catfile("t","data","polymorphism.old.xml"), 
158
 
             Bio::Root::IO->catfile("t","data","polymorphism.out.xml")); #13..14
159
 
 
160
 
    }
161
 
};
162
 
 
163
 
eval { 
164
 
    if( $XML::Writer::VERSION >= 0.5 ) { 
165
 
        io  (Bio::Root::IO->catfile("t","data","mutations.dat"), 
166
 
             Bio::Root::IO->catfile("t","data","mutations.out.xml")); #15..25
167
 
    } else { 
168
 
        io  (Bio::Root::IO->catfile("t","data","mutations.old.dat"), 
169
 
             Bio::Root::IO->catfile("t","data","mutations.old.out.xml")); #15..25
170
 
    }
171
 
};