[open-ils-commits] r12524 - trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test (djfiander)

svn at svn.open-ils.org svn at svn.open-ils.org
Sat Mar 14 14:28:20 EDT 2009


Author: djfiander
Date: 2009-03-14 14:28:17 -0400 (Sat, 14 Mar 2009)
New Revision: 12524

Added:
   trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/mfhd.t
Removed:
   trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/tests.outline.txt
Log:
first pass at MFHD test suite

Added: trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/mfhd.t
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/mfhd.t	                        (rev 0)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/mfhd.t	2009-03-14 18:28:17 UTC (rev 12524)
@@ -0,0 +1,184 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Data::Dumper;
+use Test::More 'no_plan';
+
+use MARC::Record;
+use OpenILS::Utils::MFHD;
+
+my $testno = 0;
+
+sub right_answer {
+    my $holding = shift;
+    my $answer = {};
+
+    foreach my $subfield (split(/\|/, $holding->subfield('x'))) {
+	next unless $subfield;
+
+	my ($key, $val) = unpack('aa*', $subfield);
+	$answer->{$key} = $val;
+    }
+
+    return $answer;
+}
+
+sub load_MARC_rec {
+    my $rec;
+    my $line;
+    my $marc = undef;
+
+    # skim to beginning of record (a non-blank, non comment line)
+    while ($line = <DATA>) {
+	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('cc', $indicators);
+	my $field = MARC::Field->new($fieldno, $inds[0], $inds[1],
+				     a => 'scratch');
+
+	foreach my $subfield (split(/\$/, $rest)) {
+	    next unless $subfield;
+
+	    my ($key, $val) = unpack('aa*', $subfield);
+	    $field->update($key => $val);
+	}
+
+	$marc->append_fields($field);
+
+	$line = <DATA>;
+	chomp $line if $line;
+    }
+    return $marc;
+}
+
+my $rec;
+
+while ($rec = load_MARC_rec) {
+    $rec = MFHD->new($rec);
+
+    foreach my $cap_id ($rec->captions('853')) {
+	my @holdings = $rec->holdings('863', $cap_id);
+
+	next unless scalar @holdings;
+	foreach my $field (@holdings) {
+	  TODO: {
+		local $TODO = "unimplemented"
+		  if ($field->subfield('z') =~ /^TODO/);
+		is_deeply($field->next, right_answer($field),
+			  $field->subfield('8'));
+	    }
+	}
+    }
+}
+
+1;
+
+__END__
+#
+# load record, then loop over 863 fields calling next().
+#
+
+245 00 $aMonthly, issue no. restarts, calendar change: Jan
+853 20 $81$av.$bno.$u12$vr$i(year)$j(month)$wm$x01
+863 41 $81.1$a1$b6$i1990$j06$x|a1|b7|i1990|j07$zMiddle of year, middle of vol.
+863 41 $81.2$a1$b11$i1990$j11$x|a1|b12|i1990|j12$zEnd of year, end of vol.
+863 41 $81.3$a1$b12$i1990$j12$x|a2|b1|i1991|j01$zWrap at end of year/vol.
+
+245 00 $aMonthly, issue no. restarts, calendar change: Mar
+853 20 $82$av.$bno.$u12$vr$i(year)$j(month)$wm$x03
+863 41 $82.1$a1$b6$i1990$j08$x|a1|b7|i1990|j09$zMiddle of year, middle of vol.
+863 41 $82.2$a1$b10$i1990$j12$x|a1|b11|i1991|j01$zEnd of year, middle of vol.
+863 41 $82.3$a1$b11$i1991$j01$x|a1|b12|i1991|j02$zMiddle of year, end of vol.
+863 41 $82.3$a1$b12$i1991$j02$x|a2|b1|i1991|j03$zWrap vol in mid-year
+
+245 00 $aMonthly, issue no. continuous, calendar change: Jan
+853 20 $83$av.$bno.$u12$vc$i(year)$j(month)$wm$x01
+863 41 $83.1$a1$b6$i1990$j06$x|a1|b7|i1990|j07$zMiddle of year, middle of vol.
+863 41 $83.2$a1$b11$i1990$j11$x|a1|b12|i1990|j12$zEnd of year, end of vol.
+863 41 $83.3$a1$b12$i1190$j12$x|a2|b13|i1991|j01$zTODO wrap vol @ end of year
+
+245 00 $aMonthly, issue no. continuous, calendar change: Mar
+853 20 $84$av.$bno.$u12$vc$i(year)$j(month)$wm$x03
+863 41 $84.1$a1$b6$i1990$j08$x|a1|b7|i1990|j09$zMiddle of year, middle of vol.
+863 41 $84.2$a1$b10$i1990$j12$x|a1|b11|i1991|j01$zEnd of year, middle of vol.
+863 41 $84.3$a1$b11$i1991$j01$x|a1|b12|i1991|j02$zMiddle of year, end of vol.
+863 41 $84.3$a1$b12$i1991$j02$x|a2|b13|i1991|j03$zTODO wrap vol mid-year
+
+245 00 $aMonthly, issue no. restarts, Calendar change: Jan, Jul
+853 20 $85$av.$bno.$u6$vr$i(year)$j(month)$wm$x01,07
+863 41 $85.1$a1$b5$i1990$j05$x|a1|b6|i1990|j06$zMiddle of year, near end of vol.
+863 41 $85.2$a1$b6$i1990$j06$x|a2|b1|i1990|j07$zMiddle of year, end of vol.
+863 41 $85.3$a2$b6$i1990$j12$x|a3|b1|i1991|j01$zEnd of year, end of vol.
+
+245 00 $aMonthly, issue no. continuous, Calendar change: Jan, Jul
+853 20 $86$av.$bno.$u6$vc$i(year)$j(month)$wm$x01,07
+863 41 $86.1$a1$b5$i1990$j05$x|a1|b6|i1990|j06$zMiddle of year, end of vol.
+863 41 $86.2$a1$b6$i1990$j06$x|a2|b7|i1990|j07$zTODO Middle of year, end of vol.
+863 41 $86.3$a2$b12$i1990$j12$x|a3|b13|i1991|j01$zTODO End of year, end of vol.
+
+245 00 $aMonthly, issue no. restarts, Calendar change: Jan, Combined issue: Jan/Feb
+853 20 $87$av.$bno.$u11$vr$i(year)$j(month)$wm$x01$ycm01/02
+863 41 $87.1$a1$b11$i1990$j12$x|a2|b1|i1991|j01/02$zTODO End of year, end of vol.
+863 41 $87.2$a2$b1$i1991$j01/02$x|a2|b2|i1991|j03$zTODO Beginning of year, beginning of vol.
+
+245 00 $aMonthly, iss no. restarts, Calendar change: Jan, Combined iss: Nov/Dec
+853 20 $88$av.$bno.$u11$vr$i(year)$j(month)$wm$x01$ycm11/12
+863 41 $88.1$a1$b10$i1990$j10$x|a1|b11|i1990|j11/12$zTODO end of year, end of vol.
+863 41 $88.2$a1$b11$i1990$j11/12$x|a2|b1|i1991|j01$zTODO wrap vol at year end
+
+245 00 $aMonthly, iss no. restarts, Cal. change: Jan, Combined iss: Jan/Feb, Nov/Dec
+853 20 $89$av.$bno.$u10$vr$i(year)$j(month)$wm$x01$ycm01/02,11/12
+863 41 $89.1$a1$b1$i1990$j01/02$x|a1|b2|i1990|j03$zTODO beg. of year, beg. of vol.
+863 41 $89.2$a1$b9$i1990$j10$x|a1|b10|i1990|j11/12$zTODO end of year, end of vol.
+863 41 $89.3$a1$b10$i1990$j11/12$x|a2|b1|i1991|j01/02$zTODO zwrap vol at year end
+
+245 00 $aMonthly, iss no. restarts, Cal. change: Jan, Combined iss: May/Jun, Jul/Aug
+853 20 $810$av.$bno.$u10$vr$i(year)$j(month)$wm$x01$ycm05/06,07/08
+863 41 $810.1$a1$b4$i1990$j04$x|a1|b5|i1990|j05/06$zTODO next iss is combined.
+863 41 $810.2$a1$b5$i1990$j05/06$x|a1|b6|i1990|j07/08$zTODO combined to combined
+863 41 $810.3$a1$b6$i1990$j07/08$x|a1|b7|i1990|j09$zTODO combined to reg
+
+245 00 $aMonthly, issue no. restarts, Calendar change: Jan, Combined issue: 1/2 Jan/Feb 
+853 20 $811$av.$bno.$u12$vr$i(year)$j(month)$wm$x01$ycm01/02$yce21/2
+863 41 $811.1$a1$b12$i1990$j12$x|a2|b1/2|i1991|j01/02$zTODO new vol at year end regular iss to combined
+863 41 $811.2$a2$b1/2$i1991$j01/02$x|a2|b3|i1991|j03$zTODO combined iss to regular
+
+245 00 $aMonthly, iss no. restarts, Calendar change: Jan, Combined iss: 11/12 Nov/Dec
+853 20 $812$av.$bno.$u12$vr$i(year)$j(month)$wm$x01$ycm11/12$yce211/12
+863 41 $812.1$a1$b10$i1990$j10$x|a1|b11/12|i1990|j11/12$zTODO regular to combined iss
+863 41 $812.2$a1$b11/12$i1990$j11/12$x|a2|b1|i1991|j01$zTODO end of vol: combined to regular issue
+
+245 00 $aMonthly, iss no. restarts, Cal. change: Jan, Combined iss: 1/2 Jan/Feb, 11/12 Nov/Dec
+853 20 $813$av.$bno.$u12$vr$i(year)$j(month)$wm$x01$ycm01/02,11/12$yce21/2,11/12
+863 41 $813.1$a1$b10$i1990$j10$x|a1|b11/12|i1990|j11/12$zTODO end of vol regular to combined iss
+863 41 $813.2$a1$b11/12$i1990$j11/12$x|a2|b1/2|i1991|j01/02$zTODO wrap at volume end: combined to combined
+863 41 $813.3$a2$b1/2$i1991$j01/02$x|a2|b3|i1991|j03$zTODO beginning of vol: combined to regular
+
+245 00 $aMonthly, iss no. restarts, Cal. change: Jan, Combined iss: 5/6 May/Jun, 7/8 Jul/Aug 
+853 20 $814$av.$bno.$u12$vr$i(year)$j(month)$wm$x01$ycm05/06,07/08$yce25/6,7/8
+863 41 $814.1$a1$b4$i1990$j04$x|a1|b5/6|i1990|j05/06$zTODO mid year: reg to combined
+863 41 $814.2$a1$b5/6$i1990$j05/06$x|a1|b7/8|i1990|j07/08$zTODO mid year: combined to combined
+863 41 $814.3$a1$b7/8$i1990$j07/08$x|a1|b9|i1990|j09$zTODO mid year: combined to regular
+
+245 00 $aMonthly, iss no. restarts, Cal change: Jan, July issue omitted
+853 20 $815$av.$bno.$u11$vr$i(year)$j(month)$wm$x01$yom07

