From 006b906a3e4aa24d6ef4297f2ba8b85e1edcf467 Mon Sep 17 00:00:00 2001 From: Syed Hussain Ather Date: Sun, 1 Jun 2025 13:11:11 -0400 Subject: [PATCH 1/5] Add test for Bio::SeqI interface using mock class --- t/SeqI.t | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 t/SeqI.t diff --git a/t/SeqI.t b/t/SeqI.t new file mode 100644 index 000000000..d56358c70 --- /dev/null +++ b/t/SeqI.t @@ -0,0 +1,31 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More tests => 4; + +BEGIN { + use_ok('Bio::SeqI'); +} + +{ + package MySeq; + use base qw(Bio::SeqI); + + sub new { + my $class = shift; + return bless {}, $class; + } + + sub display_id { return "test_id"; } + sub seq { return "ATGC"; } + sub desc { return "Test sequence"; } + sub alphabet { return "dna"; } +} + +my $seq = MySeq->new(); + +isa_ok($seq, 'Bio::SeqI'); +is($seq->display_id, 'test_id', 'display_id returns correct value'); +is($seq->seq, 'ATGC', 'seq returns correct sequence'); + From 0196b7a2adbaa82163d3036646f54e1505a36f28 Mon Sep 17 00:00:00 2001 From: Syed Hussain Ather Date: Sun, 1 Jun 2025 13:16:19 -0400 Subject: [PATCH 2/5] Add unit test for Bio::AnnotationI interface using mock implementation --- t/AnnotationI.t | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 t/AnnotationI.t diff --git a/t/AnnotationI.t b/t/AnnotationI.t new file mode 100644 index 000000000..c680ea291 --- /dev/null +++ b/t/AnnotationI.t @@ -0,0 +1,30 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More tests => 4; + +BEGIN { + use_ok('Bio::AnnotationI'); +} + +{ + package MyAnnotation; + use base qw(Bio::AnnotationI); + + sub new { + my $class = shift; + return bless {}, $class; + } + + sub tagname { return "mock_tag"; } + sub as_text { return "Mock annotation as text"; } + sub hash_tree { return {}; } +} + +my $a = MyAnnotation->new(); + +isa_ok($a, 'Bio::AnnotationI'); +is($a->tagname, 'mock_tag', 'tagname returns expected value'); +is($a->as_text, 'Mock annotation as text', 'as_text returns expected value'); + From d3526e9f669e240c87a521a6014cab2355508741 Mon Sep 17 00:00:00 2001 From: Syed Hussain Ather Date: Sun, 1 Jun 2025 13:20:11 -0400 Subject: [PATCH 3/5] Refactor Bio::Species tests into modular files --- t/Species/basic.t | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 t/Species/basic.t diff --git a/t/Species/basic.t b/t/Species/basic.t new file mode 100644 index 000000000..03a4da20c --- /dev/null +++ b/t/Species/basic.t @@ -0,0 +1,25 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More tests => 8; + +use_ok('Bio::Species'); + +my $sps = Bio::Species->new(); +$sps->classification(qw(sapiens Homo Hominidae Catarrhini Primates Eutheria Mammalia Vertebrata Chordata Metazoa Eukaryota)); + +is $sps->binomial, 'Homo sapiens'; + +$sps->sub_species('sapiensis'); +is $sps->binomial, 'Homo sapiens'; +is $sps->binomial('FULL'), 'Homo sapiens sapiensis'; + +is $sps->sub_species, 'sapiensis'; + +my $species = Bio::Species->new( + -classification => [qw(sapiens Homo Hominidae Catarrhini Primates Eutheria Mammalia Vertebrata Chordata Metazoa Eukaryota)], + -common_name => 'human' +); +is $species->binomial, 'Homo sapiens'; +is $species->genus, 'Homo'; + From 647b4f4be7f374b99d408081b59f065ac55e9786 Mon Sep 17 00:00:00 2001 From: Syed Hussain Ather Date: Sun, 1 Jun 2025 13:36:05 -0400 Subject: [PATCH 4/5] Split Bio::Species memory and taxonomy DB tests into separate scripts --- t/Species/memory.t | 57 +++++++++++++++++++++++++++++++++++++++++ t/Species/taxonomy_db.t | 25 ++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 t/Species/memory.t create mode 100644 t/Species/taxonomy_db.t diff --git a/t/Species/memory.t b/t/Species/memory.t new file mode 100644 index 000000000..75f7fe0e4 --- /dev/null +++ b/t/Species/memory.t @@ -0,0 +1,57 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use Bio::Root::Test; +use Bio::Species; + +eval { require Test::Memory::Cycle; 1; }; +my $CYCLE = $@ ? 0 : 1; +eval { require Test::Weaken; 1; }; +my $WEAKEN = $@ ? 0 : 1; + +test_begin(-tests => 6); + +SKIP: { + skip("Test::Memory::Cycle not installed", 3) if !$CYCLE; + + # Intentional circular ref (should leak) + my ($a, $b); $a = \$b; $b = \$a; + ok(Test::Memory::Cycle::memory_cycle_exists($a), "Intentional circular reference leaks"); + + # Bio::Species should not leak + my $species = Bio::Species->new( + -classification => [qw(sapiens Homo)], + -common_name => 'human' + ); + ok(!Test::Memory::Cycle::memory_cycle_exists($species), "Bio::Species does not leak"); + + # GitHub issue #81 regression + ok(!Test::Memory::Cycle::memory_cycle_exists(Bio::Species->new(-classification => ['A'])), "Regression test for #81"); +} + +SKIP: { + skip("Test::Weaken not installed", 3) if !$WEAKEN; + + # Deliberate leak + ok(Test::Weaken::leaks({ + constructor => sub { my ($a, $b); $a = \$b; $b = \$a; } + }), "Deliberate circular ref detected by Test::Weaken"); + + # Bio::Species should not leak + ok(!Test::Weaken::leaks({ + constructor => sub { + Bio::Species->new( + -classification => [qw(sapiens Homo)], + -common_name => 'human' + ) + } + }), "Bio::Species passes Test::Weaken"); + + # Regression test for #81 + ok(!Test::Weaken::leaks({ + constructor => sub { Bio::Species->new(-classification => ['A']) } + }), "Regression check for #81 via Test::Weaken"); +} + diff --git a/t/Species/taxonomy_db.t b/t/Species/taxonomy_db.t new file mode 100644 index 000000000..e0e5eddd3 --- /dev/null +++ b/t/Species/taxonomy_db.t @@ -0,0 +1,25 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use Bio::Root::Test; +use Bio::Species; +use Bio::DB::Taxonomy; + +test_begin(-tests => 5, + -requires_module => 'Bio::DB::Taxonomy::entrez', + -requires_networking => 1); + +my $species = Bio::Species->new(-id => 51351); +my $taxdb = Bio::DB::Taxonomy->new(-source => 'entrez'); + +eval { $species->db_handle($taxdb); }; +skip("Unable to connect to Entrez database; no network or server busy?", 5) if $@; + +is $species->binomial, 'Brassica rapa subsp.'; +is $species->binomial('FULL'), 'Brassica rapa subsp. pekinensis'; +is $species->genus, 'Brassica'; +is $species->species, 'rapa subsp.'; +is $species->sub_species, 'pekinensis'; + From bd04ce84c9791cf60419af2abb8c8f30cbda94ca Mon Sep 17 00:00:00 2001 From: Chris Fields Date: Wed, 3 Sep 2025 09:54:33 -0500 Subject: [PATCH 5/5] Update t/Species/basic.t Please update to include recommended Copilot change Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- t/Species/basic.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/Species/basic.t b/t/Species/basic.t index 03a4da20c..b1ba014da 100644 --- a/t/Species/basic.t +++ b/t/Species/basic.t @@ -6,7 +6,7 @@ use Test::More tests => 8; use_ok('Bio::Species'); my $sps = Bio::Species->new(); -$sps->classification(qw(sapiens Homo Hominidae Catarrhini Primates Eutheria Mammalia Vertebrata Chordata Metazoa Eukaryota)); +$sps->classification([qw(sapiens Homo Hominidae Catarrhini Primates Eutheria Mammalia Vertebrata Chordata Metazoa Eukaryota)]); is $sps->binomial, 'Homo sapiens';