Skip to content
Snippets Groups Projects
Commit 982e4f34 authored by Graham McVicker's avatar Graham McVicker
Browse files

Added TestUtils module with a single class method test_getter_setter

updated predictionTranscript test to use new module
parent 007766bc
No related branches found
No related tags found
No related merge requests found
use strict;
package TestUtils;
=head2 test_getter_setter
Arg [1] : Object $object
The object to test the getter setter on
Arg [2] : string $method
The name of the getter setter method to test
Arg [3] : $test_val
The value to use to test the set behavior of the method.
Example : ok(&TestUtils::test_getter_setter($object, 'type', 'value'));
Description: Tests a getter setter method by attempting to set a value
and verifying that the newly set value can be retrieved. The
old value of the the attribute is restored after the test
(providing the method functions correctly).
Returntype : boolean - true value on success, false on failure
Exceptions : none
Caller : test scripts
=cut
sub test_getter_setter {
my ($object, $method, $test_val) = @_;
my $ret_val = 0;
#save the old value
my $old_val = $object->$method;
$object->$method($test_val);
#verify value was set
$ret_val = ($object->$method eq $test_val);
#restore the old value
$object->$method($old_val);
return $ret_val;
}
1;
......@@ -9,7 +9,7 @@ BEGIN { $| = 1;
}
use MultiTestDB;
use Bio::EnsEMBL::DBSQL::SliceAdaptor;
use TestUtils;
use Bio::EnsEMBL::PredictionTranscript;
use Bio::EnsEMBL::Exon;
......@@ -59,41 +59,41 @@ ok($pt->stable_id =~ /(\w+\.\d+\.\d+\.\d+)\.(\d+)\.(\d+)/);
#
# 6 test coding start
#
ok(&test_getter_setter($pt, 'coding_start', 6));
ok(&TestUtils::test_getter_setter($pt, 'coding_start', 6));
#
# 7 test coding end
#
ok(&test_getter_setter($pt, 'coding_end', 7));
ok(&TestUtils::test_getter_setter($pt, 'coding_end', 7));
#
# 8 test start
#
ok(&test_getter_setter($pt, 'start', 8));
ok(&TestUtils::test_getter_setter($pt, 'start', 8));
#
# 9 test end
#
ok(&test_getter_setter($pt, 'end', 9));
ok(&TestUtils::test_getter_setter($pt, 'end', 9));
#
# 10 test analysis
#
my $analysis = $db->get_AnalysisAdaptor->fetch_by_logic_name('Vertrna');
ok(&test_getter_setter($pt, 'analysis', $analysis));
ok(&TestUtils::test_getter_setter($pt, 'analysis', $analysis));
#
# 11 test dbID
#
ok(&test_getter_setter($pt, 'dbID', 11));
ok(&TestUtils::test_getter_setter($pt, 'dbID', 11));
#
# 12 test adaptor
#
my $pta = $db->get_PredictionTranscriptAdaptor;
ok(&test_getter_setter($pt, 'adaptor', $pta));
ok(&TestUtils::test_getter_setter($pt, 'adaptor', $pta));
#
# 13-17 test add Exon
......@@ -212,5 +212,5 @@ ok($pt->_dump || 1);
#
# 33 test type
#
ok(&test_getter_setter($pt, 'type', 'test'));
ok(&TestUtils::test_getter_setter($pt, 'type', 'test'));
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