Пример #1
0
 def test_add_field(self):
     record = Record()
     field = Field(tag='245',
                   indicators=['1', '0'],
                   subfields=['a', 'Python', 'c', 'Guido'])
     record.add_field(field)
     self.assertTrue(field in record.fields, msg='found field')
Пример #2
0
    def test_pubyear(self):
        record = Record()
        self.assertEqual(record.pubyear(), None)
        record.add_field(
            Field(
                "260",
                [" ", " "],
                subfields=[
                    "a",
                    "Paris :",
                    "b",
                    "Gauthier-Villars ;",
                    "a",
                    "Chicago :",
                    "b",
                    "University of Chicago Press,",
                    "c",
                    "1955.",
                ],
            ))
        self.assertEqual(record.pubyear(), "1955.")

        record = Record()
        self.assertEqual(record.pubyear(), None)
        record.add_field(
            Field(
                "264",
                [" ", "1"],
                subfields=["a", "London :", "b", "Penguin,", "c", "1961."],
            ))
        self.assertEqual(record.pubyear(), "1961.")
Пример #3
0
    def test_isbn(self):
        record = Record()
        self.assertEqual(record.isbn(), None)
        record.add_field(Field('020', [0, 1], subfields=['a',
                                                         '9781416566113']))
        self.assertEqual(record.isbn(), '9781416566113')

        record = Record()
        record.add_field(
            Field('020', [0, 1], subfields=['a', '978-1416566113']))
        self.assertEqual(record.isbn(), '9781416566113')

        record = Record()
        record.add_field(
            Field('020', [0, 1], subfields=['a', 'ISBN-978-1416566113']))
        self.assertEqual(record.isbn(), '9781416566113')

        record = Record()
        record.add_field(
            Field('020', [' ', ' '], subfields=['a', '0456789012 (reel 1)']))
        self.assertEqual(record.isbn(), '0456789012')

        record = Record()
        record.add_field(
            Field('020', [' ', ' '], subfields=['a', '006073132X']))
        self.assertEqual(record.isbn(), '006073132X')
Пример #4
0
 def test_add_field(self):
     record = Record()
     field = Field(tag="245",
                   indicators=["1", "0"],
                   subfields=["a", "Python", "c", "Guido"])
     record.add_field(field)
     self.assertTrue(field in record.fields, msg="found field")
Пример #5
0
    def test_pubyear(self):
        record = Record()
        self.assertEqual(record.pubyear(), None)
        record.add_field(
            Field(
                "260",
                [" ", " "],
                subfields=[
                    "a",
                    "Paris :",
                    "b",
                    "Gauthier-Villars ;",
                    "a",
                    "Chicago :",
                    "b",
                    "University of Chicago Press,",
                    "c",
                    "1955.",
                ],
            )
        )
        self.assertEqual(record.pubyear(), "1955.")

        record = Record()
        self.assertEqual(record.pubyear(), None)
        record.add_field(Field("264", [" ", "1"], subfields=["a", "London :", "b", "Penguin,", "c", "1961."]))
        self.assertEqual(record.pubyear(), "1961.")
Пример #6
0
 def test_physicaldescription(self):
     record = Record()
     pd1 = "=300  \\$a1 photographic print :$bgelatin silver ;$c10 x 56 in."
     pd2 = "=300  \\$aFOO$bBAR$cBAZ"
     pdlist = [pd1, pd2]
     self.assertEqual(record.physicaldescription(), [])
     record.add_field(
         Field(
             "300",
             ["\\", ""],
             subfields=[
                 "a",
                 "1 photographic print :",
                 "b",
                 "gelatin silver ;",
                 "c",
                 "10 x 56 in.",
             ],
         ))
     record.add_field(
         Field("300", ["\\", ""],
               subfields=["a", "FOO", "b", "BAR", "c", "BAZ"]))
     self.assertEqual(len(record.physicaldescription()), 2)
     self.assertEqual(record.physicaldescription()[0].__str__(), pd1)
     self.assertEqual(record.physicaldescription()[1].__str__(), pd2)
     rpdlist = [rpd.__str__() for rpd in record.physicaldescription()]
     self.assertEqual(pdlist, rpdlist)
