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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 481 - (show annotations)
Sun May 14 00:50:35 2006 UTC (17 years, 11 months ago) by dpavlin
File MIME type: application/x-troff
File size: 2527 byte(s)
 r622@llin:  dpavlin | 2006-05-14 02:54:00 +0200
 display lookup just once

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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26