Skip to content

Commit 5c07b2c

Browse files
committed
update all tests to use modern Test2 suite
lots of changes, but mostly syntax and style, nothing substantial
1 parent ae8d137 commit 5c07b2c

18 files changed

+674
-644
lines changed

Build.PL

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ sub get_base_options {
3838
'Module::Build' => 0.42,
3939
},
4040
test_requires => {
41-
'Test::More' => 1.302,
42-
'Test::Warn' => 0.36,
41+
'Test2::V0' => 1.302,
4342
'Test::Script' => 1.29,
4443
},
4544
meta_merge => {

t/00.utility.t

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
1-
#!/usr/bin/perl -w
1+
#!/usr/bin/env perl
22

33
# Test script for Bio::ToolBox::utility
44

5-
use strict;
6-
use Test::More;
5+
use Test2::V0 -no_srand => 1;
6+
plan(18);
77

8-
BEGIN {
9-
plan tests => 19;
10-
}
11-
12-
use_ok(
13-
'Bio::ToolBox::utility', qw(
14-
parse_list
15-
format_with_commas
16-
ask_user_for_index
17-
simplify_dataset_name
18-
sane_chromo_sort
19-
)
20-
) or BAIL_OUT "Cannot load Bio::ToolBox::utility";
8+
use Bio::ToolBox::utility qw(
9+
parse_list
10+
format_with_commas
11+
ask_user_for_index
12+
simplify_dataset_name
13+
sane_chromo_sort
14+
);
2115

2216
### parse list
2317
my $in = '1-10';
2418
my @expect = ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 );
2519
my @got = parse_list($in);
26-
is_deeply( \@got, \@expect, "Parse list $in" );
20+
is( \@got, \@expect, "Parse list $in" );
2721

2822
$in = '1,2,6,8-10';
2923
@expect = ( 1, 2, 6, 8, 9, 10 );
3024
@got = parse_list($in);
31-
is_deeply( \@got, \@expect, "Parse list $in" );
25+
is( \@got, \@expect, "Parse list $in" );
3226

3327
### format_with_commas
3428
$in = 1234567890;
@@ -108,16 +102,16 @@ is( $got, $expect, "Simplify dataset name $in" );
108102
my @list = qw(chr1 chr10 chr11 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 MT);
109103
my @expect_l = qw(chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 MT);
110104
my @got_l = sane_chromo_sort(@list);
111-
is_deeply( \@got_l, \@expect_l, 'Sanely sort chromosome list 1' );
105+
is( \@got_l, \@expect_l, 'Sanely sort chromosome list 1' );
112106

113107
@list = qw(1 10 chr11 chr2 chr3 chr4 5 chr6 chr7 chr8 chr9 contig.124 contig.14 Y X mito);
114108
@expect_l =
115109
qw(1 chr2 chr3 chr4 5 chr6 chr7 chr8 chr9 10 chr11 X Y mito contig.14 contig.124);
116110
@got_l = sane_chromo_sort(@list);
117-
is_deeply( \@got_l, \@expect_l, 'Sanely sort chromosome list 2' );
111+
is( \@got_l, \@expect_l, 'Sanely sort chromosome list 2' );
118112

119113
@list = qw(2-micron scaffold-1 M scaffold-10 scaffold-3 I III IX VIII IV XII X Y );
120114
@expect_l = qw(I III IV VIII IX X XII Y M scaffold-1 scaffold-3 scaffold-10 2-micron);
121115
@got_l = sane_chromo_sort(@list);
122-
is_deeply( \@got_l, \@expect_l, 'Sanely sort chromosome list 3' );
116+
is( \@got_l, \@expect_l, 'Sanely sort chromosome list 3' );
123117

t/01.Data.t

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
1-
#!/usr/bin/perl -w
1+
#!/usr/bin/env perl
22

33
# Test script for Bio::ToolBox::Data and Bio::ToolBox::Data::Stream
44

