Skip to content
Snippets Groups Projects
Commit ce6b1b31 authored by Graham McVicker's avatar Graham McVicker
Browse files

runtests script now catches SIG, INT and HUP signals to ensure correct cleanup

changed some throws to warnings in MultiTestDB
parent 29389440
No related branches found
No related tags found
No related merge requests found
......@@ -27,19 +27,29 @@ if($opt_l) {
exit;
}
#run all of the specified tests
#set environment var
$ENV{'RUNTESTS_HARNESS'} = 1;
#make sure proper cleanup is done if the user interrupts the tests
$SIG{HUP} = $SIG{KILL} = $SIG{INT} =
sub {warn "\n\nINTERRUPT SIGNAL RECEIEVED\n\n"; &clean;};
#create a multitest db, its destruction will clean up after scripts
my $clean_up = new MultiTestDB;
#run all specified tests
eval {
runtests(@{&get_all_tests('.', \@ARGV)});
};
# do some clean up by creating a MultiTestDB object
&clean;
delete $ENV{"RUNTESTS_HARNESS"};
sub clean {
#unset env var indicating final cleanup should be performed
delete $ENV{"RUNTESTS_HARNESS"};
exit;
}
=head2 get_all_tests
......
......@@ -184,7 +184,8 @@ sub load_databases {
my $db = DBI->connect($locator, $user, $pass, {RaiseError => 1});
unless($db) {
$self->throw("Can't connect to database $locator");
$self->warn("Can't connect to database $locator");
return;
}
#create a database for each database specified
......@@ -195,7 +196,8 @@ sub load_databases {
print STDERR "\nCreating db $dbname";
unless($db->do("CREATE DATABASE $dbname")) {
$self->throw("Could not create database [$dbname]");
$self->warn("Could not create database [$dbname]");
return;
}
#copy the general config into a dbtype specific config
......@@ -217,7 +219,10 @@ sub load_databases {
my $dir = $self->curr_dir . "$DUMP_DIR/".$self->species."/$dbtype";
local *DIR;
opendir(DIR, $dir) or die "could not open dump directory '$dir'";
unless(opendir(DIR, $dir)) {
$self->warn("could not open dump directory '$dir'");
return;
}
my @files = readdir DIR;
......@@ -286,7 +291,8 @@ sub unzip_test_dbs {
}
unless(-f $zipfile) {
$self->throw("zipfile could not be found\n");
$self->warn("zipfile could not be found\n");
return;
}
# unzip the zip file quietly
......
use strict;
use warnings;
use lib 't';
use lib 't';
BEGIN { $| = 1;
use Test;
plan tests => 4;
plan tests => 27;
}
my $loaded = 0;
END {print "not ok 1\n" unless $loaded;}
use EnsTestDB;
use MultiTestDB;
use Bio::EnsEMBL::DBLoader;
use Bio::EnsEMBL::Slice;
$loaded = 1;
#
#1 TEST - Slice Compiles
#
ok(1);
ok(1);
# Database will be dropped when this
# object goes out of scope
my $ens_test = EnsTestDB->new;
my $CHR = '20';
my $START = 31_000_000;
my $END = 31_200_000;
my $STRAND = 1;
my $ASSEMBLY_TYPE = 'NCBI_30';
my $DBID = 123;
$ens_test->do_sql_file("t/minidatabase.dump");
my $multi_db = MultiTestDB->new;
my $db = $multi_db->get_DBAdaptor('core');
ok($ens_test);
#
#2-5 TEST - Slice creation from adaptor
#
my $slice_adaptor = $db->get_SliceAdaptor;
my $slice = $slice_adaptor->fetch_by_chr_start_end($CHR, $START, $END);
ok($slice->chr_name eq $CHR);
ok($slice->chr_start == $START);
ok($slice->chr_end == $END);
ok($slice->adaptor);
my $db = $ens_test->get_DBSQL_Obj;
$sla= $db->get_SliceAdaptor();
$slice = $sla->new_slice('1',4,400,'NCBI_28');
#
#6 TEST - Slice::new (empty)
#
$slice = new Bio::EnsEMBL::Slice(-empty => 1);
ok($slice);
&write_feature();
ok(1);
#
#7-12 TEST - Slice::new
#
$slice = new Bio::EnsEMBL::Slice(-chr_name => $CHR,
-chr_start => $START,
-chr_end => $END,
-strand => $STRAND,
-assembly_type => $ASSEMBLY_TYPE,
-dbid => $DBID);
($outf) = $slice->get_all_SimilarityFeatures_above_score(5);
#ok($outf);
ok($slice->chr_name eq $CHR);
ok($slice->chr_start == $START);
ok($slice->chr_end == $END);
ok($slice->strand == $STRAND);
ok($slice->assembly_type eq $ASSEMBLY_TYPE);
ok($slice->dbID == $DBID);
#
#13 Test - Slice::adaptor
#
$slice->adaptor($slice_adaptor);
ok($slice->adaptor == $slice_adaptor);
sub write_feature {
#
#14 Test - Slice::dbID
#
$slice->dbID(10);
ok($slice->dbID==10);
$dna_f_ad = $db->get_DnaAlignFeatureAdaptor();
#
#15-17 Test Slice::name
#
#verify that chr_name start and end are contained in the name
my $name = $slice->name;
ok($name =~/$CHR/);
ok($name =~/$START/);
ok($name =~/$END/);
#
#18 Test Slice::id
#
ok($slice->id eq $slice->name);
$feature1 = new Bio::EnsEMBL::SeqFeature();
$feature1->start(5);
$feature1->end (7);
$feature1->strand(1);
$feature1->score(10);
$feature1->seqname(1);
#$feature1->analysis($self->analysis);
#
#19 Test Slice::length
#
ok($slice->length == ($END-$START + 1));
$feature2 = new Bio::EnsEMBL::SeqFeature();
$feature2->start (105);
$feature2->end (107);
$feature2->strand (1);
$feature2->score (10);
$feature2->seqname("dummy-hid");
$fp = new Bio::EnsEMBL::FeaturePair(-feature1 => $feature1,
-feature2 => $feature2);
#
#20-22 Test Slice::invert
#
my $inverted_slice = $slice->invert;
ok($slice != $inverted_slice); #slice is not same object as inverted slice
#inverted slice on opposite strand
ok($slice->strand == ($inverted_slice->strand * -1));
#slice still on same strand
ok($slice->strand == $STRAND);
push(@feats,$fp);
#
# 23-24 Test Slice::seq
#
my $seq = $slice->seq;
my $invert_seq = $slice->invert->seq;
$feature1 = new Bio::EnsEMBL::SeqFeature();
$feature1->start(10);
$feature1->end (14);
$feature1->strand(1);
$feature1->score(10);
$feature1->seqname(1);
print STDERR "SEQ=[$seq]\n";
#$feature1->analysis($self->analysis);
ok(length($seq) == $slice->length); #sequence is correct length
print STDERR "[".length($seq)."] != [".$slice->length."]\n";
$seq = uc reverse $seq; #reverse complement seq
$seq =~ s/ACTG/TGAC/g;
ok($seq eq $invert_seq); #revcom same as seq on inverted slice
$feature2 = new Bio::EnsEMBL::SeqFeature();
$feature2->start (106);
$feature2->end (110);
$feature2->strand (1);
$feature2->score (10);
$feature2->seqname('dummy-hid');
#
# 25-26 Test Slice::subseq
#
my $SPAN = 10;
my $sub_seq = $slice->subseq(-$SPAN,$SPAN);
my $invert_sub_seq = $slice->invert->subseq($slice->length + $SPAN,
$slice->length - $SPAN);
ok(length $sub_seq == (2*$SPAN) + 1 );
$seq = uc reverse $seq;
$seq =~ s/ACTG/TGAC/g;
ok($seq eq $invert_seq);
$fp2 = new Bio::EnsEMBL::FeaturePair(-feature1 => $feature1,
-feature2 => $feature2);
push(@feats,$fp2);
$dnaf = Bio::EnsEMBL::DnaDnaAlignFeature->new( -features => \@feats );
$dnaf->seqname(1);
$dnaf->hseqname('dummy-hid');
$dnaf->analysis($db->get_AnalysisAdaptor->fetch_by_logic_name("dummy-blast"));
$dna_f_ad->store(1,$dnaf);
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment