import pytest from collections import OrderedDict from calculate.templates.format.xml_gconf_format import XMLGConfFormat @pytest.mark.xml_gconf class TestParsingMethods: def test_if_input_document_is_simple_gconf_tree__the_format_object_contains_correct_dictionary(self): document_text = ''' Something I can never have. True if the command used to handle this type of URL should be run in a terminal. distributor ''' result = OrderedDict({('', 'gconf'): OrderedDict({('', 'dir', ('name', 'gnome')): OrderedDict({('', 'dir', ('name', 'ymsgr')): OrderedDict({('', 'entry', ('name', 'needs_terminal')): OrderedDict({('', 'default', ('type', 'string')): OrderedDict({('', 'stringvalue'): 'Something I can never have.'}), ('', 'local_schema', ('short_desc', 'Run the command in a terminal')): OrderedDict({('', 'longdesc'): 'True if the command used to handle this type of URL should be run in a terminal.'})}), ('', 'entry', ('name', 'logo_icon_name'), ('mtime', '1342486180'), ('type', 'string')): OrderedDict({('', 'stringvalue'): 'distributor'})})})})}) xml_gconf_object = XMLGConfFormat(document_text) assert xml_gconf_object._document_dictionary == result def test_if_input_document_is_simple_gconf__the_format_object_contains_correct_dictionary(self): document_text = '''
  • grp grp:lwin_toggle
  • us
  • ru
  • full
    ''' result = OrderedDict({('', 'gconf'): OrderedDict({('', 'entry', ('name', 'options'), ('mtime', '1298136657'), ('type', 'list'), ('ltype', 'string')): ['grp grp:lwin_toggle'], ('', 'entry', ('name', 'layouts'), ('mtime', '1298136657'), ('type', 'list'), ('ltype', 'string')): ['us', 'ru'], ('', 'entry', ('name', 'hinting'), ('mtime', '1298136657'), ('type', 'list')): OrderedDict({('', 'stringvalue'): 'full'})})}) xml_gconf_object = XMLGConfFormat(document_text) assert xml_gconf_object._document_dictionary == result def test_joining_documents_1(self): with open('./tests/format/testfiles/xml_gconf_original.xml', 'r') as original_file: original_text = original_file.read() xml_gconf_original_object = XMLGConfFormat(original_text) with open('./tests/format/testfiles/xml_gconf_template.xml', 'r') as template_file: template_text = template_file.read() xml_gconf_template_object = XMLGConfFormat(template_text) xml_gconf_original_object.join_template(xml_gconf_template_object) with open('./tests/format/testfiles/xml_gconf_result.xml', 'r') as result_file: result_text = result_file.read() assert xml_gconf_original_object.get_document_text() == result_text