Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_getters(self):
leader = Leader(LEADER)
for field, index, expected in FIELDS:
self.assertEqual(getattr(leader, field), leader[index])
self.assertEqual(expected, leader[index])
def test_add(self):
leader = Leader(LEADER)
new_leader = leader[0:9] + "b" + leader[10:]
self.assertEqual(new_leader, "00475casab2200169 ib4500")
def test_leader_invalid_length(self):
self.assertRaises(RecordLeaderInvalid, Leader, LEADER[:-1])
def test_str(self):
leader = Leader(LEADER)
self.assertEqual(str(leader), LEADER)
def test_leader_value(self):
leader = Leader(LEADER)
self.assertEqual(leader.leader, LEADER)
def test_setters_errors(self):
leader = Leader(LEADER)
for field, index, expected in FIELDS:
value = random_string(len(expected) + 1)
with self.assertRaises(BadLeaderValue):
setattr(leader, field, value)
def test_setters(self):
leader = Leader(LEADER)
for field, index, expected in FIELDS:
value = random_string(len(expected))
leader[index] = value
self.assertEqual(getattr(leader, field), value)
value = random_string(len(expected))
setattr(leader, field, value)
self.assertEqual(leader[index], value)
def __init__(
self,
data="",
to_unicode=True,
force_utf8=False,
hide_utf8_warnings=False,
utf8_handling="strict",
leader=" " * LEADER_LEN,
file_encoding="iso8859-1",
):
"""Initialize a Record."""
self.leader = Leader(leader[0:10] + "22" + leader[12:20] + "4500")
self.fields = list()
self.pos = 0
self.force_utf8 = force_utf8
if len(data) > 0:
self.decode_marc(
data,
to_unicode=to_unicode,
force_utf8=force_utf8,
hide_utf8_warnings=hide_utf8_warnings,
utf8_handling=utf8_handling,
encoding=file_encoding,
)
elif force_utf8:
self.leader = self.leader[0:9] + "a" + self.leader[10:]