Skip to content

Commit

Permalink
Merge branch 'version/2.5'
Browse files Browse the repository at this point in the history
* version/2.5:
  Added a unit-test for the parsing of URLs in init_pipeline
  Make sure the URLs are valid in dataflow and control rules
  • Loading branch information
ens-bwalts committed Jul 1, 2020
2 parents 2bf2efc + 43541ab commit 4210309
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
15 changes: 15 additions & 0 deletions modules/Bio/EnsEMBL/Hive/Utils/PCL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use Exporter 'import';
our @EXPORT = qw(WHEN ELSE INPUT_PLUS);

use Bio::EnsEMBL::Hive::Utils ('stringify');
use Bio::EnsEMBL::Hive::Utils::URL;


our $cond_group_marker = 'CONDitionGRoup';
Expand Down Expand Up @@ -70,8 +71,17 @@ sub parse_wait_for {
# create control rules:
foreach my $condition_url (@$wait_for) {
if($condition_url =~ m{^\w+$}) {
# Just a warning because analyses can be added later
my $condition_analysis = $pipeline->collection_of('Analysis')->find_one_by('logic_name', $condition_url)
or warn "WARNING: Could not find a local analysis '$condition_url' to create a control rule (in '".($ctrled_analysis->logic_name)."')\n";
} else {
# URLs that can't be parsed won't magically become parsable, so this is an error
my $url_hash = Bio::EnsEMBL::Hive::Utils::URL::parse($condition_url)
or die "ERROR: Could not parse the URL '$condition_url' to create a control rule (in '".($ctrled_analysis->logic_name)."')\n";
# Now check that the target is actually an analysis
if ((not exists $url_hash->{'query_params'}) or ($url_hash->{'query_params'}->{'object_type'} ne 'Analysis')) {
die "ERROR: The URL '$condition_url' does not refer to an Analysis (to create a control rule in '".($ctrled_analysis->logic_name)."')\n";
}
}
my ($c_rule) = $pipeline->add_new_or_update( 'AnalysisCtrlRule', $verbose, # NB: add_new_or_update returns a list
'condition_analysis_url' => $condition_url,
Expand Down Expand Up @@ -164,8 +174,13 @@ sub parse_flow_into {
my $input_id_template_list = $heirs->{$heir_url};

if($heir_url =~ m{^\w+$}) {
# Just a warning because analyses can be added later
my $heir_analysis = $pipeline->collection_of('Analysis')->find_one_by('logic_name', $heir_url)
or warn "WARNING: Could not find a local analysis named '$heir_url' (dataflow from analysis '".($from_analysis->logic_name)."')\n";
} else {
# URLs that can't be parsed won't magically become parsable, so this is an error
my $url_hash = Bio::EnsEMBL::Hive::Utils::URL::parse($heir_url)
or die "ERROR: Could not parse the URL '$heir_url' (dataflow from analysis '".($from_analysis->logic_name)."'";
}

$input_id_template_list = [ $input_id_template_list ] unless(ref($input_id_template_list) eq 'ARRAY'); # allow for more than one template per analysis
Expand Down
79 changes: 79 additions & 0 deletions t/02.api/pipeconfig_parser.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env perl
# Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
# Copyright [2016-2020] EMBL-European Bioinformatics Institute
#
# 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.


use strict;
use warnings;

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

use Bio::EnsEMBL::Hive::HivePipeline;
use Bio::EnsEMBL::Hive::Utils::PCL;

my $pipeline = Bio::EnsEMBL::Hive::HivePipeline->new();
my ($analysis) = $pipeline->add_new_or_update('Analysis', logic_name => 'first');

subtest 'dataflow', sub {

warnings_are {
Bio::EnsEMBL::Hive::Utils::PCL::parse_flow_into($pipeline, $analysis, [ 'first' ]);
} [], 'no warnings if the analysis exists';

warning_like {
Bio::EnsEMBL::Hive::Utils::PCL::parse_flow_into($pipeline, $analysis, [ 'oops_i_am_missing' ]);
} qr/WARNING: Could not find a local analysis named 'oops_i_am_missing' \Q(dataflow from analysis 'first')/, 'warning about missing analysis';

throws_ok {
Bio::EnsEMBL::Hive::Utils::PCL::parse_flow_into($pipeline, $analysis, [ '<oops_i_am_missing>' ]);
} qr/Could not parse the URL '<oops_i_am_missing>' .dataflow from analysis/, 'invalid URL';

warnings_are {
Bio::EnsEMBL::Hive::Utils::PCL::parse_flow_into($pipeline, $analysis, [ '?logic_name=oops_i_am_missing' ]);
} [], 'no warnings when using an analysis URL, even if it does not exist';

# Accumulators are accepted
warnings_are {
Bio::EnsEMBL::Hive::Utils::PCL::parse_flow_into($pipeline, $analysis, [ '?accu_name=oops_i_am_missing' ]);
} [], 'accu targets are accepted';
};

subtest 'wait_for', sub {

warnings_are {
Bio::EnsEMBL::Hive::Utils::PCL::parse_wait_for($pipeline, $analysis, [ 'first' ]);
} [], 'no warnings if the analysis exists';

warning_like {
Bio::EnsEMBL::Hive::Utils::PCL::parse_wait_for($pipeline, $analysis, [ 'oops_i_am_missing' ]);
} qr/WARNING: Could not find a local analysis 'oops_i_am_missing' to create a control rule \Q(in 'first')/, 'warning about missing analysis';

throws_ok {
Bio::EnsEMBL::Hive::Utils::PCL::parse_wait_for($pipeline, $analysis, [ '<oops_i_am_missing>' ]);
} qr/Could not parse the URL '<oops_i_am_missing>' to create a control rule/, 'invalid URL';

warnings_are {
Bio::EnsEMBL::Hive::Utils::PCL::parse_wait_for($pipeline, $analysis, [ '?logic_name=oops_i_am_missing' ]);
} [], 'no warnings when using an analysis URL, even if it does not exist';

throws_ok {
Bio::EnsEMBL::Hive::Utils::PCL::parse_wait_for($pipeline, $analysis, [ '?accu_name=oops_i_am_missing' ]);
} qr/ERROR: The URL '.*' does not refer to an Analysis/, 'accu targets are not accepted';
};

done_testing();

0 comments on commit 4210309

Please sign in to comment.