def test_move_2(self): """start.tail is correctly copied without keeping boundaries""" template_two_name = pkg_resources.resource_filename( 'py3o.template', 'tests/templates/move_two.xml' ) test_template_two = lxml.etree.parse(template_two_name) start = test_template_two.find('mystruct/start') end = test_template_two.find('mystruct/end') new_ = lxml.etree.Element('finishcontainer') move_siblings(start, end, new_) result_s = lxml.etree.tostring( test_template_two, pretty_print=True, ).decode('utf-8') expected_result = open( pkg_resources.resource_filename( 'py3o.template', 'tests/templates/move_two_result.xml' ) ).read() expected_result = expected_result.replace( '\n', '').replace(' ', '').strip() result_s = result_s.replace('\n', '').replace(' ', '').strip() assert result_s == expected_result
def test_move_1(self): """test that siblings are properly moved without keeping boundaries""" template_one_name = pkg_resources.resource_filename( 'py3o.template', 'tests/templates/move_one.xml' ) test_template_one = lxml.etree.parse(template_one_name) start = test_template_one.find('mystruct/start') end = test_template_one.find('mystruct/end') new_ = lxml.etree.Element("finishcontainer") move_siblings(start, end, new_) result_s = lxml.etree.tostring( test_template_one, pretty_print=True, ).decode('utf-8') expected_result = open( pkg_resources.resource_filename( 'py3o.template', 'tests/templates/move_one_result.xml' ) ).read() expected_result = expected_result.replace( '\n', '').replace(' ', '').strip() result_s = result_s.replace('\n', '').replace(' ', '').strip() assert result_s == expected_result
def test_move_keep_boundaries(self): """test that siblings are properly moved keeping boundaries""" template_three_name = pkg_resources.resource_filename( "py3o.template", "tests/templates/move_three.xml" ) test_template_three = lxml.etree.parse(template_three_name) start = test_template_three.find("mystruct/start") end = test_template_three.find("mystruct/end") new_ = lxml.etree.Element("finishcontainer") move_siblings( start, end, new_, keep_start_boundary=True, keep_end_boundary=True ) result_s = lxml.etree.tostring( test_template_three, pretty_print=True ).decode("utf-8") expected_result = open( pkg_resources.resource_filename( "py3o.template", "tests/templates/move_three_result.xml" ) ).read() expected_result = ( expected_result.replace("\n", "").replace(" ", "").strip() ) result_s = result_s.replace("\n", "").replace(" ", "").strip() assert result_s == expected_result
def test_move_2(self): """start.tail is correctly copied without keeping boundaries""" template_two_name = pkg_resources.resource_filename( "py3o.template", "tests/templates/move_two.xml" ) test_template_two = lxml.etree.parse(template_two_name) start = test_template_two.find("mystruct/start") end = test_template_two.find("mystruct/end") new_ = lxml.etree.Element("finishcontainer") move_siblings(start, end, new_) result_s = lxml.etree.tostring( test_template_two, pretty_print=True ).decode("utf-8") expected_result = open( pkg_resources.resource_filename( "py3o.template", "tests/templates/move_two_result.xml" ) ).read() expected_result = ( expected_result.replace("\n", "").replace(" ", "").strip() ) result_s = result_s.replace("\n", "").replace(" ", "").strip() assert result_s == expected_result
def test_move_siblings_1(self): template_xml = pkg_resources.resource_filename( 'py3o.template', 'tests/templates/move_siblings.xml' ) test_xml = lxml.etree.parse(template_xml) starts, ends = self.reference_template.find_instructions( [test_xml], self.reference_template.namespaces ) assert len(starts) == 1 assert len(ends) == 1 start, _ = starts[0] end = ends[id(start)] keep_start, keep_end = detect_keep_boundary( start, end, self.reference_template.namespaces ) assert keep_start is True assert keep_end is False new_ = lxml.etree.Element('finishcontainer') start_parent = start.getparent() end_parent = end.getparent() start.getparent().remove(start) end.getparent().remove(end) move_siblings( start_parent, end_parent, new_, keep_start_boundary=keep_start, keep_end_boundary=keep_end, ) result_a = lxml.etree.tostring( test_xml, pretty_print=True, ).decode('utf-8') result_e = open( pkg_resources.resource_filename( 'py3o.template', 'tests/templates/move_siblings_result_1.xml' ) ).read() result_a = result_a.replace("\n", "").replace(" ", "") result_e = result_e.replace("\n", "").replace(" ", "") assert result_a == result_e
def test_move_siblings_1(self): template_xml = pkg_resources.resource_filename( 'py3o.template', 'tests/templates/move_siblings.xml' ) test_xml = lxml.etree.parse(template_xml) starts, ends = self.reference_template.handle_instructions( [test_xml], self.reference_template.namespaces ) assert len(starts) == 1 assert len(ends) == 1 start, _ = starts[0] end = ends[id(start)] keep_start, keep_end = detect_keep_boundary( start, end, self.reference_template.namespaces ) assert keep_start is True assert keep_end is False new_ = lxml.etree.Element('finishcontainer') start_parent = start.getparent() end_parent = end.getparent() start.getparent().remove(start) end.getparent().remove(end) move_siblings( start_parent, end_parent, new_, keep_start_boundary=keep_start, keep_end_boundary=keep_end, ) result_a = lxml.etree.tostring( test_xml, pretty_print=True, ).decode('utf-8') result_e = open( pkg_resources.resource_filename( 'py3o.template', 'tests/templates/move_siblings_result_1.xml' ) ).read() result_a = result_a.replace("\n", "").replace(" ", "") result_e = result_e.replace("\n", "").replace(" ", "") assert result_a == result_e