/[webpac2]/trunk/t/6-unit.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/t/6-unit.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 481 by dpavlin, Sun May 14 00:50:35 2006 UTC revision 1100 by dpavlin, Sat Aug 2 23:46:41 2008 UTC
# Line 2  Line 2 
2    
3  use strict;  use strict;
4    
5  use Test::More tests => 66;  use Test::More tests => 31;
6  use Test::Exception;  use Test::Exception;
7  use Cwd qw/abs_path/;  use Cwd qw/abs_path/;
8  use File::Temp qw/tempdir/;  use File::Temp qw/tempdir/;
9  use File::Slurp;  use File::Slurp;
10  use Data::Dumper;  use Data::Dump qw/dump/;
11    use Time::HiRes qw/time/;
12  use blib;  use blib;
13    
14  my $debug = shift @ARGV;  my $debug = shift @ARGV;
15    
16    #
17    # FIXME add lookup testing!
18    #
19    
20  BEGIN {  BEGIN {
 use_ok( 'WebPAC::Lookup' );  
21  use_ok( 'WebPAC::Input' );  use_ok( 'WebPAC::Input' );
22  use_ok( 'WebPAC::Store' );  use_ok( 'WebPAC::Store' );
23  use_ok( 'WebPAC::Normalize::XML' );  use_ok( 'WebPAC::Normalize' );
 use_ok( 'WebPAC::Normalize::Set' );  
24  use_ok( 'WebPAC::Output::TT' );  use_ok( 'WebPAC::Output::TT' );
25  }  }
26    
# Line 27  diag "abs_path: $abs_path" if ($debug); Line 30  diag "abs_path: $abs_path" if ($debug);
30    
31  my $isis_file = "$abs_path../t/winisis/BIBL";  my $isis_file = "$abs_path../t/winisis/BIBL";
32  #$isis_file = '/data/hidra/THS/THS';  #$isis_file = '/data/hidra/THS/THS';
33  $isis_file = '/data/isis_data/ffkk/';  #$isis_file = '/data/isis_data/ffkk/';
34    
35  diag "isis_file: $isis_file" if ($debug);  diag "isis_file: $isis_file" if ($debug);
36    
37  my $normalize_set_pl = "$abs_path/data/normalize.pl";  my $normalize_set_pl = "$abs_path/data/normalize.pl";
38  my $lookup_file = "$abs_path../conf/lookup/isis.pm";  my $lookup_file = "$abs_path../conf/lookup/isis.pm";
39    
 ok(my $lookup = new WebPAC::Lookup(  
         lookup_file => $lookup_file,  
 ), "new Lookup");  
   
40  ok(my $isis = new WebPAC::Input(  ok(my $isis = new WebPAC::Input(
41          module => 'WebPAC::Input::ISIS',          module => 'WebPAC::Input::ISIS',
42          code_page => 'ISO-8859-2',      # application encoding          limit => 100,
43          limit => 10,          no_progress_bar => 1,
44  ), "new Input::ISIS");  ), "new Input::ISIS");
45    
46  ok(my $maxmfn = $isis->open(  ok(my $maxmfn = $isis->open(
47          path => $isis_file,          path => $isis_file,
48          code_page => '852',             # database encoding          input_encoding => 'cp852',              # database encoding
49          lookup => $lookup,          lookup_coderef => sub {
50                    my $rec = shift || return;
51                    ok($rec, 'lookup_coderef has rec');
52                    ok(defined($rec->{'000'}->[0]), 'have mfn');
53            },
54  ), "Input::ISIS->open");  ), "Input::ISIS->open");
55    
56  ok(my $path = tempdir( CLEANUP => 1 ), "path");  ok(my $path = tempdir( CLEANUP => 1 ), "path");
57    
58  ok(my $db = new WebPAC::Store(  ok(my $db = new WebPAC::Store({
         path => $path,  
59          database => '.',          database => '.',
60  ), "new Store");  }), "new Store");
   
 ok(my $n = new WebPAC::Normalize::XML(  
 #       filter => { 'foo' => sub { shift } },  
         db => $db,  
         lookup_regex => $lookup->regex,  
         lookup => $lookup,  
 ), "new Normalize::XML");  
   
 ok($n->open(  
         tag => 'isis',  
         xml_file => "$abs_path/data/normalize.xml",  
 ), "Normalize::XML->open");  
61    
62  ok(my $norm_pl = read_file( $normalize_set_pl ), "set definitions: $normalize_set_pl" );  ok(my $norm_pl = read_file( $normalize_set_pl ), "set definitions: $normalize_set_pl" );
63    
# Line 76  ok(my $out = new WebPAC::Output::TT( Line 66  ok(my $out = new WebPAC::Output::TT(
66          filters => { foo => sub { shift } },          filters => { foo => sub { shift } },
67  ), "new Output::TT");  ), "new Output::TT");
68    
69  diag " lookup => ",Dumper($lookup->lookup_hash) if ($debug);  my $t_norm = 0;
70    
71  while (my $row = $isis->fetch) {  foreach my $pos ( 0 ... $isis->size ) {
72    
73          diag " row => ",Dumper($row) if ($debug);          my $row = $isis->fetch || next;
         set_rec( $row );  
74    
75          ok(my $ds = $n->data_structure($row), "data_structure");          diag " row $pos => ",dump($row) if ($debug);
76    
77          diag " ds => ",Dumper($ds) if ($debug);          my $t = time();
78            ok( my $ds = WebPAC::Normalize::data_structure(
79          # TODO move somewhere                  row => $row,
80          {                  rules => $norm_pl,
81                  no strict 'subs';          ), "Set data_structure");
82                  use WebPAC::Normalize::Set;          $t_norm += time() - $t;
                 set_lookup( $lookup->lookup_hash );  
                 clean_ds();  
                 eval "$norm_pl";  
                 ok(! $@, $@ ? "error: $@" : "no error");  
                 ok(my $ds2 = get_ds(), "get_ds");  
                 is_deeply( $ds, $ds2, 'ds same for xml and sets');  
83    
84                  diag " ds2 => ",Dumper($ds2) if ($debug);          diag " ds $pos => ",dump($ds) if ($debug);
         }  
85    
86          ok(my $html = $out->apply(          ok(my $html = $out->apply(
87                  template => 'html.tt',                  template => 'html.tt',
# Line 111  while (my $row = $isis->fetch) { Line 93  while (my $row = $isis->fetch) {
93          #diag $html;          #diag $html;
94    
95  };  };
96    
97    diag sprintf("timings: %.2fs\n", $t_norm);

Legend:
Removed from v.481  
changed lines
  Added in v.1100

  ViewVC Help
Powered by ViewVC 1.1.26