def test_fix_section_node(self):
        xml = u"""
            <REGTEXT>
            <P>paragraph 1</P>
            <P>paragraph 2</P>
            </REGTEXT>
        """
        reg_paragraphs = etree.fromstring(xml)
        paragraphs = [p for p in reg_paragraphs if p.tag == "P"]

        amdpar_xml = u"""
            <REGTEXT>
                <SECTION>
                    <SECTNO> 205.4 </SECTNO>
                    <SUBJECT>[Corrected]</SUBJECT>
                </SECTION>
                <AMDPAR>
                    3. In § 105.1, revise paragraph (b) to read as follows:
                </AMDPAR>
            </REGTEXT>
        """
        amdpar = etree.fromstring(amdpar_xml)
        par = amdpar.xpath("//AMDPAR")[0]
        section = diff.fix_section_node(paragraphs, par)
        self.assertNotEqual(None, section)
        section_paragraphs = [p for p in section if p.tag == "P"]
        self.assertEqual(2, len(section_paragraphs))

        self.assertEqual(section_paragraphs[0].text, "paragraph 1")
        self.assertEqual(section_paragraphs[1].text, "paragraph 2")
Beispiel #2
0
    def test_fix_section_node(self):
        xml = u"""
            <REGTEXT>
            <P>paragraph 1</P>
            <P>paragraph 2</P>
            </REGTEXT>
        """
        reg_paragraphs = etree.fromstring(xml)
        paragraphs = [p for p in reg_paragraphs if p.tag == 'P']

        amdpar_xml = u"""
            <REGTEXT>
                <SECTION>
                    <SECTNO> 205.4 </SECTNO>
                    <SUBJECT>[Corrected]</SUBJECT>
                </SECTION>
                <AMDPAR>
                    3. In § 105.1, revise paragraph (b) to read as follows:
                </AMDPAR>
            </REGTEXT>
        """
        amdpar = etree.fromstring(amdpar_xml)
        par = amdpar.xpath('//AMDPAR')[0]
        section = diff.fix_section_node(paragraphs, par)
        self.assertNotEqual(None, section)
        section_paragraphs = [p for p in section if p.tag == 'P']
        self.assertEqual(2, len(section_paragraphs))

        self.assertEqual(section_paragraphs[0].text, 'paragraph 1')
        self.assertEqual(section_paragraphs[1].text, 'paragraph 2')
    def test_fix_section_node(self):
        with self.tree.builder("REGTEXT") as regtext:
            regtext.P("paragraph 1")
            regtext.P("paragraph 2")
        paragraphs = [p for p in self.tree.render_xml() if p.tag == 'P']

        with self.tree.builder("REGTEXT") as regtext:
            with regtext.SECTION() as section:
                section.SECTNO(" 205.4 ")
                section.SUBJECT("[Corrected]")
            regtext.AMDPAR(u"3. In § 105.1, revise paragraph (b) to read as "
                           "follows:")
        par = self.tree.render_xml().xpath('//AMDPAR')[0]
        section = diff.fix_section_node(paragraphs, par)
        self.assertNotEqual(None, section)
        section_paragraphs = [p for p in section if p.tag == 'P']
        self.assertEqual(2, len(section_paragraphs))

        self.assertEqual(section_paragraphs[0].text, 'paragraph 1')
        self.assertEqual(section_paragraphs[1].text, 'paragraph 2')