Skip to content

Commit

Permalink
Prompt when input directory is empty
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Chang <[email protected]>
  • Loading branch information
mocsharp committed Jan 14, 2025
1 parent 7628e6c commit 2406687
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
"Typing :: Typed",
]
version = "0.0.0"

# [tool.poetry.build]
# script = "build.py"
# generate-setup-file = false
version = "0.0.0"

[tool.poetry.dependencies]
python = ">=3.9,<3.13"
Expand Down
4 changes: 4 additions & 0 deletions src/holoscan_cli/common/argparse_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ def valid_existing_path(path: str) -> Path:
path = os.path.expanduser(path)
file_path = Path(path).absolute()
if file_path.exists():
if os.path.isdir(file_path):
if os.listdir(path):
return file_path
raise argparse.ArgumentTypeError(f"No such file/folder: '{file_path}'")
return file_path
raise argparse.ArgumentTypeError(f"No such file/folder: '{file_path}'")

Expand Down
14 changes: 14 additions & 0 deletions tests/unit/common/test_argparse_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ def test_existing_path_not_exists(self, monkeypatch):
with pytest.raises(argparse.ArgumentTypeError):
valid_existing_path("this/is/some/path")

def test_empty_directory(self, monkeypatch):
monkeypatch.setattr(pathlib.Path, "exists", lambda x: True)
monkeypatch.setattr(os.path, "isdir", lambda x: True)
monkeypatch.setattr(os, "listdir", lambda x: [])
with pytest.raises(argparse.ArgumentTypeError):
valid_existing_path("this/is/some/path")

def test_non_empty_directory(self, monkeypatch):
monkeypatch.setattr(pathlib.Path, "exists", lambda x: True)
monkeypatch.setattr(os.path, "isdir", lambda x: True)
monkeypatch.setattr(os, "listdir", lambda x: ["/a"])
result = valid_existing_path("this/is/some/path")
assert type(result) is PosixPath


class TestValidPlatforms:
@pytest.mark.parametrize(
Expand Down

0 comments on commit 2406687

Please sign in to comment.