/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 479 - (hide annotations)
Sat May 13 13:39:09 2006 UTC (17 years, 11 months ago) by dpavlin
File MIME type: application/x-troff
File size: 2528 byte(s)
 r617@llin:  dpavlin | 2006-05-13 15:42:13 +0200
 dump lookup_hash

1 dpavlin 22 #!/usr/bin/perl -w
2    
3     use strict;
4    
5 dpavlin 470 use Test::More tests => 66;
6 dpavlin 22 use Test::Exception;
7     use Cwd qw/abs_path/;
8     use File::Temp qw/tempdir/;
9 dpavlin 470 use File::Slurp;
10 dpavlin 33 use Data::Dumper;
11 dpavlin 22 use blib;
12    
13 dpavlin 474 my $debug = shift @ARGV;
14 dpavlin 470
15 dpavlin 22 BEGIN {
16     use_ok( 'WebPAC::Lookup' );
17 dpavlin 300 use_ok( 'WebPAC::Input' );
18 dpavlin 209 use_ok( 'WebPAC::Store' );
19 dpavlin 22 use_ok( 'WebPAC::Normalize::XML' );
20 dpavlin 470 use_ok( 'WebPAC::Normalize::Set' );
21 dpavlin 22 use_ok( 'WebPAC::Output::TT' );
22     }
23    
24     ok(my $abs_path = abs_path($0), "abs_path");
25     $abs_path =~ s#/[^/]*$#/#;
26 dpavlin 470 diag "abs_path: $abs_path" if ($debug);
27 dpavlin 22
28     my $isis_file = "$abs_path../t/winisis/BIBL";
29 dpavlin 479 #$isis_file = '/data/hidra/THS/THS';
30     $isis_file = '/data/isis_data/ffkk/';
31 dpavlin 22
32 dpavlin 470 diag "isis_file: $isis_file" if ($debug);
33 dpavlin 22
34 dpavlin 470 my $normalize_set_pl = "$abs_path/data/normalize.pl";
35     my $lookup_file = "$abs_path../conf/lookup/isis.pm";
36    
37 dpavlin 22 ok(my $lookup = new WebPAC::Lookup(
38 dpavlin 470 lookup_file => $lookup_file,
39 dpavlin 22 ), "new Lookup");
40    
41 dpavlin 300 ok(my $isis = new WebPAC::Input(
42     module => 'WebPAC::Input::ISIS',
43 dpavlin 22 code_page => 'ISO-8859-2', # application encoding
44 dpavlin 300 limit => 10,
45 dpavlin 22 ), "new Input::ISIS");
46    
47     ok(my $maxmfn = $isis->open(
48 dpavlin 300 path => $isis_file,
49 dpavlin 22 code_page => '852', # database encoding
50 dpavlin 252 lookup => $lookup,
51 dpavlin 22 ), "Input::ISIS->open");
52    
53     ok(my $path = tempdir( CLEANUP => 1 ), "path");
54    
55 dpavlin 209 ok(my $db = new WebPAC::Store(
56 dpavlin 22 path => $path,
57 dpavlin 217 database => '.',
58 dpavlin 209 ), "new Store");
59 dpavlin 22
60     ok(my $n = new WebPAC::Normalize::XML(
61     # filter => { 'foo' => sub { shift } },
62     db => $db,
63     lookup_regex => $lookup->regex,
64 dpavlin 31 lookup => $lookup,
65 dpavlin 22 ), "new Normalize::XML");
66    
67     ok($n->open(
68     tag => 'isis',
69 dpavlin 366 xml_file => "$abs_path/data/normalize.xml",
70 dpavlin 22 ), "Normalize::XML->open");
71    
72 dpavlin 470 ok(my $norm_pl = read_file( $normalize_set_pl ), "set definitions: $normalize_set_pl" );
73    
74 dpavlin 22 ok(my $out = new WebPAC::Output::TT(
75     include_path => "$abs_path../conf/output/tt",
76     filters => { foo => sub { shift } },
77     ), "new Output::TT");
78    
79     while (my $row = $isis->fetch) {
80 dpavlin 470
81 dpavlin 474 diag " row => ",Dumper($row) if ($debug);
82     set_rec( $row );
83    
84 dpavlin 70 ok(my $ds = $n->data_structure($row), "data_structure");
85 dpavlin 22
86 dpavlin 470 diag " ds => ",Dumper($ds) if ($debug);
87 dpavlin 22
88 dpavlin 470 # TODO move somewhere
89     {
90     no strict 'subs';
91     use WebPAC::Normalize::Set;
92 dpavlin 479 diag " lookup => ",Dumper($lookup->lookup_hash) if ($debug);
93 dpavlin 474 set_lookup( $lookup->lookup_hash );
94 dpavlin 470 clean_ds();
95     eval "$norm_pl";
96     ok(! $@, $@ ? "error: $@" : "no error");
97     ok(my $ds2 = get_ds(), "get_ds");
98     is_deeply( $ds, $ds2, 'ds same for xml and sets');
99    
100     diag " ds2 => ",Dumper($ds2) if ($debug);
101     }
102    
103 dpavlin 33 ok(my $html = $out->apply(
104 dpavlin 22 template => 'html.tt',
105 dpavlin 70 data => $ds,
106 dpavlin 22 ), "apply");
107    
108 dpavlin 33 $html =~ s#\s*[\n\r]+\s*##gs;
109    
110 dpavlin 352 #diag $html;
111 dpavlin 33
112 dpavlin 22 };

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26