def test_toc_sect_appendix(self): data = {'title': u'§ 1026.1 - Authority', 'index': ['1026', '1']} result = toc.toc_sect_appendix(data, []) self.assertEqual(u'1026.1', result['label']) self.assertEqual('Authority', result['sub_label']) self.assertTrue(result['is_section']) data = {'title': u'§ 1026.1 [Reserved]', 'index': ['1026', '1']} result = toc.toc_sect_appendix(data, []) self.assertEqual(u'1026.1', result['label']) self.assertEqual('[Reserved]', result['sub_label']) self.assertTrue(result['is_section']) data = {'title': u'Appendix A', 'index': ['1026', 'A']} result = toc.toc_sect_appendix(data, []) self.assertEqual('Appendix A', result['label']) self.assertTrue(result['is_first_appendix']) self.assertTrue(result['is_appendix']) data = {'title': u'Appendix B [Reserved]', 'index': ['1026', 'A']} result = toc.toc_sect_appendix(data, []) self.assertEqual('Appendix B', result['label']) self.assertEqual('[Reserved]', result['sub_label']) self.assertTrue(result['is_first_appendix']) self.assertTrue(result['is_appendix']) data = {'title': u'Appendix B [Reserved]', 'index': ['1026', 'A']} result = toc.toc_sect_appendix(data, [{'is_appendix': True}]) self.assertEqual('Appendix B', result['label']) self.assertEqual('[Reserved]', result['sub_label']) self.assertFalse(result['is_first_appendix']) self.assertTrue(result['is_appendix'])
def apply_layer(self, text_index): if text_index in self.layer: layer_elements = self.layer[text_index] toc_list = [] for data in layer_elements: if 'Subpart' in data['index']: toc_list.append(toc_subpart(data, toc_list, self.layer)) elif 'Interp' in data['index']: toc_list.append(toc_interp(data, toc_list, self.layer)) else: toc_list.append(toc_sect_appendix(data, toc_list)) for el in toc_list: el['url'] = self.section_url.fetch(el['index'], self.version, self.sectional) for sub in el.get('sub_toc', []): sub['url'] = self.section_url.fetch( sub['index'], self.version, self.sectional) return ('TOC', toc_list)
def apply_layer(self, text_index): if text_index in self.layer: layer_elements = self.layer[text_index] toc_list = [] for data in layer_elements: if 'Subpart' in data['index']: toc_list.append(toc_subpart(data, toc_list, self.layer)) elif 'Interp' in data['index']: toc_list.append(toc_interp(data, toc_list, self.layer)) else: toc_list.append(toc_sect_appendix(data, toc_list)) for el in toc_list: el['url'] = self.section_url.fetch( el['index'], self.version, self.sectional) for sub in el.get('sub_toc', []): sub['url'] = self.section_url.fetch( sub['index'], self.version, self.sectional) return ('TOC', toc_list)
def attach_metadata(self, node): text_index = node['label_id'] if text_index in self.layer: layer_elements = self.layer[text_index] toc_list = [] for data in layer_elements: if 'Subpart' in data['index']: toc_list.append(toc_subpart(data, toc_list, self.layer)) elif 'Interp' in data['index']: toc_list.append(toc_interp(data, toc_list, self.layer)) else: toc_list.append(toc_sect_appendix(data, toc_list)) for el in toc_list: el['url'] = self.section_url.fetch( el['index'], self.version, self.sectional) for sub in el.get('sub_toc', []): sub['url'] = self.section_url.fetch( sub['index'], self.version, self.sectional) node['TOC'] = toc_list