Skip to content

Commit 78917fe

Browse files
committed
Test init_pipeline outside of the test process.
init_pipeline was the last script tested this way. That caused some issues because it is not isolated from the test process, and for instance it will register the pipeline in TheApiary. Also, the test is more reliable if the actual script is tested.
1 parent d5a5e79 commit 78917fe

File tree

5 files changed

+20
-34
lines changed

5 files changed

+20
-34
lines changed

modules/Bio/EnsEMBL/Hive/Utils/Test.pm

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -199,20 +199,11 @@ sub init_pipeline {
199199
$url = (splice(@$options, $url_flag_index, 2))[1];
200200
}
201201

202-
local @ARGV = @$options;
203-
unshift @ARGV, (-pipeline_url => $url, -hive_force_init => 1);
204-
205-
lives_ok(sub {
206-
my $orig_unambig_url = Bio::EnsEMBL::Hive::Utils::URL::parse($url)->{'unambig_url'};
207-
ok($orig_unambig_url, 'Given URL could be parsed');
208-
my $returned_url = Bio::EnsEMBL::Hive::Scripts::InitPipeline::init_pipeline($file_or_module, $tweaks);
209-
ok($returned_url, 'pipeline initialized on '.$returned_url);
210-
211-
my $returned_unambig_url = Bio::EnsEMBL::Hive::Utils::URL::parse($returned_url)->{'unambig_url'};
212-
# Both $url and $returned_url MAY contain the password (if applicable for the driver) but can be missing the port number assuming a default
213-
# Both $orig_unambig_url and $returned_unambig_url SHOULD contain the port number (if applicable for the driver) but WILL NOT contain a password
214-
is($returned_unambig_url, $orig_unambig_url, 'pipeline initialized on '.$url);
215-
}, sprintf('init_pipeline("%s", %s)', $file_or_module, stringify($options)));
202+
my @args = ($file_or_module, -pipeline_url => $url, -hive_force_init => 1);
203+
push @args, @$options;
204+
push @args, map {-tweak => $_} @$tweaks if $tweaks;
205+
206+
return _test_ehive_script('init_pipeline', undef, \@args);
216207
}
217208

218209

t/03.scripts/generate_graph.t

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ GetOptions(
3939

4040
my $server_url = get_test_url_or_die(-tag => 'server', -no_user_prefix => 1);
4141

42-
# Most of the test scripts test init_pipeline() from Utils::Test but we
43-
# also need to test the main scripts/init_pipeline.pl !
44-
my @init_pipeline_args = ($ENV{'EHIVE_ROOT_DIR'}.'/scripts/init_pipeline.pl', 'Bio::EnsEMBL::Hive::Examples::LongMult::PipeConfig::LongMultServer_conf', -pipeline_url => $server_url, -hive_force_init => 1, -tweak => 'pipeline.param[take_time]=0');
45-
test_command(\@init_pipeline_args);
42+
init_pipeline(
43+
'Bio::EnsEMBL::Hive::Examples::LongMult::PipeConfig::LongMultServer_conf',
44+
$server_url,
45+
[],
46+
[
47+
'pipeline.param[take_time]=0',
48+
],
49+
);
4650

4751

4852
my $client_url = get_test_url_or_die(-tag => 'client', -no_user_prefix => 1);
@@ -59,12 +63,6 @@ push @confs_to_test, 'GC::PipeConfig::GCPct_conf' unless $@; # SKIP it in cas
5963
my ($fh, $tmp_filename) = tempfile(UNLINK => 1);
6064
close($fh);
6165

62-
sub test_command {
63-
my $cmd_array = shift;
64-
ok(!system(@$cmd_array), 'Can run '.join(' ', @$cmd_array));
65-
}
66-
67-
6866
foreach my $conf (@confs_to_test) {
6967
subtest $conf, sub {
7068
my $module_name = 'Bio::EnsEMBL::Hive::Examples::'.$conf;

t/10.pipeconfig/analysis_heir.t

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ $ENV{'EHIVE_ROOT_DIR'} ||= File::Basename::dirname( File::Basename::dirname( Fil
3232
my $pipeline_url = get_test_url_or_die();
3333

3434
my $init_stderr = capture_stderr {
35-
local @INC = @INC;
36-
push @INC, $ENV{'EHIVE_ROOT_DIR'}.'/t/10.pipeconfig/';
35+
local $ENV{'PERL5LIB'} = $ENV{'EHIVE_ROOT_DIR'}.'/t/10.pipeconfig/::'.$ENV{PERL5LIB};
3736
init_pipeline(
3837
'TestPipeConfig::MissingAnalysis_conf',
3938
$pipeline_url,

t/10.pipeconfig/gc_dataflow.t

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ $ENV{'EHIVE_ROOT_DIR'} ||= File::Basename::dirname( File::Basename::dirname( Fil
3030
my $pipeline_url = get_test_url_or_die();
3131

3232
{
33-
local @INC = @INC;
34-
push @INC, $ENV{'EHIVE_ROOT_DIR'}.'/t/10.pipeconfig/';
33+
local $ENV{'PERL5LIB'} = $ENV{'EHIVE_ROOT_DIR'}.'/t/10.pipeconfig/::'.$ENV{PERL5LIB};
3534
init_pipeline('TestPipeConfig::AnyFailureBranch_conf', $pipeline_url, [], ['pipeline.param[take_time]=100']);
3635
}
3736
my $hive_dba = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new( -url => $pipeline_url );

t/10.pipeconfig/pipeline_url.t

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,18 @@ use warnings;
2121

2222
use Test::More;
2323

24-
use Bio::EnsEMBL::Hive::Utils::Test qw(init_pipeline beekeeper get_test_url_or_die safe_drop_database);
24+
use Bio::EnsEMBL::Hive::Utils::Test qw(init_pipeline get_test_url_or_die safe_drop_database);
2525
use Bio::EnsEMBL::Hive::Utils qw(destringify);
2626

2727
# eHive needs this to initialize the pipeline (and run db_cmd.pl)
2828
$ENV{'EHIVE_ROOT_DIR'} ||= File::Basename::dirname( File::Basename::dirname( File::Basename::dirname( Cwd::realpath($0) ) ) );
2929

3030
my $pipeline_url = get_test_url_or_die();
3131

32-
# Utils::Test::init_pipeline runs things internally instead of invoking init_pipeline.pl
33-
# Here we need to run the script to trigger the password sanitization
34-
my @cmd = ('env', 'PERL5LIB='.$ENV{'EHIVE_ROOT_DIR'}.'/t/10.pipeconfig/::'.$ENV{PERL5LIB}, $ENV{'EHIVE_ROOT_DIR'}.'/scripts/init_pipeline.pl', 'TestPipeConfig::PipelineURL_conf', -pipeline_url => $pipeline_url);
35-
my $rc = system(@cmd);
36-
is($rc, 0, 'init_pipeline.pl successfully ran');
32+
{
33+
local $ENV{'PERL5LIB'} = $ENV{'EHIVE_ROOT_DIR'}.'/t/10.pipeconfig/::'.$ENV{PERL5LIB};
34+
init_pipeline('TestPipeConfig::PipelineURL_conf', $pipeline_url);
35+
}
3736

3837
my $hive_dba = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new( -url => $pipeline_url );
3938

0 commit comments

Comments
 (0)