File: Storable.t

package info (click to toggle)
bioperl 1.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 40,768 kB
  • ctags: 12,005
  • sloc: perl: 174,299; xml: 13,923; sh: 1,941; lisp: 1,803; asm: 109; makefile: 53
file content (79 lines) | stat: -rw-r--r-- 2,338 bytes parent folder | download
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
# -*-Perl-*- Test Harness script for Bioperl
# $Id: Storable.t 15112 2008-12-08 18:12:38Z sendu $

use strict;

BEGIN {
    use lib '.';
    use Bio::Root::Test;
    
    test_begin(-tests => 35);
	
    use_ok('Bio::Root::Storable');
}

foreach my $mode( "BINARY", "ASCII" ){
    if( $mode eq "ASCII" ){
		no warnings;
        $Bio::Root::Storable::BINARY = 0;
    }

    #------------------------------
    # Test the easy bits that don't need file IO
    my $obj = Bio::Root::Storable->new();
    ok defined($obj) && $obj->isa('Bio::Root::Storable');

    eval { $obj->throw('Testing throw') };
    ok $@ =~ /Testing throw/;   # 'throw failed';

    $obj->{_test}  = "_TEST";   # Provide test attributes
    $obj->{__test} = "__TEST";  # 

    my $state = $obj->serialise;
    ok length($state) > 0;

    my $clone = $obj->clone;
    ok defined($clone) and $clone->isa('Bio::Root::Storable');
    ok $clone->{_test} eq "_TEST" && $clone->{__test}  eq "__TEST";

    #------------------------------
    # Test standard file IO 
    my $file = $obj->store;
    ok $file && -f $obj->statefile;

    my $retrieved;
    eval { $retrieved = Bio::Root::Storable->retrieve( $file ) };
    ok defined($retrieved) && $retrieved->isa('Bio::Root::Storable');
    ok $retrieved->{_test} eq "_TEST" && ! exists $retrieved->{__test};

    my $skel = $obj->new_retrievable;
    ok defined($skel) && $skel->isa('Bio::Root::Storable');
    ok ! exists $skel->{_test} && ! exists $skel->{__test};
    ok $skel->retrievable;

    eval { $skel->retrieve };
    ok ! $skel->retrievable;
    ok $skel->{_test} eq "_TEST" && ! exists $skel->{__test};

    my $obj2 = Bio::Root::Storable->new();
    $obj2->template('TEST_XXXXXX');
    $obj2->suffix('.state');
    my $file2 = $obj2->store;
    ok $file2 =~ /TEST_\w{6}?\.state$/ and -f $file2;

    #------------------------------
    # Test recursive file IO
    $obj->{_test_lazy} = $obj2;
    $obj->store;
    my $retrieved2;
    eval { $retrieved2 = Bio::Root::Storable->retrieve( $obj->token ) };
    ok $retrieved2->{_test_lazy} && $retrieved2->{_test_lazy}->retrievable;

    #------------------------------
    # Clean up
    # Should only be 2 object files; all others were clones in one way or another
    $obj->remove;
    ok ! -f $obj->statefile;
    $obj2->remove;
    ok ! -f $obj2->statefile;
}