/usr/share/perl5/Bio/Chado/Schema/Test.pm is in libbio-chado-schema-perl 0.20000-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | package Bio::Chado::Schema::Test;
BEGIN {
$Bio::Chado::Schema::Test::AUTHORITY = 'cpan:RBUELS';
}
{
$Bio::Chado::Schema::Test::VERSION = '0.20000';
}
use strict;
use warnings;
use Carp::Clan qr/^Bio::Chado::Schema/;
use Bio::Chado::Schema;
=head1 NAME
Bio::Chado::Schema::Test - Library to be used by Bio::Chado::Schema test scripts.
=head1 SYNOPSIS
use lib qw(t/lib);
use Bio::Chado::Schema::Test;
use Test::More;
my $schema = Bio::Chado::Schema::Test->init_schema();
=head1 DESCRIPTION
This module provides the basic utilities to write tests against Bio::Chado::Schema.
=head1 METHODS
=head2 init_schema
my $schema = Bio::Chado::Schema::Test->init_schema(
deploy => 1,
populate => 1,
storage_type => '::DBI::Replicated',
storage_type_args => {
balancer_type=>'DBIx::Class::Storage::DBI::Replicated::Balancer::Random'
},
);
This method removes the test SQLite database in t/var/BCS.db
and then creates a new, empty database.
This method will call deploy_schema() by default, unless the
deploy flag is set to 0.
This method will call populate_schema() if the populate argument
is set to a true value.
=cut
=head2 has_custom_dsn
Returns true if the BCS_TEST_DSN environment variable is set.
=cut
sub has_custom_dsn {
return $ENV{"BCS_TEST_DSN"} ? 1 : 0;
}
sub _sqlite_dbfilename {
return "t/var/BCS.db";
}
sub _sqlite_dbname {
my $self = shift;
my %args = @_;
return $self->_sqlite_dbfilename; # if $args{sqlite_use_file} or $ENV{"BCS_SQLITE_USE_FILE"};
return ":memory:";
}
sub _database {
my $self = shift;
my %args = @_;
my $db_file = $self->_sqlite_dbname(%args);
#warn "Removing $db_file";
#unlink($db_file) if -e $db_file;
#unlink($db_file . "-journal") if -e $db_file . "-journal";
mkdir("t/var") unless -d "t/var";
my $dsn = $ENV{"BCS_TEST_DSN"} || "dbi:SQLite:${db_file}";
my $dbuser = $ENV{"BCS_TEST_DBUSER"} || '';
my $dbpass = $ENV{"BCS_TEST_DBPASS"} || '';
my @connect_info = ($dsn, $dbuser, $dbpass, { AutoCommit => 1, %args });
return @connect_info;
}
sub init_schema {
my $self = shift;
my %args = @_;
my $should_deploy = $ENV{"BCS_TEST_DSN"} ? 0 : 1 ;
my $schema;
if ($args{compose_connection}) {
$schema = Bio::Chado::Schema->compose_connection(
'Bio::Chado::Schema::Test', $self->_database(%args)
);
} else {
$schema = Bio::Chado::Schema->compose_namespace('Bio::Chado::Schema::Test');
}
if ($args{storage_type}) {
$schema->storage_type($args{storage_type});
}
$schema = $schema->connect($self->_database(%args));
$schema->storage->on_connect_do(['PRAGMA synchronous = OFF']) unless $self->has_custom_dsn;
unless ( -e _sqlite_dbfilename() ) {
__PACKAGE__->deploy_schema( $schema, $args{deploy_args} ) if $should_deploy;
__PACKAGE__->populate_schema( $schema ) if $args{populate};
}
return $schema;
}
=head2 deploy_schema
Bio::Chado::Schema::Test->deploy_schema( $schema );
This method does one of two things to the schema. It can either call
the experimental $schema->deploy() if the BCSTEST_SQLT_DEPLOY environment
variable is set, otherwise the default is to read in the t/lib/sqlite.sql
file and execute the SQL within. Either way you end up with a fresh set
of tables for testing.
=cut
sub deploy_schema {
my $self = shift;
my $schema = shift;
my $args = shift || {};
$schema->deploy($args);
return;
}
=head2 populate_schema
Bio::Chado::Schema::Test->populate_schema( $schema );
After you deploy your schema you can use this method to populate
the tables with test data.
=cut
sub populate_schema {
my $self = shift;
my $schema = shift;
# $schema->populate('Genre', [
# [qw/genreid name/],
# [qw/1 emo/],
# ]);
}
1;
|