Skip to content

Commit

Permalink
TST/DOC: add tests and docstring for OnyoRepo.validate_anchors()
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasKadelka committed Jul 27, 2023
1 parent a236ff2 commit c197626
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 6 additions & 2 deletions onyo/lib/onyo.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,12 @@ def get_template_file(self,

def validate_anchors(self) -> bool:
"""
Check if all dirs (except those in .onyo) contain an .anchor file.
Returns True or False.
Check if all dirs (except those in `.onyo/`) contain an .anchor file.
Returns
-------
boolean
True if all directories contain an `.anchor` file, otherwise False.
"""
# Note: First line not using protected_paths, because `.anchor` is part
# of it. But ultimately, exist vs expected should take the same
Expand Down
19 changes: 19 additions & 0 deletions onyo/lib/tests/test_onyo.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,22 @@ def test_Repo_get_template_file(repo: OnyoRepo) -> None:
# does not exist
with pytest.raises(ValueError):
repo.get_template_file('I DO NOT EXIST')


@pytest.mark.repo_dirs('a/test/directory/structure/',
'another/dir/')
def test_Repo_validate_anchors(repo: OnyoRepo) -> None:
"""
`OnyoRepo.validate_anchors()` must return True when all existing directories
have an `.anchor` file, and otherwise False.
"""
# Must be true for valid repository
assert repo.validate_anchors()

# Delete an .anchor, commit changes, reload object
Path.unlink(repo.git.root / "a" / "test" / ".anchor")
repo.git.stage_and_commit(repo.git.root / "a" / "test" / ".anchor", "TEST")
repo = OnyoRepo(repo.git.root)

# Must return False, because an .anchor is missing
assert not repo.validate_anchors()

0 comments on commit c197626

Please sign in to comment.