Skip to content
Snippets Groups Projects
Commit c70d55a1 authored by Andy Yates's avatar Andy Yates
Browse files

Covering more cases with the execute_single_result() code

parent d7d9bdac
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,7 @@ my $dba = $multi->get_DBAdaptor( 'core' ); ...@@ -22,6 +22,7 @@ my $dba = $multi->get_DBAdaptor( 'core' );
ok( $dba, 'Test database instatiated' ); ok( $dba, 'Test database instatiated' );
#Now start testing the Helper #Now start testing the Helper
dies_ok { Bio::EnsEMBL::Utils::SqlHelper->new() } 'Expect to die when no DBConnection was given';
dies_ok { Bio::EnsEMBL::Utils::SqlHelper->new(-DB_CONNECTION => $dba) } dies_ok { Bio::EnsEMBL::Utils::SqlHelper->new(-DB_CONNECTION => $dba) }
'Expect to die when we do not give SqlHelper a DBConncetion'; #was given a DBAdaptor 'Expect to die when we do not give SqlHelper a DBConncetion'; #was given a DBAdaptor
ok ( ok (
...@@ -32,7 +33,6 @@ ok ( ...@@ -32,7 +33,6 @@ ok (
my $helper = Bio::EnsEMBL::Utils::SqlHelper->new(-DB_CONNECTION => $dba->dbc()); my $helper = Bio::EnsEMBL::Utils::SqlHelper->new(-DB_CONNECTION => $dba->dbc());
ok ( $helper, 'SqlHelper instance was created' ); ok ( $helper, 'SqlHelper instance was created' );
my $meta_key = 'species.common_name'; my $meta_key = 'species.common_name';
note("Meta key queries working with ${meta_key}. If the tests fail then check for it in the DB dumps"); note("Meta key queries working with ${meta_key}. If the tests fail then check for it in the DB dumps");
...@@ -48,6 +48,9 @@ is( ...@@ -48,6 +48,9 @@ is(
'Checking count of meta key is right with params' 'Checking count of meta key is right with params'
); );
throws_ok { $helper->execute_single_result(-SQL => 'select * from meta') } qr/Too many results/, 'More than 1 row causes an error';
throws_ok { $helper->execute_single_result(-SQL => 'select * from meta where species_id =?', -PARAMS => [-1]) } qr/No results/, 'Less than 1 row causes an error';
is_deeply( is_deeply(
$helper->execute(-SQL => 'select count(*), 3 from meta where meta_key =?', -PARAMS => [$meta_key])->[0], $helper->execute(-SQL => 'select count(*), 3 from meta where meta_key =?', -PARAMS => [$meta_key])->[0],
[1,3], [1,3],
...@@ -70,7 +73,7 @@ is($meta_count_hash->{$meta_key}, 1, 'Checking hash comes back correctly'); ...@@ -70,7 +73,7 @@ is($meta_count_hash->{$meta_key}, 1, 'Checking hash comes back correctly');
); );
my $expected_hash = { my $expected_hash = {
'species.classification' => [ 'species.classification' => [
qw(Hominidae Catarrhini Primates Eutheria Mammalia Vertebrata Chordata Metazoa Eukaryota) 'Homo sapiens', qw(Hominidae Catarrhini Primates Eutheria Mammalia Vertebrata Chordata Metazoa Eukaryota)
] ]
}; };
......
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