Skip to content

Commit

Permalink
Add utility to test actions
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz committed Aug 7, 2023
1 parent 958f29a commit cd22785
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/outpack/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pathlib import Path


def find_file_descend(filename, path):
path = Path(path)
root = Path(path.root)

while path != root:
attempt = path / filename
if attempt.exists():
return str(attempt.parent)
path = path.parent

return None
8 changes: 8 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from outpack.util import find_file_descend


def test_find_descend(tmp_path):
(tmp_path / "a" / "b" / "c" / "d").mkdir(parents=True)
(tmp_path / "a" / "b" / ".foo").mkdir(parents=True)
assert find_file_descend(".foo", tmp_path / "a/b/c/d") == str(tmp_path / "a/b")
assert find_file_descend(".foo", tmp_path / "a") is None

0 comments on commit cd22785

Please sign in to comment.