예제 #1
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
예제 #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
예제 #3
0
 def __getitem__(self, item: str) -> Any:
     if item in self.ALL_SECTIONS:
         if self._yaml.get(item) is None:
             self._yaml[item] = CommentedMap()
         return Section(item, parent_yaml=self._yaml)
     else:
         raise KeyError(f"Section {item} not found.")
예제 #4
0
def test_section_children():
    commented_map = CommentedMap({
        "section1":
        CommentedMap({"subsection1": CommentedMap({"subsection2": "item"})})
    })
    sec = Section("section1", parent_yaml=commented_map)
    assert sec.section_name == "section1"
    assert sec.values[0].section_name == "subsection1"
예제 #5
0
def test_section_yaml_obj():
    commented_map = CommentedMap(
        {"section1": {
            "subsection1": {
                "subsection2": "item"
            }
        }})
    sec = Section("MAIN_SECTION", parent_yaml=commented_map)
    assert sec.yaml_obj == commented_map.update({"MAIN_SECTION": None})
예제 #6
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"]
예제 #7
0
def test_repr():
    commented_map = CommentedMap(
        {"section1": {
            "subsection1": {
                "subsection2": "item"
            }
        }})
    sec = Section("section1", commented_map)
    assert repr(
        sec) == "Section(section_name=section1, subsection=['subsection1'])"
예제 #8
0
def test_section_load():
    commented_map = CommentedMap(
        {"section1": {
            "subsection1": {
                "subsection2": "item"
            }
        }})
    sec = Section("section1", commented_map)
    assert sec.section_name == "section1"
    assert sec["subsection1"].section_name == "subsection1"
    assert sec["subsection1"]["subsection2"].section_name == "subsection2"
    assert sec["subsection1"]["subsection2"][0].value == "item"
예제 #9
0
 def __init__(self, name=None, version=None, load_recipe: str = ""):
     if load_recipe:
         with open(load_recipe, "r") as yaml_file:
             self._yaml = yaml.load(yaml_file)
     else:
         self._yaml = yaml.load(f'{{% set name = "{name}" %}}\n'
                                "package:\n    name: {{ name|lower }}\n")
         for section in self.ALL_SECTIONS[1:]:
             Section(section, self._yaml)
         if version:
             self.add_jinja_var("version", version, quote=True)
             self["package"]["version"] = "<{ version }}"
         self["build"]["number"] = 0
         self.__files_copy: List = []
         self.update_all_recipe()
     super(AbstractRecipeModel, self).__init__()
예제 #10
0
 def __reduce_list(self, name, recipe: CommentedMap):
     for section in Section(name, recipe):
         if section == "entry_points":
             continue
         section.reduce_section()
예제 #11
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']")
예제 #12
0
def test_str():
    commented_map = CommentedMap()
    sec = Section("section1", commented_map)
    assert str(sec) == "section1"
예제 #13
0
def test_add_subsection():
    sec = Section("MAIN_SEC")
    sec.add_subsection("SUBSECTION")
    assert "SUBSECTION" in sec
    assert sec.section_name == "MAIN_SEC"
예제 #14
0
 def __reduce_list(self, name, recipe: CommentedMap):
     for section in Section(name, recipe):
         section.reduce_section()