Пример #7
0
 def test_notes(self):
     record = Record()
     self.assertEquals(record.notes(), [])
     record.add_field(
         Field("500", [" ", " "], subfields=["a", "Recast in bronze from artist's plaster original of 1903."])
     )
     self.assertEquals(record.notes()[0].format_field(), "Recast in bronze from artist's plaster original of 1903.")
Пример #8
0
 def test_electronic_location(self):
     record = Record()
     record.add_field(
         Field(
             '856', ['4', ' '],
             subfields=[
                 's', '287086', 'u',
                 'http://digitallibrary.un.org/record/1317932/files/A_C-4_72_L-24-EN.pdf'
             ]))
     record.add_field(
         Field(
             '856', ['4', ' '],
             subfields=[
                 's', '289890', 'u',
                 'http://digitallibrary.un.org/record/1317932/files/A_C-4_72_L-24-ES.pdf'
             ]))
     self.assertEqual(len(record.electronic_location()), 2)
     self.assertEqual(
         record.electronic_location()[0].format_field(),
         '287086 http://digitallibrary.un.org/record/1317932/files/A_C-4_72_L-24-EN.pdf'
     )
     self.assertEqual(
         record.electronic_location()[1].format_field(),
         '289890 http://digitallibrary.un.org/record/1317932/files/A_C-4_72_L-24-ES.pdf'
     )
Пример #9
0
    def test_isbn(self):
        record = Record()
        self.assertEqual(record.isbn(), None)
        record.add_field(Field("020", [0, 1], subfields=["a",
                                                         "9781416566113"]))
        self.assertEqual(record.isbn(), "9781416566113")

        record = Record()
        record.add_field(
            Field("020", [0, 1], subfields=["a", "978-1416566113"]))
        self.assertEqual(record.isbn(), "9781416566113")

        record = Record()
        record.add_field(
            Field("020", [0, 1], subfields=["a", "ISBN-978-1416566113"]))
        self.assertEqual(record.isbn(), "9781416566113")

        record = Record()
        record.add_field(
            Field("020", [" ", " "], subfields=["a", "0456789012 (reel 1)"]))
        self.assertEqual(record.isbn(), "0456789012")

        record = Record()
        record.add_field(
            Field("020", [" ", " "], subfields=["a", "006073132X"]))
        self.assertEqual(record.isbn(), "006073132X")
Пример #10
0
 def test_membership(self):
     record = Record()
     title = Field(tag="245",
                   indicators=["1", "0"],
                   subfields=["a", "Python", "c", "Guido"])
     record.add_field(title)
     self.assertTrue("245" in record)
     self.assertFalse("999" in record)
Пример #11
0
 def test_quick_access(self):
     record = Record()
     title = Field(tag="245",
                   indicators=["1", "0"],
                   subfields=["a", "Python", "c", "Guido"])
     record.add_field(title)
     self.assertEqual(record["245"], title, "short access")
     self.assertEqual(record["999"], None, "short access with no field")
Пример #12
0
 def test_issn(self):
     record = Record()
     self.assertEqual(record.issn(), None)
     record.add_field(
         Field(tag="022",
               indicators=["0", ""],
               subfields=["a", "0395-2037"]))
     self.assertEqual(record.issn(), "0395-2037")
Пример #13
0
 def test_membership(self):
     record = Record()
     title = Field(tag='245',
                   indicators=['1', '0'],
                   subfields=['a', 'Python', 'c', 'Guido'])
     record.add_field(title)
     self.assertTrue('245' in record)
     self.assertFalse('999' in record)
Пример #14
0
 def test_quick_access(self):
     record = Record()
     title = Field(tag='245',
                   indicators=['1', '0'],
                   subfields=['a', 'Python', 'c', 'Guido'])
     record.add_field(title)
     self.assertEqual(record['245'], title, 'short access')
     self.assertEqual(record['999'], None, 'short access with no field')
Пример #15
0
 def test_multi_find(self):
     record = Record()
     subject1 = Field(tag="650", indicators=["", "0"], subfields=["a", "Programming Language"])
     record.add_field(subject1)
     subject2 = Field(tag="651", indicators=["", "0"], subfields=["a", "Object Oriented"])
     record.add_field(subject2)
     found = record.get_fields("650", "651")
     self.assertEquals(len(found), 2)
