Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: YAML parser to read the checklist items #60

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies:
- python-dotenv=1.0.1
- fire=0.6.0
- langchain=0.1.16
- ruamel.yaml=0.18.6
tonyshumlh marked this conversation as resolved.
Show resolved Hide resolved
- pip:
- distro==1.9.0
- h11==0.14.0
Expand Down
Empty file added src/checklist/__init__.py
Empty file.
51 changes: 51 additions & 0 deletions src/checklist/checklist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import os
from typing import Union

import fire
from ruamel.yaml import YAML


class Checklist:
tonyshumlh marked this conversation as resolved.
Show resolved Hide resolved
def __init__(self, checklist_path: str):
if not os.path.exists(checklist_path):
raise FileNotFoundError("Checklist file not found.")
try:
with open(checklist_path, "r") as f:
self.content = YAML(typ="safe").load(f)
self.test_areas = set([x["Topic"] for x in self.content["Test Areas"]])
except Exception as e:
raise SyntaxError("Failed to parse the checklist. Make sure that it is a YAML 1.2 document.")

def get_tests_by_areas(self, areas: Union[list, str, set], requirements_only: bool = False):
tests = []

if isinstance(areas, str):
areas = [areas]
areas_set = set(areas)
if not areas_set.issubset(self.test_areas):
raise KeyError("The provided areas has one or more items that is not present in the checklist.")

areas = [ x for x in self.content["Test Areas"] if x["Topic"] in areas ]
for area in areas:
if requirements_only:
tests += [x.get("Requirement") for x in area["Tests"]]
else:
tests += area["Tests"]
return tests

def get_all_tests(self, requirements_only: bool = False):
return self.get_tests_by_areas(self.test_areas, requirements_only)

def get_test_areas(self):
return self.test_areas


if __name__ == "__main__":
def example(checklist_path: str):
"""Example calls. To be removed later."""
checklist = Checklist(checklist_path)
# tests = checklist.get_tests_by_areas("General", requirements_only=False)
tests = checklist.get_all_tests()
print(tests)

fire.Fire(example)