Permalink
Browse files

bugfix and tests for when len(tag) < 3

  • Loading branch information...
1 parent 0bdb7d8 commit d1f71c4de1db2b01247b98748514fe443a2963a9 @edsu committed Oct 21, 2008
Showing with 73 additions and 2 deletions.
  1. +4 −0 Changes
  2. +1 −1 pymarc/__init__.py
  3. +6 −1 pymarc/field.py
  4. +51 −0 test/bad_tag.xml
  5. +7 −0 test/field.py
  6. +4 −0 test/xml_test.py
View
@@ -1,3 +1,7 @@
+v2.3 Tue Oct 21 08:27:58 EDT 2008
+- added logic to Field to format integer tags if they aren't of length 3
+ thanks to Ross Singer for noticing the problem
+
v2.23 Tue Jul 8 12:20:27 EDT 2008
- added *.py to MANIFEST.in, or else ez_setup.py ain't there
View
@@ -1,6 +1,6 @@
# __init__.py
-__version__ = '2.23'
+__version__ = '2.3'
r'''
The pymarc module provides an API for reading, writing and modifying
View
@@ -28,7 +28,12 @@ def __init__(self, tag, indicators=None, subfields=None, data=''):
if subfields == None:
subfields = []
- self.tag = '%03s' % tag
+ # attempt to normalize integer tags if necessary
+ try:
+ self.tag = '%03i' % int(tag)
+ except ValueError:
+ self.tag = '%03s' % tag
+
if self.tag < '010':
self.data = data
else:
View
@@ -0,0 +1,51 @@
+<?xml version="1.0"?>
+<ns0:record xmlns:ns0="http://www.loc.gov/MARC21/slim">
+ <ns0:leader> Z 22 4500</ns0:leader>
+ <ns0:datafield ind1="0" ind2="0" tag="245">
+ <ns0:subfield code="a">The Untamed</ns0:subfield>
+ <ns0:subfield code="b"/>
+ <ns0:subfield code="c">by Max Brand</ns0:subfield>
+ </ns0:datafield>
+ <ns0:datafield ind1="0" ind2="z" tag="100">
+ <ns0:subfield code="a">Brand, Max,</ns0:subfield>
+ </ns0:datafield>
+ <ns0:datafield ind1="z" ind2="z" tag="42">
+ <ns0:subfield code="a">dc</ns0:subfield>
+ </ns0:datafield>
+ <ns0:datafield ind1="z" ind2="z" tag="100">
+ <ns0:subfield code="d">1892-1944</ns0:subfield>
+ </ns0:datafield>
+ <ns0:datafield ind1="z" ind2="z" tag="245">
+ <ns0:subfield code="h">[electronic resource] /</ns0:subfield>
+ </ns0:datafield>
+ <ns0:datafield ind1="z" ind2="z" tag="260">
+ <ns0:subfield code="b">Project Gutenberg,</ns0:subfield>
+ </ns0:datafield>
+ <ns0:datafield ind1="z" ind2="z" tag="260">
+ <ns0:subfield code="c">2004</ns0:subfield>
+ </ns0:datafield>
+ <ns0:datafield ind1="z" ind2="z" tag="500">
+ <ns0:subfield code="a">Project Gutenberg</ns0:subfield>
+ </ns0:datafield>
+ <ns0:datafield ind1="z" ind2="z" tag="506">
+ <ns0:subfield code="a">Freely available.</ns0:subfield>
+ </ns0:datafield>
+ <ns0:datafield ind1="z" ind2="z" tag="516">
+ <ns0:subfield code="a">Electronic text</ns0:subfield>
+ </ns0:datafield>
+ <ns0:datafield ind1="z" ind2="z" tag="830">
+ <ns0:subfield code="a">Project Gutenberg</ns0:subfield>
+ </ns0:datafield>
+ <ns0:datafield ind1="z" ind2="z" tag="830">
+ <ns0:subfield code="v">10886</ns0:subfield>
+ </ns0:datafield>
+ <ns0:datafield ind1="z" ind2="z" tag="856">
+ <ns0:subfield code="u">http://www.gutenberg.org/etext/10886</ns0:subfield>
+ </ns0:datafield>
+ <ns0:datafield ind1="z" ind2="z" tag="856">
+ <ns0:subfield code="u">http://www.gutenberg.org/license</ns0:subfield>
+ </ns0:datafield>
+ <ns0:datafield ind1="z" ind2="z" tag="856">
+ <ns0:subfield code="3">Rights</ns0:subfield>
+ </ns0:datafield>
+</ns0:record>
View
@@ -95,6 +95,13 @@ def test_format_field(self):
self.assertEqual(self.field.format_field(),
'Huckleberry Finn: An American Odyssey')
+ def test_tag_normalize(self):
+ f = Field(tag='42', indicators=['', ''])
+ self.assertEqual(f.tag, '042')
+ #f.subfields.append('a')
+ #f.subfields.append('foo')
+ #print f
+
def suite():
test_suite = unittest.makeSuite(FieldTest, 'test')
return test_suite
View
@@ -103,3 +103,7 @@ def test_xml_quiet(self):
sys.stderr.close()
# no errors should have been written
self.assertEqual(getsize(outfile), 0)
+
+ def test_bad_tag(self):
+ a = pymarc.parse_xml_to_array(file('test/bad_tag.xml'))
+ self.assertEqual(len(a), 1)

0 comments on commit d1f71c4

Please sign in to comment.