def unserialize(document_container, root_structure=None): def construct_hierarchy(current_object, current_object_args, document_container): if 'children' in current_object_args: for child in current_object_args['children']: class_name = child.keys()[0] class_args = child.values()[0] if class_name == 'UIStructure': document_name = class_args['name'] document_root = getattr(document_container, document_name) structure = read_yaml(document_root) root_object = structure.items()[0] class_name = root_object[0] class_args = root_object[1] class_instance = globals()[class_name](**class_args) current_object.append(class_instance) construct_hierarchy(class_instance, class_args, document_container) document_root = root_structure or document_container.root_structure structure = read_yaml(document_root) root_object_name = structure.keys()[0] root_object_args = structure.values()[0] root_object = globals()[root_object_name](**root_object_args) construct_hierarchy(root_object, root_object_args, document_container) return root_object
def test_read_structure_with_tabs(): structure_content = read_yaml(structure_with_tabs) assert structure_content == { 'some_item': { 'children': ['other_item', 'third_item'] } }
def test_read_valid_file(): file_content = read_yaml('valid.yaml') assert file_content == { 'a': 1, 'b': { 'c': 5, 'd': 4, }, }, 'This test fails if it is run at some other directory than in which the test is!'
def construct_key_event_ids(self, hotkeys, key_mapping=None): def append_key_event(key, func_name, event): if hasattr(self.events, func_name): event_func = getattr(self.events, func_name) self.key_events.append(key, event_func, event) keys_structure = read_yaml(hotkeys) if isinstance(keys_structure, dict): for key, value in keys_structure.items(): if key_mapping and key in key_mapping: key = key_mapping[key] elif len(key) == 1: key = ord(key) if isinstance(value, dict): for event, func_name in value.items(): append_key_event(key, func_name, event) else: append_key_event(key, value, 'press')
def parse_configuration(self, configuration): parsed_configuration = read_yaml(configuration) for item, value in parsed_configuration.items(): if item in self.__dict__: self.__dict__[item] = value
def test_read_invalid_file(): file_content = read_yaml('foo.yaml') assert file_content == {}
def test_read_non_file_structure(): structure_content = read_yaml(structure_with_one_item) assert structure_content == [{'some_item': None}]
def test_read_empty_structure(): structure_content = read_yaml('') assert structure_content == {}