Пример #1
0
def assert_equals_file_content(reference_file, fixture, filetype='xml'):
    if os.path.isfile(fixture):
        with open(fixture) as fixture_file:
            fixture_content = fixture_file.read()
    else:
        fixture_content = fixture

    with open(reference_file) as expected_file:
        expected_content = expected_file.read()

    if filetype == 'xml':
        fixture_content = fromstring(fixture_content)
        pretty_indent(fixture_content)
        temp = StringIO()
        ElementTree(fixture_content).write(temp)
        fixture_content = temp.getvalue()

        expected_content = fromstring(expected_content)
        pretty_indent(expected_content)
        temp = StringIO()
        ElementTree(expected_content).write(temp)
        expected_content = temp.getvalue()

    fixture_lines = fixture_content.split('\n')
    expected_lines = expected_content.split('\n')
    differences = list(difflib.unified_diff(expected_lines, fixture_lines))
    if differences:
        temp = StringIO()
        pprint(differences, stream=temp)
        assert False, 'Differences found : %s' % temp.getvalue()
Пример #2
0
def get_xml(xml_node):

    io = BytesIO()
    if version_info[0] >= 3 and version_info[1] >= 2:
        ElementTree(xml_node).write(io, encoding='UTF-8', xml_declaration=True)
        ret = str(io.getvalue(), 'utf-8')
        ret = ret.replace('utf-8', 'UTF-8', 1)
    else:
        ElementTree(xml_node).write(io, encoding='UTF-8')
        ret = io.getvalue()
    io.close()
    return ret.replace('\n', '')
Пример #3
0
def get_xml(xml_node):

    io = StringIO()
    ElementTree(xml_node).write(io, encoding='UTF-8')
    ret = io.getvalue()
    io.close()
    return ret.replace('\n', '')