Пример #16
0
 def test_add_field(self):
     record = Record()
     field = Field(
         tag = '245', 
         indicators = ['1', '0'], 
         subfields = ['a', 'Python', 'c', 'Guido'])
     record.add_field(field)
     self.assertTrue(field in record.fields, msg='found field')
Пример #17
0
 def test_authority_authors(self):
     record = Record()
     record.add_field(
         Field('710', ['2', ' '],
               subfields=[
                   'a', "UN. General Assembly (60th sess. : 2005-2006)"
               ]))
     record.add_field(Field('710', ['2', ' '], subfields=['a', "Andorra"]))
     self.assertEqual(len(record.authority_authors()), 2)
Пример #18
0
 def test_alphatag(self):
     record = Record()
     record.add_field(Field("CAT", [" ", " "], subfields=["a", "foo"]))
     record.add_field(Field("CAT", [" ", " "], subfields=["b", "bar"]))
     fields = record.get_fields("CAT")
     self.assertEqual(len(fields), 2)
     self.assertEqual(fields[0]["a"], "foo")
     self.assertEqual(fields[1]["b"], "bar")
     self.assertEqual(record["CAT"]["a"], "foo")
Пример #19
0
    def test_title(self):
        record = Record()
        self.assertEquals(record.title(), None)
        record.add_field(Field("245", [0, 1], subfields=["a", "Foo :", "b", "bar"]))
        self.assertEquals(record.title(), "Foo :bar")

        record = Record()
        record.add_field(Field("245", [0, 1], subfields=["a", "Farghin"]))
        self.assertEquals(record.title(), "Farghin")
Пример #20
0
 def test_alphatag(self):
     record = Record()
     record.add_field(Field('CAT', [' ', ' '], subfields=['a', 'foo']))
     record.add_field(Field('CAT', [' ', ' '], subfields=['b', 'bar']))
     fields = record.get_fields('CAT')
     self.assertEqual(len(fields), 2)
     self.assertEqual(fields[0]['a'], 'foo')
     self.assertEqual(fields[1]['b'], 'bar')
     self.assertEqual(record['CAT']['a'], 'foo')
Пример #21
0
 def test_alphatag(self):
     record = Record()
     record.add_field(Field('CAT', [' ', ' '], subfields=['a', 'foo']))
     record.add_field(Field('CAT', [' ', ' '], subfields=['b', 'bar']))
     fields = record.get_fields('CAT')
     self.assertEqual(len(fields), 2)
     self.assertEqual(fields[0]['a'], 'foo')
     self.assertEqual(fields[1]['b'], 'bar')
     self.assertEqual(record['CAT']['a'], 'foo')
Пример #22
0
 def test_membership(self):
     record = Record()
     title = Field(
         tag = '245',
         indicators = ['1', '0'],
         subfields = ['a', 'Python', 'c', 'Guido'])
     record.add_field(title)
     self.assertTrue('245' in record)
     self.assertFalse('999' in record)
Пример #23
0
 def test_quick_access(self):
     record = Record() 
     title = Field(
         tag = '245', 
         indicators = ['1', '0'],
         subfields = ['a', 'Python', 'c', 'Guido'])
     record.add_field(title)
     self.assertEqual(record['245'], title, 'short access')
     self.assertEqual(record['999'], None, 'short access with no field')
Пример #24
0
 def test_init_with_no_leader(self):
     """
     Test creating a Record object with no leader argument.
     """
     record = Record()
     record.add_field(Field(tag="245", indicators=["0", "1"], subfields=["a", "The pragmatic programmer"]))
     transmission_format = record.as_marc()
     transmission_format_leader = transmission_format[0:24]
     self.assertEqual(transmission_format_leader, b"00067     2200037   4500")
Пример #25
0
 def test_alphatag(self):
     record = Record()
     record.add_field(Field("CAT", [" ", " "], subfields=["a", "foo"]))
     record.add_field(Field("CAT", [" ", " "], subfields=["b", "bar"]))
     fields = record.get_fields("CAT")
     self.assertEqual(len(fields), 2)
     self.assertEqual(fields[0]["a"], "foo")
     self.assertEqual(fields[1]["b"], "bar")
     self.assertEqual(record["CAT"]["a"], "foo")
