def test_set(): from dlx.marc import Bib bib = Bib() bib.set('245', 'a', 'Edited') assert bib.get_value('245', 'a') == 'Edited' bib.set('245', 'a', 'Repeated field', address=['+']) assert bib.get_values('245', 'a') == ['Edited', 'Repeated field'] bib.set('245', 'a', 'Repeated field edited', address=[1]) assert bib.get_value('245', 'a', address=[1, 0]) == 'Repeated field edited' bib.set('245', 'a', 'Repeated subfield', address=[1, '+']) assert bib.get_value('245', 'a', address=[1, 1]) == 'Repeated subfield' bib.set('651', 'a', 9) assert bib.get_xref('651', 'a') == 9 bib = Bib().set_values( ('245', 'a', 'yet another'), ('245', 'b', 'title'), ('500', 'a', 'desc'), ('500', 'a', 'desc', {'address': ['+']}), ) assert bib.get_values('245', 'a', 'b') == ['yet another', 'title'] assert bib.get_values('500', 'a') == ['desc', 'desc']
def test_merge(): from dlx.marc import Bib bib1 = Bib().set('000', None, 'leader').set('245', 'a', 'Title') bib2 = Bib().set('000', None, '|eade|').set('269', 'a', 'Date') bib1.merge(bib2) assert bib1.get_value('269', 'a') == 'Date' assert bib1.get_value('000') == 'leader'
def test_get_value(bibs): from dlx.marc import Bib bib = Bib(bibs[0]) assert bib.get_value('000') == 'leader' assert bib.get_value('245', 'a') == 'This' assert bib.get_values('245', 'a', 'b') == ['This', 'is the'] assert bib.get_value('520', 'a', address=[1, 1]) == 'Repeated subfield' assert bib.get_values('520', 'a', place=1) == ['Another description', 'Repeated subfield'] assert bib.get_value('999', 'a') == '' assert bib.get_values('999', 'a') == [] assert bib.get_value('245', 'a') == bib.get('245', 'a') assert bib.get_values('520', 'a') == bib.gets('520', 'a')
def test_set_008(bibs): from dlx.marc import Bib from dlx.config import Config import time bib = Bib(bibs[0]) date_tag, date_code = Config.date_field bib.set(date_tag, date_code, '19991231') with pytest.raises(Exception): bib.set('008', None, 'already set') bib.set_008() bib.set('008', None, '') bib.set_008(); assert bib.get_value('008')[0:6] == time.strftime('%y%m%d') assert bib.get_value('008')[7:11] == '1999'