Test.pm 2.49 KB
Newer Older
1 2
=head1 LICENSE

3
Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Matthieu Muffato's avatar
Matthieu Muffato committed
4
Copyright [2016-2018] EMBL-European Bioinformatics Institute
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

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=cut


package Bio::EnsEMBL::Hive::Utils::Test;

use strict;
use warnings;
no warnings qw( redefine );

use Exporter;
use Carp qw{croak};

use Test::More;
use Test::Exception;

use Bio::EnsEMBL::Hive::Process;
use Bio::EnsEMBL::Hive::AnalysisJob;
use Bio::EnsEMBL::Hive::DBSQL::DBAdaptor;
use Bio::EnsEMBL::Hive::Utils ('load_file_or_module', 'stringify', 'destringify');


our @ISA         = qw(Exporter);
our @EXPORT      = ();
our %EXPORT_TAGS = ();
our @EXPORT_OK   = qw( init_pipeline runWorker );

our $VERSION = '0.00';


sub init_pipeline {
    my ($file_or_module, $pipeline_url, $options) = @_;

    $options ||= [];

    my $hive_dba;
    local @ARGV = @$options;
    local %Bio::EnsEMBL::Hive::Cacheable::cache_by_class;

    lives_ok(sub {
        my @cmd = ($ENV{'EHIVE_ROOT_DIR'}.'/scripts/init_pipeline.pl', $file_or_module, '-pipeline_url', $pipeline_url, @$options);
        my $rc = system(@cmd);
        ok(!$rc, 'pipeline initialized');
        $hive_dba = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new(-url => $pipeline_url);
        ok($hive_dba, 'DBAdaptor created');
    }, sprintf('init_pipeline("%s on %s", %s)', $file_or_module, $pipeline_url, stringify($options)));

    return $hive_dba;
}


sub runWorker {
    my ($hive_dba, $specialization_options, $life_options, $execution_options) = @_;

    $specialization_options ||= {};
    $life_options ||= {};
    $execution_options ||= {};

    lives_ok(sub {
        my $pipeline_url = $hive_dba->dbc->url;
        my @cmd = ($ENV{'EHIVE_ROOT_DIR'}.'/scripts/runWorker.pl', '-url', $pipeline_url);
        my %super_hash = (%$specialization_options, %$life_options, %$execution_options);
        foreach my $option (keys %super_hash) {
            push @cmd, ('-'.$option, $super_hash{$option});
        }
        system(@cmd);
    }, sprintf('runWorker()'));
}


1;