Пример #26
0
 def test_init_with_leader(self):
     """
     Test creating a Record with a leader argument.
     """
     record = Record(leader="abcdefghijklmnopqrstuvwx")
     record.add_field(Field(tag="245", indicators=["0", "1"], subfields=["a", "The pragmatic programmer"]))
     transmission_format = record.as_marc()
     transmission_format_leader = transmission_format[0:24]
     self.assertEqual(transmission_format_leader, b"00067fghij2200037rst4500")
Пример #27
0
    def test_author(self):
        record = Record()
        self.assertEquals(record.author(), None)
        record.add_field(Field("100", [1, 0], subfields=["a", "Bletch, Foobie,", "d", "1979-1981."]))
        self.assertEquals(record.author(), "Bletch, Foobie, 1979-1981.")

        record = Record()
        record.add_field(Field("130", [0, " "], subfields=["a", "Bible.", "l", "Python."]))
        self.assertEquals(record.author(), None)
Пример #28
0
    def test_uniformtitle(self):
        record = Record()
        self.assertEquals(record.uniformtitle(), None)
        record.add_field(Field("130", [0, " "], subfields=["a", "Tosefta.", "l", "English.", "f", "1977."]))
        self.assertEquals(record.uniformtitle(), "Tosefta. English. 1977.")

        record = Record()
        record.add_field(Field("240", [1, 4], subfields=["a", "The Pickwick papers.", "l", "French."]))
        self.assertEquals(record.uniformtitle(), "The Pickwick papers. French.")
Пример #29
0
    def test_title(self):
        record = Record()
        self.assertEqual(record.title(), None)
        record.add_field(
            Field("245", [0, 1], subfields=["a", "Foo :", "b", "bar"]))
        self.assertEqual(record.title(), "Foo : bar")

        record = Record()
        record.add_field(Field("245", [0, 1], subfields=["a", "Farghin"]))
        self.assertEqual(record.title(), "Farghin")
Пример #30
0
    def test_title(self):
        record = Record()
        self.assertEqual(record.title(), None)
        record.add_field(
            Field('245', [0, 1], subfields=['a', 'Foo :', 'b', 'bar']))
        self.assertEqual(record.title(), 'Foo : bar')

        record = Record()
        record.add_field(Field('245', [0, 1], subfields=['a', "Farghin"]))
        self.assertEqual(record.title(), "Farghin")
Пример #31
0
    def test_author(self):
        record = Record()
        self.assertEqual(record.author(), None)
        record.add_field(Field('100', [1, 0],
            subfields=['a', 'Bletch, Foobie,', 'd', '1979-1981.']))
        self.assertEqual(record.author(), 'Bletch, Foobie, 1979-1981.')

        record = Record()
        record.add_field(Field('130', [0, ' '],
            subfields=['a', 'Bible.', 'l', 'Python.']))
        self.assertEqual(record.author(), None)
Пример #32
0
 def test_pubyear(self):
     record = Record()
     self.assertEquals(record.pubyear(), None)
     record.add_field(
         Field('260', [' ', ' '],
               subfields=[
                   'a', 'Paris :', 'b', 'Gauthier-Villars ;', 'a',
                   'Chicago :', 'b', 'University of Chicago Press,', 'c',
                   '1955.'
               ]))
     self.assertEquals(record.pubyear(), '1955.')
Пример #33
0
 def test_author(self):
     record = Record()
     self.assertEqual(record.author(), None)
     record.add_field(Field('100', [1, 0], 
         subfields=['a', 'Bletch, Foobie,', 'd', '1979-1981.']))
     self.assertEqual(record.author(), 'Bletch, Foobie, 1979-1981.')
     
     record = Record()
     record.add_field(Field('130', [0, ' '], 
         subfields=['a', 'Bible.', 'l', 'Python.']))
     self.assertEqual(record.author(), None)
Пример #34
0
    def test_title(self):
        record = Record()
        self.assertEqual(record.title(), None)
        record.add_field(Field('245', [0, 1], 
            subfields=['a', 'Foo :', 'b', 'bar']))
        self.assertEqual(record.title(), 'Foo :bar')

        record = Record()
        record.add_field(Field('245', [0, 1], 
            subfields=['a', "Farghin"]))
        self.assertEqual(record.title(), "Farghin")
