[open-ils-commits] r15302 - trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test (djfiander)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Jan 11 21:14:39 EST 2010
Author: djfiander
Date: 2010-01-11 21:14:38 -0500 (Mon, 11 Jan 2010)
New Revision: 15302
Added:
trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/testlib.pm
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/mfhd.t
Log:
move load_MARC_rec into separate package to prep for creating new test scripts
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/mfhd.t
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/mfhd.t 2010-01-12 02:03:25 UTC (rev 15301)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/mfhd.t 2010-01-12 02:14:38 UTC (rev 15302)
@@ -8,8 +8,10 @@
use MARC::Record;
use OpenILS::Utils::MFHD;
-my $testno = 0;
+use testlib;
+my $testno = 1;
+
sub right_answer {
my $holding = shift;
my $answer = {};
@@ -24,68 +26,13 @@
return $answer;
}
-sub load_MARC_rec {
- my $fh = shift;
- my $rec;
- my $line;
- my $marc = undef;
- # skim to beginning of record (a non-blank, non comment line)
- while ($line = <$fh>) {
- chomp $line;
- last if (!($line =~ /^\s*$/) && !($line =~ /^#/));
- }
-
- return undef if !$line;
-
- $testno += 1;
- $marc = MARC::Record->new();
- carp('No record created!') unless $marc;
-
- $marc->leader('01119nas 2200313 a 4500');
- $marc->append_fields(
- MARC::Field->new('008', '970701c18439999enkwr p 0 a0eng '));
- $marc->append_fields(
- MARC::Field->new('035', '', '', a => sprintf('%04d', $testno)));
-
- while ($line) {
- next if $line =~ /^#/; # allow embedded comments
-
- return $marc if $line =~ /^\s*$/;
-
- my ($fieldno, $indicators, $rest) = split(/ /, $line, 3);
- my @inds = unpack('aa', $indicators);
- my $field;
- my @subfields;
-
- @subfields = ();
- foreach my $subfield (split(/\$/, $rest)) {
- next unless $subfield;
-
- my ($key, $val) = unpack('aa*', $subfield);
- push @subfields, $key, $val;
- }
-
- $field = MARC::Field->new(
- $fieldno, $inds[0], $inds[1],
- a => 'scratch',
- @subfields
- );
-
- $marc->append_fields($field);
-
- $line = <$fh>;
- chomp $line if $line;
- }
- return $marc;
-}
-
my $rec;
my @captions;
open(my $testdata, "<mfhddata.txt") or die("Cannot open 'mfhddata.txt': $!");
-while ($rec = load_MARC_rec($testdata)) {
+while ($rec = testlib::load_MARC_rec($testdata, $testno++)) {
$rec = MFHD->new($rec);
foreach my $cap (sort { $a->tag <=> $b->tag } $rec->field('85.')) {
Added: trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/testlib.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/testlib.pm (rev 0)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/testlib.pm 2010-01-12 02:14:38 UTC (rev 15302)
@@ -0,0 +1,70 @@
+package testlib;
+
+use strict;
+use warnings;
+
+use base 'Exporter';
+
+our @EXPORT_OK = qw(load_MARC_rec);
+
+use Data::Dumper;
+
+use MARC::Record;
+
+sub load_MARC_rec {
+ my $fh = shift;
+ my $testno = shift;
+ my $rec;
+ my $line;
+ my $marc = undef;
+
+ # skim to beginning of record (a non-blank, non comment line)
+ while ($line = <$fh>) {
+ chomp $line;
+ last if (!($line =~ /^\s*$/) && !($line =~ /^#/));
+ }
+
+ return undef if !$line;
+
+ $marc = MARC::Record->new();
+ carp('No record created!') unless $marc;
+
+ $marc->leader('01119nas 2200313 a 4500');
+ $marc->append_fields(
+ MARC::Field->new('008', '970701c18439999enkwr p 0 a0eng '));
+ $marc->append_fields(
+ MARC::Field->new('035', '', '', a => sprintf('%04d', $testno)));
+
+ while ($line) {
+ next if $line =~ /^#/; # allow embedded comments
+
+ return $marc if $line =~ /^\s*$/;
+
+ my ($fieldno, $indicators, $rest) = split(/ /, $line, 3);
+ my @inds = unpack('aa', $indicators);
+ my $field;
+ my @subfields;
+
+ @subfields = ();
+ foreach my $subfield (split(/\$/, $rest)) {
+ next unless $subfield;
+
+ my ($key, $val) = unpack('aa*', $subfield);
+ push @subfields, $key, $val;
+ }
+
+ $field = MARC::Field->new(
+ $fieldno, $inds[0], $inds[1],
+ a => 'scratch',
+ @subfields
+ );
+
+ $marc->append_fields($field);
+
+ $line = <$fh>;
+ chomp $line if $line;
+ }
+ return $marc;
+}
+
+1;
More information about the open-ils-commits
mailing list