5-
use strict;
6-
use Test::More;
7-
use Test::Warn;
5+
use Test2::V0 -no_srand => 1;
6+
plan(255);
87
use File::Spec;
98
use FindBin '$Bin';
109

1110
BEGIN {
12-
plan tests => 261;
1311
## no critic
1412
$ENV{'BIOTOOLBOX'} = File::Spec->catfile( $Bin, "Data", "biotoolbox.cfg" );
1513
## use critic
1614
}
1715

18-
require_ok 'Bio::ToolBox::Data'
19-
or BAIL_OUT "Cannot load Bio::ToolBox::Data";
20-
require_ok 'Bio::ToolBox::Data::Stream'
21-
or BAIL_OUT "Cannot load Bio::ToolBox::Data::Stream";
16+
require Bio::ToolBox::Data;
17+
require Bio::ToolBox::Data::Stream;
2218

2319
### Open a test file
2420
my $infile = File::Spec->catfile( $Bin, "Data", "chrI.gff3" );
2521
my $Data = Bio::ToolBox::Data->new( file => $infile, );
26-
isa_ok( $Data, 'Bio::ToolBox::Data', 'GFF3 Data' );
22+
isa_ok( $Data, ['Bio::ToolBox::Data'], 'got a GFF3 Data object' );
2723

2824
# test general metadata
2925
is( $Data->gff, 3, 'gff version' );
@@ -96,10 +92,15 @@ is( $Data->name(7), 'Strand', 'name of column 7 again' );
9692
# column metadata
9793
is( $Data->metadata( 1, 'name' ), 'Chromosome', 'column name via metadata value' );
9894
$Data->metadata( 2, 'accuracy', 'bogus' );
99-
my $md = $Data->metadata(2);
95+
my $md = $Data->metadata(2);
96+
my $expected = {
97+
'index' => 2,
98+
'name' => 'Source',
99+
'AUTO' => 3,
100+
'accuracy' => 'bogus'
101+
};
100102
ok( $md, 'metadata success' );
101-
isa_ok( $md, 'HASH', 'metadata is a hash' );
102-
is( $md->{'accuracy'}, 'bogus', 'set metadata value is correct' );
103+
is( $md, $expected, 'metadata hash matches expected' );
103104

104105
# column values
105106
my $cv = $Data->column_values(4);
@@ -109,7 +110,7 @@ is( $cv->[1], 1, 'check specific column value' );
109110

110111
# test duplicate
111112
my $Dupe = $Data->duplicate;
112-
isa_ok( $Dupe, 'Bio::ToolBox::Data', 'Duplicated object' );
113+
isa_ok( $Dupe, ['Bio::ToolBox::Data'], 'Duplicated object' );
113114
is( $Dupe->gff, 3, 'Dupe gff version' );
114115
is( $Dupe->program, undef, 'Dupe program name' );
115116
is( $Dupe->feature, 'region', 'Dupe general feature' );
@@ -121,11 +122,11 @@ is( $Dupe->last_row, 0, 'Dupe last row index' );
121122

122123
# test row_stream
123124
my $stream = $Data->row_stream;
124-
isa_ok( $stream, 'Bio::ToolBox::Data::Iterator', 'Iterator object' );
125+
isa_ok( $stream, ['Bio::ToolBox::Data::Iterator'], 'Got an Iterator object' );
125126

126127
# first row feature
127128
my $row = $stream->next_row;
128-
isa_ok( $row, 'Bio::ToolBox::Data::Feature', 'Feature object' );
129+
isa_ok( $row, ['Bio::ToolBox::Data::Feature'], 'Got a Feature object' );
129130
is( $row->value(1), 'chrI', 'row object value of index 1' );
130131
is( $row->seq_id, 'chrI', 'row object chromosome value' );
131132
is( $row->start, 1, 'row object start value' );
@@ -146,8 +147,12 @@ is( $row->end, 62, 'row object end value' );
146147