Пример #35
0
 def test_find(self):
     record = Record()
     subject1 = Field(tag="650", indicators=["", "0"], subfields=["a", "Programming Language"])
     record.add_field(subject1)
     subject2 = Field(tag="650", indicators=["", "0"], subfields=["a", "Object Oriented"])
     record.add_field(subject2)
     found = record.get_fields("650")
     self.assertEqual(found[0], subject1, "get_fields() item 1")
     self.assertEqual(found[0], subject1, "get_fields() item 2")
     found = record.get_fields()
     self.assertEqual(len(found), 2, "get_fields() with no tag")
Пример #36
0
 def test_as_marc_leader(self):
     record = Record()
     record.add_field(
         Field(tag='245',
               indicators=['0', '1'],
               subfields=['a', 'The pragmatic programmer']))
     record.leader = '00067     2200037   4500'
     leader_not_touched = record.leader
     transmission_format = record.as_marc()
     leader_touched = record.leader
     self.assertTrue(leader_not_touched == leader_touched)
Пример #37
0
    def test_uniformtitle(self):
        record = Record()
        self.assertEqual(record.uniformtitle(), None)
        record.add_field(Field('130', [0, ' '], 
            subfields=['a', "Tosefta.", 'l', "English.", 'f', "1977."]))
        self.assertEqual(record.uniformtitle(), "Tosefta. English. 1977.")

        record = Record()
        record.add_field(Field('240', [1, 4], 
            subfields=['a', "The Pickwick papers.", 'l', "French."]))
        self.assertEqual(record.uniformtitle(), 
                "The Pickwick papers. French.")
Пример #38
0
def standardize_maemarc(fid, mae_marc, fname_suffix):
	marc_file = MARC_FILE % fname_suffix

	mae_marc = mae_marc.replace("\r", "")
	mae_marc = mae_marc.strip()
	mae_marc = mae_marc.rstrip("&")
	mae_marc = mae_marc.rstrip("%")
	
	parts = mae_marc.split('\n')

	header = parts[:2]
	tags_values =  parts[2:]
	ret = []

	writer = MARCWriter(file(marc_file, 'a+'))
	record = Record()
	control = parts[1:2][0][:-1]
	field = Field(tag = '001', data = fid)
	record.add_field(field)
	#field = Field(tag = '008', data = control) 
	#record.add_field(field)

	for dat in tags_values:
		dat = dat.strip('\n')
		tag = dat[0:3]
		values = []
		subfields = []
		for v in dat[6:-1].split('$'):
			subfield = v[:1]
			value = v[1:]
			if (tag == '260') and (subfield == 'c'):
				value = value.lstrip('c')
				value = value.rstrip(".")
				
			subfields.append(subfield)
			subfields.append(value)
			
		if tag == '245':
			indicator = ['1', '0']
		elif tag == '041':
			indicator = ['1', '0']
		else:
			indicator = ['', '']
		field = Field(tag, indicator, subfields)
		record.add_field(field)

		if tag:
			ret.append({tag:subfields})

	print "final output:"
	print record
	writer.write(record)
	writer.close()
Пример #39
0
 def test_as_marc_with_explicit_leader(self):
     """
     Test setting an explicit leader.
     as_marc() should use the whole leader as set.
     """
     record = Record()
     record.add_field(Field(tag="245", indicators=["0", "1"], subfields=["a", "The pragmatic programmer"]))
     record.leader = "00067     2200037   4500"
     leader_not_touched = record.leader
     transmission_format = record.as_marc()
     leader_touched = record.leader
     self.assertTrue(leader_not_touched == leader_touched)
Пример #40
0
    def test_uniformtitle(self):
        record = Record()
        self.assertEqual(record.uniformtitle(), None)
        record.add_field(Field('130', [0, ' '],
            subfields=['a', "Tosefta.", 'l', "English.", 'f', "1977."]))
        self.assertEqual(record.uniformtitle(), "Tosefta. English. 1977.")

        record = Record()
        record.add_field(Field('240', [1, 4],
            subfields=['a', "The Pickwick papers.", 'l', "French."]))
        self.assertEqual(record.uniformtitle(),
                "The Pickwick papers. French.")
