Bio-BLAST

 view release on metacpan or  search on metacpan

t/basic.t  view on Meta::CPAN

use strict;
use warnings;
use English;
use FindBin;

use Bio::SeqIO;

use File::Spec::Functions;
use File::Temp qw/ tempdir tempfile /;

use Fatal qw/ open mkdir chmod /;

use Test::More;
use Test::Exception;

use IPC::Cmd qw/ can_run /;

BEGIN {
    if( can_run('fastacmd') ) {
        plan tests => 302;
    }

t/basic.t  view on Meta::CPAN

    is( $one->seq, $two->seq, $one->id.' seq OK');
    is( $one->description, $two->description, $one->id.' desc OK');
}

# test check_format_permissions
my $permdir = catdir( $tempdir, 'permdir' );
mkdir $permdir;
my $fs3 = Bio::BLAST::Database->open( full_file_basename => catfile( $permdir, 'foo'), type => 'nucleotide', write => 1);
ok(! $fs3->check_format_permissions, 'check_format_permissions OK for ffbn in new dir' );
ok( ! $fs3->is_split, 'returns false for is_split');
chmod 0444,$permdir;
my $perr = $fs3->check_format_permissions;
ok($perr, 'check_format_permissions returns bad for ffbn in non-writable' );
like( $perr, qr/directory/i, 'permissions error mentions directory');
throws_ok {
    Bio::BLAST::Database->open( full_file_basename => catfile( $permdir, 'foo' ),
                                  type => 'nucleotide',
                                  write => 1,
                                 );
} qr/writable/, 'new() should die if ffbn is not writable';
chmod 0744,$permdir;
ok(! $fs3->check_format_permissions, 'check_format_permissions OK again' );

my $test_seq_file = catfile( $DATADIR, "blastdb_test.nucleotide.seq" );
$fs3->format_from_file( seqfile => $test_seq_file );
my @newfiles = $fs3->list_files;
is( scalar @newfiles, 3, 'format succeeded in new dir' );
ok(! $fs3->check_format_permissions, 'check_format_permissions still OK after new format' );
foreach my $f (@newfiles) {
    chmod 0444,$f;
    my $perr2 = $fs3->check_format_permissions;
    like( $perr2, qr/$f/, 'perm error mentions file');
}
chmod 0744, $_ for @newfiles;
ok(! $fs3->check_format_permissions, 'and then it comes back OK after all are writable again' );

# now test formatting it yet again
$fs3->format_from_file( seqfile => $test_seq_file );
is( scalar @newfiles, 3, 'format succeeded again' );
ok(! $fs3->check_format_permissions, 'permissions OK' );

#test downloading and formatting NR
SKIP: {
  my $big_file = $ENV{BIO_BLAST_DATABASE_TEST_BIG_FORMAT}



( run in 0.639 second using v1.01-cache-2.11-cpan-496ff517765 )