Esempio n. 1
0
def test_reduce_section():
    commented_map = CommentedMap({})
    sec = Section("section", commented_map)
    sec.add_items(["item", None])
    sec.values[0].selector = "# [win]"
    assert sec.values == ["item", None]
    assert sec._get_parent()[sec.section_name] == ["item", None]

    sec.reduce_section()
    assert sec._get_parent()[sec.section_name] == "item"
    assert sec.values == ["item"]
Esempio n. 2
0
 def populate_metadata_from_dict(self, metadata: Any,
                                 section: Section) -> Section:
     if not isinstance(metadata, bool) and not metadata:
         return section
     if isinstance(metadata, list):
         section.add_items(metadata)
         return section
     if isinstance(metadata, dict):
         for name, value in metadata.items():
             if isinstance(value, bool) or value:
                 self.populate_metadata_from_dict(
                     value, Section(name, section.yaml_obj))
     else:
         section.add_item(metadata)
     return section