Exemple #1
0
    def test_preprocess_xml(self, content):
        xml = etree.fromstring("""
        <CFRGRANULE>
          <PART>
            <APPENDIX>
              <TAG>Other Text</TAG>
              <GPH DEEP="453" SPAN="2">
                <GID>ABCD.0123</GID>
              </GPH>
            </APPENDIX>
          </PART>
        </CFRGRANULE>""")
        content.Macros.return_value = [("//GID[./text()='ABCD.0123']/..", """
              <HD SOURCE="HD1">Some Title</HD>
              <GPH DEEP="453" SPAN="2">
                <GID>EFGH.0123</GID>
              </GPH>""")]
        reg_text.preprocess_xml(xml)
        should_be = etree.fromstring("""
        <CFRGRANULE>
          <PART>
            <APPENDIX>
              <TAG>Other Text</TAG>
              <HD SOURCE="HD1">Some Title</HD>
              <GPH DEEP="453" SPAN="2">
                <GID>EFGH.0123</GID>
              </GPH></APPENDIX>
          </PART>
        </CFRGRANULE>""")

        self.assertEqual(etree.tostring(xml), etree.tostring(should_be))
    def test_preprocess_xml(self, content):
        xml = etree.fromstring("""
        <CFRGRANULE>
          <PART>
            <APPENDIX>
              <TAG>Other Text</TAG>
              <GPH DEEP="453" SPAN="2">
                <GID>ABCD.0123</GID>
              </GPH>
            </APPENDIX>
          </PART>
        </CFRGRANULE>""")
        content.Macros.return_value = [
            ("//GID[./text()='ABCD.0123']/..", """
              <HD SOURCE="HD1">Some Title</HD>
              <GPH DEEP="453" SPAN="2">
                <GID>EFGH.0123</GID>
              </GPH>""")]
        reg_text.preprocess_xml(xml)
        should_be = etree.fromstring("""
        <CFRGRANULE>
          <PART>
            <APPENDIX>
              <TAG>Other Text</TAG>
              <HD SOURCE="HD1">Some Title</HD>
              <GPH DEEP="453" SPAN="2">
                <GID>EFGH.0123</GID>
              </GPH></APPENDIX>
          </PART>
        </CFRGRANULE>""")

        self.assertEqual(etree.tostring(xml), etree.tostring(should_be))
Exemple #3
0
    def test_preprocess_xml(self, content):
        with XMLBuilder("CFRGRANULE") as ctx:
            with ctx.PART():
                with ctx.APPENDIX():
                    ctx.TAG("Other Text")
                    with ctx.GPH(DEEP=453, SPAN=2):
                        ctx.GID("ABCD.0123")
        content.Macros.return_value = [
            ("//GID[./text()='ABCD.0123']/..",
             """<HD SOURCE="HD1">Some Title</HD><GPH DEEP="453" SPAN="2">"""
             """<GID>EFGH.0123</GID></GPH>""")]
        reg_text.preprocess_xml(ctx.xml)

        with XMLBuilder("CFRGRANULE") as ctx2:
            with ctx2.PART():
                with ctx2.APPENDIX():
                    ctx2.TAG("Other Text")
                    ctx2.HD("Some Title", SOURCE="HD1")
                    with ctx2.GPH(DEEP=453, SPAN=2):
                        ctx2.GID("EFGH.0123")
        self.assertEqual(ctx.xml_str, ctx2.xml_str)
    def test_preprocess_xml(self, content):
        with XMLBuilder("CFRGRANULE") as ctx:
            with ctx.PART():
                with ctx.APPENDIX():
                    ctx.TAG("Other Text")
                    with ctx.GPH(DEEP=453, SPAN=2):
                        ctx.GID("ABCD.0123")
        content.Macros.return_value = [
            ("//GID[./text()='ABCD.0123']/..",
             """<HD SOURCE="HD1">Some Title</HD><GPH DEEP="453" SPAN="2">"""
             """<GID>EFGH.0123</GID></GPH>""")]
        reg_text.preprocess_xml(ctx.xml)

        with XMLBuilder("CFRGRANULE") as ctx2:
            with ctx2.PART():
                with ctx2.APPENDIX():
                    ctx2.TAG("Other Text")
                    ctx2.HD("Some Title", SOURCE="HD1")
                    with ctx2.GPH(DEEP=453, SPAN=2):
                        ctx2.GID("EFGH.0123")
        self.assertEqual(ctx.xml_str, ctx2.xml_str)
    def test_preprocess_xml(self, content):
        with self.tree.builder("CFRGRANULE") as root:
            with root.PART() as part:
                with part.APPENDIX() as appendix:
                    appendix.TAG("Other Text")
                    with appendix.GPH(DEEP=453, SPAN=2) as gph:
                        gph.GID("ABCD.0123")
        content.Macros.return_value = [
            ("//GID[./text()='ABCD.0123']/..",
             """<HD SOURCE="HD1">Some Title</HD><GPH DEEP="453" SPAN="2">"""
             """<GID>EFGH.0123</GID></GPH>""")]
        orig_xml = self.tree.render_xml()
        reg_text.preprocess_xml(orig_xml)

        self.setUp()
        with self.tree.builder("CFRGRANULE") as root:
            with root.PART() as part:
                with part.APPENDIX() as appendix:
                    appendix.TAG("Other Text")
                    appendix.HD("Some Title", SOURCE="HD1")
                    with appendix.GPH(DEEP=453, SPAN=2) as gph:
                        gph.GID("EFGH.0123")

        self.assertEqual(etree.tostring(orig_xml), self.tree.render_string())