Пример #41
0
    def test_pubyear(self):
        record = Record()
        self.assertEqual(record.pubyear(), None)
        record.add_field(Field('260', [' ', ' '],
            subfields=['a', 'Paris :', 'b', 'Gauthier-Villars ;', 'a', 'Chicago :', 'b', 'University of Chicago Press,', 'c', '1955.']))
        self.assertEqual(record.pubyear(), '1955.')

        record = Record()
        self.assertEqual(record.pubyear(), None)
        record.add_field(Field('264', [' ', '1'],
            subfields=['a', 'London :', 'b', 'Penguin,', 'c', '1961.']))
        self.assertEqual(record.pubyear(), '1961.')
Пример #42
0
 def test_multi_find(self):
     record = Record()
     subject1 = Field(tag='650',
                      indicators=['', '0'],
                      subfields=['a', 'Programming Language'])
     record.add_field(subject1)
     subject2 = Field(tag='651',
                      indicators=['', '0'],
                      subfields=['a', 'Object Oriented'])
     record.add_field(subject2)
     found = record.get_fields('650', '651')
     self.assertEqual(len(found), 2)
Пример #43
0
 def test_as_marc_leader(self):
     record = Record()
     record.add_field(
         Field(
             tag = '245', 
             indicators = ['0','1'],
             subfields = ['a', 'The pragmatic programmer']))
     record.leader = '00067     2200037   4500'
     leader_not_touched = record.leader
     transmission_format = record.as_marc()
     leader_touched = record.leader
     self.assertTrue(leader_not_touched==leader_touched)
Пример #44
0
    def test_author(self):
        record = Record()
        self.assertEqual(record.author(), None)
        record.add_field(
            Field("100", [1, 0],
                  subfields=["a", "Bletch, Foobie,", "d", "1979-1981."]))
        self.assertEqual(record.author(), "Bletch, Foobie, 1979-1981.")

        record = Record()
        record.add_field(
            Field("130", [0, " "], subfields=["a", "Bible.", "l", "Python."]))
        self.assertEqual(record.author(), None)
Пример #45
0
 def test_init_with_no_leader_but_with_force_utf8(self):
     record = Record(force_utf8=True)
     record.add_field(
         Field(
             tag="245",
             indicators=["0", "1"],
             subfields=["a", "The pragmatic programmer"],
         ))
     transmission_format = record.as_marc()
     transmission_format_leader = transmission_format[0:24]
     self.assertEqual(transmission_format_leader,
                      b"00067    a2200037   4500")
Пример #46
0
 def test_multi_find(self):
     record = Record()
     subject1 = Field(tag="650",
                      indicators=["", "0"],
                      subfields=["a", "Programming Language"])
     record.add_field(subject1)
     subject2 = Field(tag="651",
                      indicators=["", "0"],
                      subfields=["a", "Object Oriented"])
     record.add_field(subject2)
     found = record.get_fields("650", "651")
     self.assertEqual(len(found), 2)
Пример #47
0
    def test_publisher(self):
        record = Record()
        self.assertEqual(record.publisher(), None)
        record.add_field(Field('260', [' ', ' '],
            subfields=['a', 'Paris :', 'b', 'Gauthier-Villars ;', 'a', 'Chicago :', 'b', 'University of Chicago Press,', 'c', '1955.']))
        self.assertEqual(record.publisher(), 'Gauthier-Villars ;')

        record = Record()
        self.assertEqual(record.publisher(), None)
        record.add_field(Field('264', [' ', '1'],
            subfields=['a', 'London :', 'b', 'Penguin,', 'c', '1961.']))
        self.assertEqual(record.publisher(), 'Penguin,')
Пример #48
0
 def test_init_with_leader_and_force_utf8(self):
     record = Record(leader="abcdefghijklmnopqrstuvwx", force_utf8=True)
     record.add_field(
         Field(
             tag="245",
             indicators=["0", "1"],
             subfields=["a", "The pragmatic programmer"],
         ))
     transmission_format = record.as_marc()
     transmission_format_leader = transmission_format[0:24]
     self.assertEqual(transmission_format_leader,
                      b"00067fghia2200037rst4500")
