Ejemplo n.º 1
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
Ejemplo n.º 2
0
def test_add_item():
    sec = Section("MAIN_SEC")
    sec.add_item("pkg1")
    sec.add_item("pkg2  # [win]")
    sec.add_item("pkg3")
    assert "pkg1" in sec
    assert "pkg2" in sec
    assert "pkg3" in sec
Ejemplo n.º 3
0
def test_hash():
    commented_map = CommentedMap()
    sec = Section("section1", commented_map)
    assert hash(sec) == hash("section1-[]")
    sec.add_item("item")
    assert hash(sec) == hash("section1-['item']")