147148
# check gff attribute
148149
my $gff_att = $row->gff_attributes;
149-
isa_ok( $gff_att, 'HASH', 'row GFF attributes hash' );
150-
is( $gff_att->{Name}, 'TEL01L-TR', 'row GFF attribute Name' );
150+
$expected = {
151+
'Note' => 'Terminal stretch of telomeric repeats on the left arm of Chromosome I',
152+
'Name' => 'TEL01L-TR',
153+
'ID' => 'TEL01L-TR'
154+
};
155+
is( $gff_att, $expected, 'row GFF attributes hash' );
151156
$gff_att->{Note} = 'I hereby claim this telomeric repeat to be mine';
152157
is( $row->rewrite_gff_attributes, 1, 'rewrite row GFF attributes' );
153158
is(
@@ -201,10 +206,13 @@ is( $Data->metadata( 10, 'name' ), 'Name', 'Name of new column' );
201206
# change and copy metadata
202207
$Data->name( 10, 'DuplicateName' );
203208
$Data->copy_metadata( 2, 10 );
204-
$md = $Data->metadata(10);
205-
is( $md->{name}, 'DuplicateName', 'metadata of changed column name' );
206-
is( $md->{accuracy}, 'bogus', 'metadata of copied column' );
207-
is( $md->{'index'}, 10, 'metadata of copied column' );
209+
$md = $Data->metadata(10);
210+
$expected = {
211+
'name' => 'DuplicateName',
212+
'index' => 10,
213+
'accuracy' => 'bogus'
214+
};
215+
is( $md, $expected, 'copied metadata is expected' );
208216

209217
# sort table
210218
$Data->sort_data( 9, 'd' );
@@ -264,7 +272,7 @@ undef $Data;
264272
$Data = Bio::ToolBox::Data->new( file => $file );
265273

266274
# metadata tests
267-
isa_ok( $Data, 'Bio::ToolBox::Data', 'Bed Data' );
275+
isa_ok( $Data, ['Bio::ToolBox::Data'], 'Got a bed Data object' );
268276
is( $Data->gff, 0, 'gff version' );
269277
is( $Data->bed, 4, 'bed version' );
270278
is( $Data->format, 'bed4', 'bed format' );
@@ -289,7 +297,7 @@ is( $Data->headers, 0, 'includes headers' );
289297
# stream tests and row feature
290298
$stream = $Data->row_stream;
291299
$row = $stream->next_row;
292-
isa_ok( $row, 'Bio::ToolBox::Data::Feature', 'Feature object' );
300+
isa_ok( $row, ['Bio::ToolBox::Data::Feature'], 'got a Feature object' );
293301
is( $row->value(1), 'chrI', 'row object value of chromo index' );
294302
is( $row->start, 35155, 'row object start value' );
295303
is( $row->end, 36303, 'row object end value' );
@@ -299,7 +307,7 @@ is( $row->coordinate, 'chrI:35155-36303', 'row object coordinate string' );
299307

300308
# grab row feature directly and change attributes using high API functions - v1.68
301309
$row = $Data->get_row(25);
302-
isa_ok( $row, 'Bio::ToolBox::Data::Feature', 'Direct Feature object' );
310+
isa_ok( $row, ['Bio::ToolBox::Data::Feature'], 'Got a direct Feature object' );
303311
is( $row->value(1), 'chrI', 'Feature chromosome actual value' );
304312
is( $row->seq_id, 'chrI', 'Feature chromosome' );
305313
is( $row->seq_id('chrX'), 'chrX', 'Change chromosome via high level' );
@@ -326,18 +334,19 @@ is( $Data->value( 25, 4 ), 'bob', 'Feature name actual value' );
326334

327335
is( $row->value(5), '.', 'Feature actual strand value (nonexistent)' );
328336
is( $row->strand, 0, 'Feature strand (implied)' );
329-
warning_is(
330-
sub { $row->strand(1) },
331-
'ERROR: No Strand column to update!',
337+
338+
like(
339+
warning { $row->strand(1) },
340+
qr/^ ERROR:\ No\ Strand\ column\ to\ update!/x,
332341
'Attempt strand change via high level'
333342
);
334343
is( $row->strand, 0, 'Check attempted strand change' );
335344
is( $Data->value( 25, 5 ), undef, 'Feature actual changed strand value' );
336-
337345
is( $row->type, 'region', 'Feature type (implied)' );
338-
warning_is(
339-
sub { $row->type('gene') },
340-
'ERROR: No Type column to update!',
346+
347+
like(
348+
warning { $row->type('gene') },
349+
qr/^ ERROR:\ No\ Type\ column\ to\ update!/x,
341350
'Attempt type change via high level'
342351
);
343352
isnt( $row->type, 'gene', 'Check attempted type change' );
@@ -365,7 +374,7 @@ undef $Data;
365374

366375
# open the bed file we just wrote
367376
my $Stream = Bio::ToolBox::Data::Stream->new( in => $file, );
368-
isa_ok( $Stream, 'Bio::ToolBox::Data::Stream', 'Stream Bed object' );
377+
isa_ok( $Stream, ['Bio::ToolBox::Data::Stream'], 'Got a Stream object' );
369378
is( $Stream->bed, 4, 'bed value' );
370379
is( $Stream->gff, 0, 'gff value' );
371380
is( $Stream->feature, 'region', 'feature' );
@@ -386,7 +395,7 @@ is( $Stream->name(3), 'End', 'name of column again' );
386395

387396
# iterate
388397
my $f = $Stream->next_row;
389-
isa_ok( $f, 'Bio::ToolBox::Data::Feature', 'next row Feature object' );
398+
isa_ok( $f, ['Bio::ToolBox::Data::Feature'], 'got the next row Feature object' );
390399

391400
# check feature
392401
is( $f->seq_id, 'chrI', 'feature seq_id' );
@@ -405,13 +414,14 @@ $Stream = Bio::ToolBox::Data->new(
405414
stream => 1,
406415
in => $file,
407416
);
408-
isa_ok( $Stream, 'Bio::ToolBox::Data::Stream', 'Stream object' );
417+
isa_ok( $Stream, ['Bio::ToolBox::Data::Stream'],
418+
'got another Stream object differently' );
409419

410420
# create output file
411421
my $file1 = $file;
412422
$file1 =~ s/\.bed$/_2.bed/;
413423
my $outStream = $Stream->duplicate($file1);
414-
isa_ok( $outStream, 'Bio::ToolBox::Data::Stream', 'duplicated Stream object' );
424+
isa_ok( $outStream, ['Bio::ToolBox::Data::Stream'], 'got a duplicated Stream object' );
415425
is( $Stream->basename, 'chrI', 'in Stream basename' );
416426
is( $outStream->basename, 'chrI_2', 'out Stream basename' );
417427

@@ -445,7 +455,7 @@ cmp_ok( -s $file2, '<', -s $file, "smaller file size due to lack of comments" );
445455
# reload the duplicate files
446456
# this should effectively delete the child files
447457
$Data = Bio::ToolBox::Data->new();
448-
isa_ok( $Data, 'Bio::ToolBox::Data', 'new empty Data object' );
458+
isa_ok( $Data, ['Bio::ToolBox::Data'], 'got a shiny new empty Data object' );
449459
is( $Data->number_columns, 0, 'number of columns' );
450460
is( $Data->last_row, 0, 'last row index' );
451461

@@ -460,7 +470,7 @@ undef $Data;
460470
undef $row;
461471
$infile = File::Spec->catfile( $Bin, "Data", "H3K4me3.narrowPeak" );
462472
$Data = Bio::ToolBox::Data->new( file => $infile, );
463-
isa_ok( $Data, 'Bio::ToolBox::Data', 'narrowPeak Data' );
473+
isa_ok( $Data, ['Bio::ToolBox::Data'], 'got a narrowPeak Data object' );
464474

465475
# test general metadata
466476
is( $Data->gff, 0, 'gff version' );
@@ -476,15 +486,15 @@ is( $Data->find_column('pValue'), 8, 'find column pValue' );
476486
is( $Data->find_column('peak'), 10, 'find column peak' );
477487
is( $Data->headers, 0, 'include_headers' );
478488
$row = $Data->get_row(1);
479-
isa_ok( $row, 'Bio::ToolBox::Data::Feature', 'first peak interval Feature object' );
489+
isa_ok( $row, ['Bio::ToolBox::Data::Feature'], 'got first peak interval Feature object' );
480490
is( $row->peak, 11908866, 'peak interval peak coordinate' );
481491
is( $row->midpoint, 11909060, 'peak interval midpoint' );
482492

483493
### Open a gappedPeak test file
484494
undef $Data;
485495
$infile = File::Spec->catfile( $Bin, "Data", "H3K27ac.bed" );
486496
$Data = Bio::ToolBox::Data->new( file => $infile, );
487-
isa_ok( $Data, 'Bio::ToolBox::Data', 'gappedPeak bed Data' );
497+
isa_ok( $Data, ['Bio::ToolBox::Data'], 'got a gappedPeak bed Data object' );
488498

489499
# test general metadata
490500
is( $Data->gff, 0, 'gff version' );
@@ -506,7 +516,7 @@ undef $row;
506516
$infile = File::Spec->catfile( $Bin, "Data", "H3K4me3.narrowPeak" );
507517
$Stream = Bio::ToolBox::Data::Stream->new( in => $infile );
508518
$Data = $Stream->duplicate;
509-
isa_ok( $Data, 'Bio::ToolBox::Data', 'duplicate Stream object to Data object' );
519+
isa_ok( $Data, ['Bio::ToolBox::Data'], 'got a duplicate Stream object to Data object' );
510520
is( $Data->number_columns, 10, 'number columns' );
511521
is( $Data->bed, 10, 'bed value' );
512522
is( $Data->feature, 'region', 'feature' );
@@ -527,7 +537,7 @@ undef $Data;
527537

528538
# reopen and check
529539
my $fh = Bio::ToolBox::Data->open_to_read_fh('test.txt');
530-
isa_ok( $fh, 'IO::File', 'opened filehandle' );
540+
isa_ok( $fh, ['IO::File'], 'got an opened filehandle object' );
531541
is( $fh->getline, "# example Me3 narrowPeak\n", 'first line' );
532542
my @headers = split( /\t/, $fh->getline );
533543
is( scalar(@headers), 10, 'number of header items' );
@@ -541,9 +551,9 @@ unlink('test.txt');
541551
undef $Data;
542552
$infile = File::Spec->catfile( $Bin, 'Data', 'sample.bed' );
543553
$Data = Bio::ToolBox::Data->new( in => $infile );
544-
isa_ok( $Data, 'Bio::ToolBox::Data', 'new sample bed file object' );
554+
isa_ok( $Data, ['Bio::ToolBox::Data'], 'got a new sample bed Data object' );
545555
my $Data1 = Bio::ToolBox::Data->new( columns => [qw(Coordinate Name)] );
546-
isa_ok( $Data1, 'Bio::ToolBox::Data', 'new empty Data object with columns' );
556+
isa_ok( $Data1, ['Bio::ToolBox::Data'], 'got a new empty Data object with columns' );
547557
$iterate_success = $Data->iterate(
548558
sub {
549559
my $r = shift;
@@ -555,7 +565,7 @@ is( $Data1->number_rows, $Data->number_rows, 'number of new rows' );
555565

556566
# check extraction of coordinates from string, start is transformed
557567
$row = $Data1->get_row(1);
558-
isa_ok( $row, 'Bio::ToolBox::Data::Feature', 'first feature' );
568+
isa_ok( $row, ['Bio::ToolBox::Data::Feature'], 'got the first Feature object' );
559569
is( $row->seq_id, 'chrI', 'extracted seq_id from coordinate string' );
560570
is( $row->start, 54989, 'extracted start from coordinate string' );
561571
is( $row->end, 56857, 'extracted end from coordinate string' );

0 commit comments

Comments
 (0)