Пример #49
0
    def test_remove_field(self):
        record = Record()
        field = Field(tag="245", indicators=["1", "0"], subfields=["a", "Python", "c", "Guido"])
        record.add_field(field)
        self.assertEqual(record["245"]["a"], "Python")

        # try removing a field that exists
        record.remove_field(field)
        self.assertEqual(record["245"], None)

        # try removing a field that doesn't exist
        field = Field("001", data="abcd1234")
        self.assertRaises(FieldNotFound, record.remove_field, field)
Пример #50
0
 def test_init_with_no_leader(self):
     """
     Test creating a Record object with no leader argument.
     """
     record = Record()
     record.add_field(
         Field(tag='245',
               indicators=['0', '1'],
               subfields=['a', 'The pragmatic programmer']))
     transmission_format = record.as_marc()
     transmission_format_leader = transmission_format[0:24]
     self.assertEqual(transmission_format_leader,
                      b'00067     2200037   4500')
Пример #51
0
 def test_init_with_leader(self):
     """
     Test creating a Record with a leader argument.
     """
     record = Record(leader='abcdefghijklmnopqrstuvwx')
     record.add_field(
         Field(tag='245',
               indicators=['0', '1'],
               subfields=['a', 'The pragmatic programmer']))
     transmission_format = record.as_marc()
     transmission_format_leader = transmission_format[0:24]
     self.assertEqual(transmission_format_leader,
                      b'00067fghij2200037rst4500')
Пример #52
0
 def test_notes(self):
     record = Record()
     self.assertEqual(record.notes(), [])
     record.add_field(
         Field(
             '500', [' ', ' '],
             subfields=[
                 'a',
                 "Recast in bronze from artist's plaster original of 1903."
             ]))
     self.assertEqual(
         record.notes()[0].format_field(),
         "Recast in bronze from artist's plaster original of 1903.")
Пример #53
0
 def test_subjects(self):
     record = Record()
     subject1 = "=630  0\\$aTosefta.$lEnglish.$f1977."
     subject2 = "=600  10$aLe Peu, Pepe."
     shlist = [subject1, subject2]
     self.assertEquals(record.subjects(), [])
     record.add_field(Field("630", [0, " "], subfields=["a", "Tosefta.", "l", "English.", "f", "1977."]))
     record.add_field(Field("730", [0, " "], subfields=["a", "Tosefta.", "l", "English.", "f", "1977."]))
     record.add_field(Field("600", [1, 0], subfields=["a", "Le Peu, Pepe."]))
     self.assertEquals(len(record.subjects()), 2)
     self.assertEquals(record.subjects()[0].__str__(), subject1)
     self.assertEquals(record.subjects()[1].__str__(), subject2)
     rshlist = [rsh.__str__() for rsh in record.subjects()]
     self.assertEquals(shlist, rshlist)
Пример #54
0
 def test_multi_find(self):
     record = Record() 
     subject1 = Field(
         tag = '650', 
         indicators = ['', '0'], 
         subfields = ['a', 'Programming Language'])
     record.add_field(subject1)
     subject2 = Field(
         tag = '651', 
         indicators = ['', '0'], 
         subfields = ['a', 'Object Oriented'])
     record.add_field(subject2)
     found = record.get_fields('650', '651')
     self.assertEqual(len(found), 2)
Пример #55
0
    def test_remove_field(self):
        record = Record()
        field = Field(
            tag = '245', 
            indicators = ['1', '0'], 
            subfields = ['a', 'Python', 'c', 'Guido'])
        record.add_field(field)
        self.assertEqual(record['245']['a'], 'Python')

        # try removing a field that exists
        record.remove_field(field)
        self.assertEqual(record['245'], None)

        # try removing a field that doesn't exist
        field = Field('001', data='abcd1234')
        self.assertRaises(FieldNotFound, record.remove_field, field)
Пример #56
0
 def test_find(self):
     record = Record() 
     subject1 = Field(
         tag = '650', 
         indicators = ['', '0'], 
         subfields = ['a', 'Programming Language'])
     record.add_field(subject1)
     subject2 = Field(
         tag = '650', 
         indicators = ['', '0'], 
         subfields = ['a', 'Object Oriented'])
     record.add_field(subject2)
     found = record.get_fields('650')
     self.assertEqual(found[0], subject1, 'get_fields() item 1')
     self.assertEqual(found[0], subject1, 'get_fields() item 2')
     found = record.get_fields()
     self.assertEqual(len(found), 2, 'get_fields() with no tag')
