Commit b8d245bc authored by Leo Gordon's avatar Leo Gordon
Browse files

introduced and used Utils::Test::visualize_jobs() test sub

parent 4f7a6b24
......@@ -46,7 +46,7 @@ use Bio::EnsEMBL::Hive::Scripts::RunWorker;
our @ISA = qw(Exporter);
our @EXPORT = ();
our %EXPORT_TAGS = ();
our @EXPORT_OK = qw( standaloneJob init_pipeline runWorker beekeeper seed_pipeline get_test_urls get_test_url_or_die run_sql_on_db load_sql_in_db make_new_db_from_sqls make_hive_db );
our @EXPORT_OK = qw( standaloneJob init_pipeline runWorker beekeeper visualize_jobs seed_pipeline get_test_urls get_test_url_or_die run_sql_on_db load_sql_in_db make_new_db_from_sqls make_hive_db );
our $VERSION = '0.00';
......@@ -209,6 +209,28 @@ sub init_pipeline {
}
=head2 _test_ehive_script
Arg[1] : String $script_name. The name of the script (assumed to be found in
ensembl-hive/scripts/ once the .pl suffix added)
Arg[2] : String $url. The location of the database
Arg[3] : Arrayref $args. Extra arguments given to the script
Arg[4] : String $test_name (optional). The name of the test
Description : Generic method that can run any eHive script and check its return status
Returntype : None
Exceptions : TAP-style
Caller : other methods in Utils::Test
Status : Stable
=cut
sub _test_ehive_script {
my ($script_name, $url, $args, $test_name) = @_;
$test_name ||= 'Can run '.$script_name.($args ? ' with '.join(' ', @$args) : '');
ok(!system($ENV{'EHIVE_ROOT_DIR'}.'/scripts/'.$script_name.'.pl', -url => $url, @{$args || []}), $test_name);
}
=head2 runWorker
Arg[1] : String $url. The location of the database
......@@ -242,28 +264,6 @@ sub runWorker {
}
=head2 _test_ehive_script
Arg[1] : String $script_name. The name of the script (assumed to be found in
ensembl-hive/scripts/ once the .pl suffix added)
Arg[2] : String $url. The location of the database
Arg[3] : Arrayref $args. Extra arguments given to beekeeper
Arg[4] : String $test_name (optional). The name of the test
Description : Generic method that can run any eHive script and check its return status
Returntype : None
Exceptions : TAP-style
Caller : other methods in Utils::Test
Status : Stable
=cut
sub _test_ehive_script {
my ($script_name, $url, $args, $test_name) = @_;
$test_name ||= 'Can run '.$script_name.($args ? ' with '.join(' ', @$args) : '');
ok(!system($ENV{'EHIVE_ROOT_DIR'}.'/scripts/'.$script_name.'.pl', -url => $url, @{$args || []}), $test_name);
}
=head2 seed_pipeline
Arg[1] : String $url. The location of the database
......@@ -287,9 +287,9 @@ sub seed_pipeline {
=head2 beekeeper
Arg[1] : String $url. The location of the database
Arg[2] : Arrayref $args. Extra arguments given to beekeeper
Arg[2] : Arrayref $args. Extra arguments given to beekeeper.pl
Arg[3] : String $test_name (optional). The name of the test
Example : $beekeeper($url, [$arg1, $arg2], 'Run beekeeper with two arguments');
Example : beekeeper($url, [$arg1, $arg2], 'Run beekeeper with two arguments');
Description : Very generic function to run beekeeper on the given database with the given arguments
Returntype : None
Exceptions : TAP-style
......@@ -303,6 +303,25 @@ sub beekeeper {
}
=head2 visualize_jobs
Arg[1] : String $url. The location of the database
Arg[2] : Arrayref $args. Extra arguments given to visualize_jobs.pl
Arg[3] : String $test_name (optional). The name of the test
Example : visualize_jobs($url, [-output => 'lm_jobs.png', -accu_values], 'Generate a PNG J-diagram with accu values');
Description : Very generic function to run visualize_jobs.pl on the given database with the given arguments
Returntype : None
Exceptions : TAP-style
Caller : general
Status : Stable
=cut
sub visualize_jobs {
return _test_ehive_script('visualize_jobs', @_);
}
=head2 run_sql_on_db
Arg[1] : String $url. The location of the database
......
......@@ -25,7 +25,7 @@ use Test::File::Contents; # import file_contents_eq_or_diff()
use Test::More;
use Bio::EnsEMBL::Hive::Utils::Config; # for Bio::EnsEMBL::Hive::Utils::Config->default_system_config
use Bio::EnsEMBL::Hive::Utils::Test qw(runWorker beekeeper run_sql_on_db get_test_url_or_die);
use Bio::EnsEMBL::Hive::Utils::Test qw(init_pipeline runWorker beekeeper visualize_jobs run_sql_on_db get_test_url_or_die);
# eHive needs this to initialize the pipeline (and run db_cmd.pl)
$ENV{'EHIVE_ROOT_DIR'} ||= File::Basename::dirname( File::Basename::dirname( File::Basename::dirname( Cwd::realpath($0) ) ) );
......@@ -46,12 +46,6 @@ my $ref_output_location = $ENV{'EHIVE_ROOT_DIR'}.'/t/03.scripts/visualize_jobs';
my ($fh, $generated_diagram_filename) = tempfile(UNLINK => 1);
close($fh);
sub test_command {
my $cmd_array = shift;
ok(!system(@$cmd_array), 'Can run '.join(' ', @$cmd_array));
}
my $conf_2_plan = {
'LongMult::PipeConfig::LongMult_conf' => [
[ ], # an empty list effectively skips running a worker (which is useful in the beginning)
......@@ -72,13 +66,7 @@ foreach my $conf (keys %$conf_2_plan) {
my $module_name = 'Bio::EnsEMBL::Hive::Examples::'.$conf;
my $jobs_in_order = $conf_2_plan->{$conf};
my @init_pipeline_args = ( $ENV{'EHIVE_ROOT_DIR'}.'/scripts/init_pipeline.pl',
$module_name,
-pipeline_url => $vj_url,
-hive_force_init => 1,
-tweak => 'pipeline.param[take_time]=0'
);
test_command(\@init_pipeline_args);
init_pipeline($module_name, $vj_url, [ -hive_force_init => 1 ], [ 'pipeline.param[take_time]=0' ]);
my $pipeline_name = Bio::EnsEMBL::Hive::HivePipeline->new( -url => $vj_url )->hive_pipeline_name;
......@@ -87,9 +75,9 @@ foreach my $conf (keys %$conf_2_plan) {
system('mkdir', '-p', $ref_directory);
}
foreach my $step_number (0..@$jobs_in_order-1) {
foreach my $step_number (1..@$jobs_in_order) {
foreach my $job_id_or_bk_args ( @{ $jobs_in_order->[$step_number] } ) {
foreach my $job_id_or_bk_args ( @{ $jobs_in_order->[$step_number-1] } ) {
if( ref($job_id_or_bk_args) ) {
beekeeper($vj_url, $job_id_or_bk_args );
} else {
......@@ -97,10 +85,8 @@ foreach my $conf (keys %$conf_2_plan) {
}
}
my @visualize_jobs_args = ( $ENV{'EHIVE_ROOT_DIR'}.'/scripts/visualize_jobs.pl',
# -config_file => Bio::EnsEMBL::Hive::Utils::Config->default_system_config, ## FIXME: not supported yet
-url => $vj_url,
-accu_values,
visualize_jobs( $vj_url, [ -accu_values,
# -config_file => Bio::EnsEMBL::Hive::Utils::Config->default_system_config, ## FIXME: not supported yet
($generate_format eq 'dot')
? (
-output => '/dev/null',
......@@ -110,10 +96,9 @@ foreach my $conf (keys %$conf_2_plan) {
-format => $generate_format,
-output => $generated_diagram_filename,
)
);
test_command(\@visualize_jobs_args);
], "Generated a PNG J-diagram for pipeline '$pipeline_name', step $step_number, with accu values" );
my $ref_filename = sprintf("%s/%s_jobs_%02d.%s", $ref_directory, $pipeline_name, $step_number+1, $generate_format);
my $ref_filename = sprintf("%s/%s_jobs_%02d.%s", $ref_directory, $pipeline_name, $step_number, $generate_format);
if($generate_files) {
system('cp', '-f', $generated_diagram_filename, $ref_filename);
......
Markdown is supported
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