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

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

parent 7a8a0e9b
......@@ -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 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 @EXPORT_OK = qw( standaloneJob init_pipeline runWorker beekeeper generate_graph 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';
......@@ -226,8 +226,11 @@ sub init_pipeline {
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);
$args ||= [];
unshift @$args, (-url => $url) if(defined($url));
$test_name ||= 'Can run '.$script_name.(@$args ? ' with the following cmdline options: '.join(' ', @$args) : '');
ok(!system($ENV{'EHIVE_ROOT_DIR'}.'/scripts/'.$script_name.'.pl', @$args), $test_name);
}
......@@ -303,6 +306,25 @@ sub beekeeper {
}
=head2 generate_graph
Arg[1] : String $url or undef. The location of the database
Arg[2] : Arrayref $args. Extra arguments given to generate_graph.pl
Arg[3] : String $test_name (optional). The name of the test
Example : generate_graph($url, [-output => 'lm_analyses.png'], 'Generate a PNG A-diagram');
Description : Very generic function to run generate_graph.pl on the given database with the given arguments
Returntype : None
Exceptions : TAP-style
Caller : general
Status : Stable
=cut
sub generate_graph {
return _test_ehive_script('generate_graph', @_);
}
=head2 visualize_jobs
Arg[1] : String $url. The location of the database
......
......@@ -19,19 +19,24 @@
use strict;
use warnings;
use Getopt::Long qw(:config pass_through);
use File::Temp qw/tempfile/;
use Test::File::Contents;
use Test::More;
use Data::Dumper;
use Bio::EnsEMBL::Hive::Utils::Config;
use Bio::EnsEMBL::Hive::Utils::Test qw(runWorker run_sql_on_db get_test_url_or_die);
use Bio::EnsEMBL::Hive::Utils::Test qw(init_pipeline runWorker generate_graph 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) ) ) );
my $generate_files = 0;
GetOptions(
'generate!' => \$generate_files,
);
my $server_url = get_test_url_or_die(-tag => 'server', -no_user_prefix => 1);
# Most of the test scripts test init_pipeline() from Utils::Test but we
......@@ -39,6 +44,7 @@ my $server_url = get_test_url_or_die(-tag => 'server', -no_user_prefix => 1);
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');
test_command(\@init_pipeline_args);
my $client_url = get_test_url_or_die(-tag => 'client', -no_user_prefix => 1);
my $ref_output_location = $ENV{'EHIVE_ROOT_DIR'}.'/t/03.scripts/generate_graph/';
......@@ -46,7 +52,7 @@ my $ref_output_location = $ENV{'EHIVE_ROOT_DIR'}.'/t/03.scripts/generate_graph/'
my @confs_to_test = qw(LongMult::PipeConfig::SmartLongMult_conf GC::PipeConfig::GCPct_conf LongMult::PipeConfig::LongMultWf_conf LongMult::PipeConfig::LongMultClient_conf);
# A temporary file to store the output of generate_graph.pl
my ($fh, $filename) = tempfile(UNLINK => 1);
my ($fh, $tmp_filename) = tempfile(UNLINK => 1);
close($fh);
sub test_command {
......@@ -54,46 +60,67 @@ sub test_command {
ok(!system(@$cmd_array), 'Can run '.join(' ', @$cmd_array));
}
my @common_diagram_args = ($ENV{'EHIVE_ROOT_DIR'}.'/scripts/generate_graph.pl', -config_file => Bio::EnsEMBL::Hive::Utils::Config->default_system_config );
foreach my $conf (@confs_to_test) {
subtest $conf, sub {
my $module_name = 'Bio::EnsEMBL::Hive::Examples::'.$conf;
# Unicode-art (dbIDs are never shown, so we can use the PipeConfig directly)
#$filename = $ref_output_location . $conf . '.txt';
my @generate_graph_args = (@common_diagram_args, -pipeconfig => $module_name);
push @generate_graph_args, (-server_url => $server_url) if $conf =~ /Client/;
test_command( [join(' ', @generate_graph_args).' > '.$filename] );
# Unicode-art (dbIDs are never shown, so we can use the PipeConfig directly) :
generate_graph( undef, [ -config_file => Bio::EnsEMBL::Hive::Utils::Config->default_system_config,
-pipeconfig => $module_name,
(($conf =~ /Client/)
? (-server_url => $server_url)
: ()
),
-output => $tmp_filename,
-format => 'txt',
], "Unicode-art A-diagram for $conf",
);
if($generate_files) {
system('cp', $filename, $ref_output_location . $conf . '.txt');
system('cp', $tmp_filename, $ref_output_location . $conf . '.txt');
} else {
files_eq_or_diff($filename, $ref_output_location . $conf . '.txt');
files_eq_or_diff($tmp_filename, $ref_output_location . $conf . '.txt');
}
# Dot output on a PipeConfig (no dBIDs)
#$filename = $ref_output_location . $conf . '.unstored.dot';
@generate_graph_args = (@common_diagram_args, -pipeconfig => $module_name, -output => '/dev/null', -format => 'canon', -dot_input => $filename);
push @generate_graph_args, (-server_url => $server_url) if $conf =~ /Client/;
test_command(\@generate_graph_args);
# Dot output on a PipeConfig (no dBIDs) :
generate_graph( undef, [ -config_file => Bio::EnsEMBL::Hive::Utils::Config->default_system_config,
-pipeconfig => $module_name,
(($conf =~ /Client/)
? (-server_url => $server_url)
: ()
),
-output => '/dev/null',
-format => 'canon',
-dot_input => $tmp_filename,
], "Dot A-diagram for $conf",
);
if($generate_files) {
system('cp', $filename, $ref_output_location . $conf . '.unstored.dot');
system('cp', $tmp_filename, $ref_output_location . $conf . '.unstored.dot');
} else {
files_eq_or_diff($filename, $ref_output_location . $conf . '.unstored.dot');
files_eq_or_diff($tmp_filename, $ref_output_location . $conf . '.unstored.dot');
}
# Dot output on a database (no dBIDs)
@init_pipeline_args = ($ENV{'EHIVE_ROOT_DIR'}.'/scripts/init_pipeline.pl', $module_name, -pipeline_url => $client_url, -hive_force_init => 1);
push @init_pipeline_args, (-server_url => $server_url) if $conf =~ /Client/;
test_command(\@init_pipeline_args);
#my $filename = $ref_output_location . $conf . '.stored.dot';
@generate_graph_args = (@common_diagram_args, -url => $client_url, -output => '/dev/null', -format => 'canon', -dot_input => $filename);
test_command(\@generate_graph_args);
# Dot output on a database (no dBIDs) :
init_pipeline( $module_name, $client_url, [
-hive_force_init => 1,
(($conf =~ /Client/)
? (-server_url => $server_url)
: ()
),
],
[ 'pipeline.param[take_time]=0' ],
);
generate_graph( $client_url, [ -config_file => Bio::EnsEMBL::Hive::Utils::Config->default_system_config,
-output => '/dev/null',
-format => 'canon',
-dot_input => $tmp_filename,
], "Dot A-diagram for a hive database created from $conf",
);
if($generate_files) {
system('cp', $filename, $ref_output_location . $conf . '.stored.dot');
system('cp', $tmp_filename, $ref_output_location . $conf . '.stored.dot');
} else {
files_eq_or_diff($filename, $ref_output_location . $conf . '.stored.dot');
files_eq_or_diff($tmp_filename, $ref_output_location . $conf . '.stored.dot');
}
}
}
......
......@@ -28,7 +28,3 @@ calc_overall_percentage
V
[[ final_result ]]
----------------------------------------------------------
Did you forget to specify the -output flowchart.png ?
----------------------------------------------------------
......@@ -46,7 +46,3 @@ take_b_apart
V
[[ final_result ]]
----------------------------------------------------------
Did you forget to specify the -output flowchart.png ?
----------------------------------------------------------
......@@ -27,7 +27,3 @@ take_b_apart
V
[[ intermediate_result ]]
----------------------------------------------------------
Did you forget to specify the -output flowchart.png ?
----------------------------------------------------------
......@@ -43,7 +43,3 @@ redirect_trivial_jobs
V
[[ final_result ]]
----------------------------------------------------------
Did you forget to specify the -output flowchart.png ?
----------------------------------------------------------
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