Пример #57
0
 def test_physicaldescription(self):
     record = Record()
     pd1 = "=300  \\$a1 photographic print :$bgelatin silver ;$c10 x 56 in."
     pd2 = "=300  \\$aFOO$bBAR$cBAZ"
     pdlist = [pd1, pd2]
     self.assertEquals(record.physicaldescription(), [])
     record.add_field(
         Field(
             "300",
             ["\\", ""],
             subfields=["a", "1 photographic print :", "b", "gelatin silver ;", "c", "10 x 56 in."],
         )
     )
     record.add_field(Field("300", ["\\", ""], subfields=["a", "FOO", "b", "BAR", "c", "BAZ"]))
     self.assertEquals(len(record.physicaldescription()), 2)
     self.assertEquals(record.physicaldescription()[0].__str__(), pd1)
     self.assertEquals(record.physicaldescription()[1].__str__(), pd2)
     rpdlist = [rpd.__str__() for rpd in record.physicaldescription()]
     self.assertEquals(pdlist, rpdlist)
Пример #58
0
 def test_physicaldescription(self):
     record = Record()
     pd1 = '=300  \\$a1 photographic print :$bgelatin silver ;$c10 x 56 in.'
     pd2 = '=300  \\$aFOO$bBAR$cBAZ'
     pdlist = [pd1, pd2]
     self.assertEqual(record.physicaldescription(), [])
     record.add_field(Field('300', ['\\', ''],
         subfields=['a', '1 photographic print :',
                    'b', 'gelatin silver ;',
                    'c', '10 x 56 in.']))
     record.add_field(Field('300', ['\\', ''],
         subfields=['a', 'FOO',
                    'b', 'BAR',
                    'c', 'BAZ']))
     self.assertEqual(len(record.physicaldescription()), 2)
     self.assertEqual(record.physicaldescription()[0].__str__(), pd1)
     self.assertEqual(record.physicaldescription()[1].__str__(), pd2)
     rpdlist = [rpd.__str__() for rpd in record.physicaldescription()]
     self.assertEqual(pdlist, rpdlist)
Пример #59
0
    def test_isbn(self):
        record = Record()
        self.assertEqual(record.isbn(), None)
        record.add_field(Field("020", [0, 1], subfields=["a", "9781416566113"]))
        self.assertEqual(record.isbn(), "9781416566113")

        record = Record()
        record.add_field(Field("020", [0, 1], subfields=["a", "978-1416566113"]))
        self.assertEqual(record.isbn(), "9781416566113")

        record = Record()
        record.add_field(Field("020", [0, 1], subfields=["a", "ISBN-978-1416566113"]))
        self.assertEqual(record.isbn(), "9781416566113")

        record = Record()
        record.add_field(Field("020", [" ", " "], subfields=["a", "0456789012 (reel 1)"]))
        self.assertEqual(record.isbn(), "0456789012")

        record = Record()
        record.add_field(Field("020", [" ", " "], subfields=["a", "006073132X"]))
        self.assertEqual(record.isbn(), "006073132X")
Пример #60
0
    def test_isbn(self):
        record = Record()
        self.assertEqual(record.isbn(), None) 
        record.add_field(Field('020', [0, 1], subfields=['a', '9781416566113']))
        self.assertEqual(record.isbn(), '9781416566113')
        
        record = Record()
        record.add_field(Field('020', [0, 1], subfields=['a', '978-1416566113']))
        self.assertEqual(record.isbn(), '9781416566113')
        
        record = Record()
        record.add_field(Field('020', [0, 1], subfields=['a', 'ISBN-978-1416566113']))
        self.assertEqual(record.isbn(), '9781416566113')
        
        record = Record()
        record.add_field(Field('020', [' ', ' '], subfields=['a', '0456789012 (reel 1)']))
        self.assertEqual(record.isbn(), '0456789012')

        record = Record()
        record.add_field(Field('020', [' ', ' '], subfields=['a', '006073132X']))
        self.assertEqual(record.isbn(), '006073132X')