def test_attach_metadata_interp_emptysubpart(self):
        toc = TableOfContentsLayer({'100': [
            {'title': u'§ 100.1 Intro', 'index': ['100', '1']},
            {'title': u'§ 100.2 Second', 'index': ['100', '2']},
            {'title': 'Supplement I', 'index': ['100', 'Interp']}]})
        node = {'label_id': '100'}
        toc.attach_metadata(node)
        self.assertEqual(3, len(node['TOC']))
        s1, s2, interp = node['TOC']
        self.assertEqual(1, len(interp['sub_toc']))
        nosubpart = interp['sub_toc'][0]
        self.assertEqual('Regulation Text', nosubpart['label'])
        self.assertEqual(['100', 'Subpart', 'Interp'], nosubpart['index'])

        toc = TableOfContentsLayer({'100': [
            {'title': u'§ 100.1 Intro', 'index': ['100', '1']},
            {'title': u'§ 100.2 Second', 'index': ['100', '2']},
            {'title': 'Appendix A', 'index': ['100', 'A']},
            {'title': 'Appendix C', 'index': ['100', 'C']},
            {'title': 'Supplement I', 'index': ['100', 'Interp']}]})
        toc.attach_metadata(node)
        self.assertEqual(5, len(node['TOC']))
        s1, s2, appA, appC, interp = node['TOC']
        self.assertEqual(2, len(interp['sub_toc']))
        nosubpart, appendices = interp['sub_toc']
        self.assertEqual('Regulation Text', nosubpart['label'])
        self.assertEqual(['100', 'Subpart', 'Interp'], nosubpart['index'])
        self.assertEqual('Appendices', appendices['label'])
        self.assertEqual(['100', 'Appendices', 'Interp'], appendices['index'])
예제 #2
0
    def test_attach_metadata_url(self):
        toc = TableOfContentsLayer({'100': [
            {'title': u'§ 100.1 Intro', 'index': ['100', '1']}]})

        node = {'label_id': '100'}
        toc.attach_metadata(node)
        self.assertEqual('#100-1', node['TOC'][0]['url'])

        toc.sectional = True
        toc.version = 'verver'
        toc.attach_metadata(node)
        self.assertTrue('100-1/verver#100-1' in node['TOC'][0]['url'])
예제 #3
0
    def test_attach_metadata_first_appendix(self):
        toc = TableOfContentsLayer({'100': [
            {'title': 'Appendix A', 'index': ['100', 'A']},
            {'title': 'Appendix B', 'index': ['100', 'B']},
            {'title': 'Appendix C', 'index': ['100', 'C']},
            {'title': 'Supplement I', 'index': ['100', 'Interp']}]})
        node = {'label_id': '100'}
        toc.attach_metadata(node)
        self.assertEqual(4, len(node['TOC']))
        aA, aB, aC, sI = node['TOC']
        self.assertTrue(aA['is_first_appendix'])
        self.assertFalse(aB['is_first_appendix'])
        self.assertFalse(aC['is_first_appendix'])
        self.assertFalse(sI.get('is_first_appendix', False))

        toc = TableOfContentsLayer({'100': [
            {'title': 'Supplement I', 'index': ['100', 'Interp']}]})
        toc.attach_metadata(node)
        self.assertEqual(1, len(node['TOC']))
        self.assertFalse(node['TOC'][0].get('is_first_appendix', False))
예제 #4
0
    def test_attach_metadata_compatibility(self):
        toc = TableOfContentsLayer({'100': [
            {'title': u'§ 100.1 Intro', 'index': ['100', '1']},
            {'title': 'Appendix A', 'index': ['100', 'A']},
            {'title': 'Supplement I', 'index': ['100', 'Interp']}]})
        node = {'label_id': '100'}
        toc.attach_metadata(node)
        self.assertEqual(3, len(node['TOC']))

        toc = TableOfContentsLayer({
            '100': [
                {'title': 'Subpart A', 'index': ['100', 'Subpart', 'A']},
                {'title': 'Appendix A', 'index': ['100', 'A']},
                {'title': 'Supplement I', 'index': ['100', 'Interp']}],
            '100-Subpart-A': [
                {'title': u'§ 100.1 Intro', 'index': ['100', '1']},
                {'title': u'§ 100.2 Sec2', 'index': ['100', '2']},
                {'title': u'§ 100.3 Sec3', 'index': ['100', '3']}]
            })
        toc.attach_metadata(node)
        self.assertEqual(3, len(node['TOC']))
        self.assertEqual(3, len(node['TOC'][0]['sub_toc']))
예제 #5
0
    def test_attach_metadata_interp_subparts(self):
        toc = TableOfContentsLayer({
            '100': [
                {'title': 'Subpart A', 'index': ['100', 'Subpart', 'A']},
                {'title': 'Supplement I', 'index': ['100', 'Interp']}],
            '100-Subpart-A': [
                {'title': u'§ 100.1 Intro', 'index': ['100', '1']},
                {'title': u'§ 100.2 Second', 'index': ['100', '2']}]})
        node = {'label_id': '100'}
        toc.attach_metadata(node)
        self.assertEqual(2, len(node['TOC']))
        subpartA, interp = node['TOC']
        self.assertEqual(2, len(subpartA['sub_toc']))
        self.assertEqual(1, len(interp['sub_toc']))
        nosubpart = interp['sub_toc'][0]
        self.assertEqual('Subpart A', nosubpart['label'])
        self.assertEqual(['100', 'Subpart', 'A', 'Interp'], nosubpart['index'])

        toc = TableOfContentsLayer({
            '100': [
                {'title': 'Subpart A', 'index': ['100', 'Subpart', 'A']},
                {'title': 'Appendix A', 'index': ['100', 'A']},
                {'title': 'Appendix C', 'index': ['100', 'C']},
                {'title': 'Supplement I', 'index': ['100', 'Interp']}],
            '100-Subpart-A': [
                {'title': u'§ 100.1 Intro', 'index': ['100', '1']},
                {'title': u'§ 100.2 Second', 'index': ['100', '2']}]})
        node = {'label_id': '100'}
        toc.attach_metadata(node)
        self.assertEqual(4, len(node['TOC']))
        subpartA, appA, appC, interp = node['TOC']
        self.assertEqual(2, len(interp['sub_toc']))
        nosubpart, appendices = interp['sub_toc']
        self.assertEqual('Subpart A', nosubpart['label'])
        self.assertEqual(['100', 'Subpart', 'A', 'Interp'], nosubpart['index'])
        self.assertEqual('Appendices', appendices['label'])
        self.assertEqual(['100', 'Appendices', 'Interp'], appendices['index'])