def test_cool_list_and_dict(self): """Bibfield Utils, CoolList and CoolDict - Unit tests""" d = CoolDict() l = CoolList() d['a'] = l self.assertTrue(d.consumed) l.append(1) l.append(2) d['a'] = l self.assertFalse(d.consumed) d['b'] = CoolList([{'a':1}, {'a':2}]) self.assertFalse(d.consumed) [v for dummy_k, v in d.iteritems()] self.assertFalse(d.consumed) [i for i in d['a']] [v for i in d['b'] for dummy_k, v in i.iteritems()] self.assertTrue(d.consumed)
def test_cool_list_and_dict(self): """Bibfield Utils, CoolList and CoolDict - Unit tests""" d = CoolDict() l = CoolList() d['a'] = l self.assertTrue(d.consumed) l.append(1) l.append(2) d['a'] = l self.assertFalse(d.consumed) d['b'] = CoolList([{'a': 1}, {'a': 2}]) self.assertFalse(d.consumed) [v for dummy_k, v in d.iteritems()] self.assertFalse(d.consumed) [i for i in d['a']] [v for i in d['b'] for dummy_k, v in i.iteritems()] self.assertTrue(d.consumed)
def test_cool_list(self): """Bibfield Utils, CoolList - Unit tests""" ll = CoolList() ll.append(1) ll.append(2) ll.append(3) self.assertFalse(ll.consumed) ll[1] self.assertEqual(ll._consumed, [False, True, False]) self.assertFalse(ll.consumed) [i for i in ll] self.assertTrue(ll.consumed) ll[1] = [4, 5, 6] self.assertFalse(ll.consumed) self.assertEqual(ll._consumed, [True, [False, False, False], True]) [i for i in ll] self.assertFalse(ll.consumed) self.assertEqual(ll._consumed, [True, [False, False, False], True]) ll[1] self.assertFalse(ll.consumed) [i for i in ll[1]] self.assertTrue(ll.consumed)
def __create_rectree_from_recstruct(self): """ Using rectruct as base format it creates the intermediate structure that _translate will use. """ for key, values in self.blob_wrapper.blob.iteritems(): if key < '010' and key.isdigit(): #Control field, it assumes controlfields are numeric only self.rec_tree[key] = CoolList([value[3] for value in values]) else: for value in values: field = CoolDict() for subfield in value[0]: field.extend(subfield[0], subfield[1]) self.rec_tree.extend( (key + value[1] + value[2]).replace(' ', '_'), field)