Deleted: trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/tests.outline.txt
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/tests.outline.txt	2009-03-14 18:26:44 UTC (rev 12523)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/tests.outline.txt	2009-03-14 18:28:17 UTC (rev 12524)
@@ -1,192 +0,0 @@
-* Test cases for MFHD code
-Basic bibliographic units only. Not testing supplements or
-indexes.
-
-** Test Caption and Pattern fields
-*** Monthly, issue # restarts, calendar change: Jan
-853 ## $81$av.$bno.$u12$vr$i(year)$j(month)$wm$x01
-
-*** Monthly, issue # restarts, calendar change: Mar
-853 ## $82$av.$bno.$u12$vr$i(year)$j(month)$wm$x03
-
-*** Monthly, issue # continuous, calendar change: Jan
-853 ## $83$av.$bno.$u12$vc$i(year)$j(month)$wm$x01
-
-*** Monthly, issue # continuous, calendar change: Mar
-853 ## $84$av.$bno.$u12$vc$i(year)$j(month)$wm$x03
-
-*** Monthly, issue # restarts, Calendar change: Jan, Jul
-853 ## $85$av.$bno.$u6$vr$i(year)$j(month)$wm$x01,07
-
-*** Monthly, issue # continuous, Calendar change: Jan, Jul
-853 ## $86$av.$bno.$u6$vc$i(year)$j(month)$wm$x01,07
-
-*** Monthly, issue # restarts, Calendar change: Jan, Combined issue: Jan/Feb
-853 ## $88$av.$bno.$u11$vr$i(year)$j(month)$wm$x01$ycm01/02
-
-*** Monthly, iss # restarts, Calendar change: Jan, Combined iss: Nov/Dec
-853 ## $89$av.$bno.$u11$vr$i(year)$j(month)$wm$x01$ycm11/12
-
-*** Monthly, iss # restarts, Cal. change: Jan, Combined iss: Jan/Feb, Nov/Dec
-853 ## $810$av.$bno.$u10$vr$i(year)$j(month)$wm$x01$ycm01/02,11/12
-
-*** Monthly, iss # restarts, Cal. change: Jan, Combined iss: May/Jun, Jul/Aug
-853 ## $811$av.$bno.$u10$vr$i(year)$j(month)$wm$x01$ycm05/06,07/08
-
-*** Monthly, issue # restarts, Calendar change: Jan, Combined issue: 1/2 Jan/Feb 
-853 ## $812$av.$bno.$u12$vr$i(year)$j(month)$wm$x01$ycm01/02$yce21/2
-
-*** Monthly, iss # restarts, Calendar change: Jan, Combined iss: 11/12 Nov/Dec
-853 ## $813$av.$bno.$u12$vr$i(year)$j(month)$wm$x01$ycm11/12$yce211/12
-
-*** Monthly, iss # restarts, Cal. change: Jan, Combined iss: 1/2 Jan/Feb, 11/12 Nov/Dec
-853 ## $814$av.$bno.$u12$vr$i(year)$j(month)$wm$x01$ycm01/02,11/12$yce21/2,11/12
-
-*** Monthly, iss # restarts, Cal. change: Jan, Combined iss: 5/6 May/Jun, 7/8 Jul/Aug 
-853 ## $815$av.$bno.$u12$vr$i(year)$j(month)$wm$x01$ycm05/06,07/08$yce25/6,7/8
-
-*** Monthly, iss # restarts, Cal change: Jan, July issue omitted
-853 ## $816$av.$bno.$u11$vr$i(year)$j(month)$wm$x01$yom07
-
-** Calculating the publication info for the next issue
-*** Calcuating enumeration (volume, issue)
-**** current issue is 'normal'
-***** subsequent issue is 'normal'
-****** in same volume
-******* issue numbering restarts
-863 ## $81.1$a1$b6$i1990$j06$xMiddle of year, middle of vol.
-863 ## $81.2$a1$b11$i1990$j11$xEnd of year, end of vol.
-
-863 ## $82.1$a1$b6$i1990$j09$xMiddle of year, middle of vol.
-863 ## $82.2$a1$b9$i1990$j12$xEnd of year, middle of vol.
-863 ## $82.3$a1$b11$i1991$j01$xMiddle of year, end of vol.
-
-******** multiple volumes per year
-863 ## $85.1$a1$b5$i1990$j05$xMiddle of year, end of vol.
-
-******* issue numbering is continuous
-863 ## $83.1$a1$b6$i1990$j06$xMiddle of year, middle of vol.
-863 ## $83.2$a1$b11$i1990$j11$xEnd of year, end of vol.
-
-863 ## $84.1$a1$b6$i1990$j09$xMiddle of year, middle of vol.
-863 ## $84.2$a1$b9$i1990$j12$xEnd of year, middle of vol.
-863 ## $84.3$a1$b11$i1991$j01$xMiddle of year, end of vol.
-
-****** in next volume
-******* issue numbering restarts
-863 ## $81.3$a1$b6$i1990$j06$xMiddle of year, middle of vol.
-863 ## $81.4$a1$b11$i1990$j11$xEnd of year, end of vol.
-
-863 ## $82.4$a1$b6$i1990$j09$xMiddle of year, middle of vol.
-863 ## $82.5$a1$b9$i1990$j12$xEnd of year, middle of vol.
-863 ## $82.6$a1$b11$i1991$j01$xMiddle of year, end of vol.
-
-******** multiple volumes per year
-863 ## $85.2$a1$b6$i1990$j06$xMiddle of year, end of vol.
-
-******* issue numbering is continuous
-863 ## $83.3$a1$b6$i1990$j06$xMiddle of year, middle of vol.
-863 ## $83.4$a1$b11$i1990$j11$xEnd of year, end of vol.
-
-863 ## $84.4$a1$b6$i1990$j09$xMiddle of year, middle of vol.
-863 ## $84.5$a1$b9$i1990$j12$xEnd of year, middle of vol.
-863 ## $84.6$a1$b11$i1991$j01$xMiddle of year, end of vol.
-
-******** multiple volumes per year
-863 ## $86.1$a1$b6$i1990$j09$xMiddle of year, end of vol.
-
-***** subsequent issue is combined dates (v.1:no.5 1990:May/Jun)
-****** in same volume
-863 ## $89.1$a1$b10$i1990$j10
-
-****** in next volume
-863 ## $88.1$a1$b11$i1990$j11
-
-***** subsequent issue is combined issue # (v.1:no.5/6 1990:May/Jun)
-****** in same volume
-863 ## $813.1$a1$b10$i1990$j10
-****** in next volume
-863 ## $812.1$a1$b12$i1990$j12
-
-***** Omitted issue number
-does this happen in a way that is worth recording in a pattern?
-
-**** current issue is combined dates
-***** subsequent issue is normal
-****** In same volume
-863 ## $88.2$a2$b1$i1991$j01/02
-
-****** In next volume
-863 ## $89.2$a1$b11$i1990$j11/12
-
-***** subsequent issue is combined dates
-****** In same volume
-863 ## $811.1$a1$b5$i1990$j05/06
-
-****** In next volume
-863 ## $810.1$a1$b10$i1990$j11/12
-
-***** subsequent issue is combined issue #
-****** In same volume
-863 ## $815.1$a1$b5/6$i1990$j05/06
-****** In next volume
-863 ## $814.1$a1$b11/12$i1990$j11/12
-***** Omitted issue number
-**** current issue is combined issue #
-***** subsequent issue is normal
-****** In same volume
-863 ## $812.2$a2$b1/2$i1991$j01/02
-
-****** In next volume
-863 ## $813.2$a1$b11/12$i1990$j11/12
-
-***** subsequent issue is combined dates
-
-Does this happen? Having no.10/11 (Nov/Dec) followed by no.1 (Jan/Feb)?!?
-
-****** In same volume
-****** In next volume
-***** subsequent issue is combined issue #
-****** In same volume
-863 ## $815.2$a1$b5/6$i1990$j05/06
-
-****** In next volume
-863 ## $814.2$a1$b11/12$i1990$j11/12
-
-***** Omitted issue number
-*** Calculating date
-**** Simple date patterns
-That is, no combined issues, no omitted issues, only one simple
-$yp publication regularity code.
-***** Annual
-***** Bimonthly
-***** Semiweekly
-***** Daily
-***** Biweekly
-***** Semiannual
-***** Biennial
-***** Triennial
-***** Three times a week
-***** Three times a month
-***** Monthly
-***** Quarterly
-***** Semimonthly
-***** Three times a year
-***** Weekly
-**** Fixed publication schedule
-$w frequency is number, $yp publication pattern lists publication
-dates
-**** Omitted dates
-***** Omitted days
-***** Omitted weeks
-***** Omitted months
-***** Omitted seasons
-**** Combined dates
-How does this work with combined issue numbers? Sometimes
-May/June is no.5, and sometimes May/June is no.5/6
-***** Combined weeks
-***** Combined months
-***** Combined seasons
-***** Combined years
-yyy1/yyy2 pattern
-



More information about the open-ils-commits mailing list