/[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 217 by dpavlin, Mon Dec 5 17:47:51 2005 UTC revision 536 by dpavlin, Mon Jun 26 16:39:51 2006 UTC
# Line 2  Line 2 
2    
3  use strict;  use strict;
4    
5  use Test::More tests => 34;  use Test::More tests => 24;
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;
10  use Data::Dumper;  use Data::Dumper;
11    use Time::HiRes qw/time/;
12  use blib;  use blib;
13    
14    my $debug = shift @ARGV;
15    
16  BEGIN {  BEGIN {
17  use_ok( 'WebPAC::Lookup' );  use_ok( 'WebPAC::Lookup' );
18  use_ok( 'WebPAC::Input::ISIS' );  use_ok( 'WebPAC::Input' );
19  use_ok( 'WebPAC::Store' );  use_ok( 'WebPAC::Store' );
20  use_ok( 'WebPAC::Normalize::XML' );  use_ok( 'WebPAC::Lookup::Normalize' );
21    use_ok( 'WebPAC::Normalize' );
22  use_ok( 'WebPAC::Output::TT' );  use_ok( 'WebPAC::Output::TT' );
23  }  }
24    
25  ok(my $abs_path = abs_path($0), "abs_path");  ok(my $abs_path = abs_path($0), "abs_path");
26  $abs_path =~ s#/[^/]*$#/#;  $abs_path =~ s#/[^/]*$#/#;
27  diag "abs_path: $abs_path";  diag "abs_path: $abs_path" if ($debug);
28    
29  my $isis_file = "$abs_path../t/winisis/BIBL";  my $isis_file = "$abs_path../t/winisis/BIBL";
30  $isis_file = '/data/hidra/THS/THS';  #$isis_file = '/data/hidra/THS/THS';
31    #$isis_file = '/data/isis_data/ffkk/';
32    
33    diag "isis_file: $isis_file" if ($debug);
34    
35  diag "isis_file: $isis_file";  my $normalize_set_pl = "$abs_path/data/normalize.pl";
36    my $lookup_file = "$abs_path../conf/lookup/isis.pm";
37    
38  ok(my $lookup = new WebPAC::Lookup(  ok(my $lookup = new WebPAC::Lookup(
39          lookup_file => "$abs_path../conf/lookup/isis.pm",          lookup_file => $lookup_file,
40  ), "new Lookup");  ), "new Lookup");
41    
42  ok(my $isis = new WebPAC::Input::ISIS(  ok(my $isis = new WebPAC::Input(
43            module => 'WebPAC::Input::ISIS',
44          code_page => 'ISO-8859-2',      # application encoding          code_page => 'ISO-8859-2',      # application encoding
45          limit_mfn => 10,          limit => 100,
46            no_progress_bar => 1,
47  ), "new Input::ISIS");  ), "new Input::ISIS");
48    
49  ok(my $maxmfn = $isis->open(  ok(my $maxmfn = $isis->open(
50          filename => $isis_file,          path => $isis_file,
51          code_page => '852',             # database encoding          code_page => '852',             # database encoding
52            lookup => $lookup,
53  ), "Input::ISIS->open");  ), "Input::ISIS->open");
54    
55  ok(my $path = tempdir( CLEANUP => 1 ), "path");  ok(my $path = tempdir( CLEANUP => 1 ), "path");
# Line 47  ok(my $db = new WebPAC::Store( Line 59  ok(my $db = new WebPAC::Store(
59          database => '.',          database => '.',
60  ), "new Store");  ), "new Store");
61    
62  ok(my $n = new WebPAC::Normalize::XML(  ok(my $norm_pl = read_file( $normalize_set_pl ), "set definitions: $normalize_set_pl" );
 #       filter => { 'foo' => sub { shift } },  
         db => $db,  
         lookup_regex => $lookup->regex,  
         lookup => $lookup,  
 ), "new Normalize::XML");  
   
 ok($n->open(  
         tag => 'isis',  
         xml_file => "$abs_path../conf/normalize/isis.xml",  
 ), "Normalize::XML->open");  
63    
64  ok(my $out = new WebPAC::Output::TT(  ok(my $out = new WebPAC::Output::TT(
65          include_path => "$abs_path../conf/output/tt",          include_path => "$abs_path../conf/output/tt",
66          filters => { foo => sub { shift } },          filters => { foo => sub { shift } },
67  ), "new Output::TT");  ), "new Output::TT");
68    
69  while (my $row = $isis->fetch) {  diag " lookup => ",Dumper($lookup->lookup_hash) if ($debug);
70            
71          ok(my $ds = $n->data_structure($row), "data_structure");  my $t_norm = 0;
72    
73  #       diag Dumper($ds);  foreach my $pos ( 0 ... $isis->size ) {
74    
75            my $row = $isis->fetch || next;
76    
77            diag " row $pos => ",Dumper($row) if ($debug);
78    
79            my $t = time();
80            ok( my $ds = WebPAC::Normalize::data_structure(
81                    lookup => $lookup->lookup_hash,
82                    row => $row,
83                    rules => $norm_pl,
84            ), "Set data_structure");
85            $t_norm += time() - $t;
86    
87            diag " ds $pos => ",Dumper($ds) if ($debug);
88    
89          ok(my $html = $out->apply(          ok(my $html = $out->apply(
90                  template => 'html.tt',                  template => 'html.tt',
# Line 77  while (my $row = $isis->fetch) { Line 93  while (my $row = $isis->fetch) {
93    
94          $html =~ s#\s*[\n\r]+\s*##gs;          $html =~ s#\s*[\n\r]+\s*##gs;
95    
96          diag $html;          #diag $html;
97    
98  };  };
99    
100    diag sprintf("timings: %.2fs\n", $t_norm);

Legend:
Removed from v.217  
changed lines
  Added in v.536

  ViewVC Help
Powered by ViewVC 1.1.26