Skip to content

Commit

Permalink
Use os.scandir for sol
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 bba087f commit 63253ee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/holoscan_cli/common/argparse_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +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(file_path):
if file_path.is_dir():
if any(os.scandir(file_path)):
return file_path
raise argparse.ArgumentTypeError(f"No such file/folder: '{file_path}'")
raise argparse.ArgumentTypeError(f"Directory is empty: '{file_path}'")
return file_path
raise argparse.ArgumentTypeError(f"No such file/folder: '{file_path}'")

Expand Down
8 changes: 4 additions & 4 deletions tests/unit/common/test_argparse_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ def test_existing_path_not_exists(self, monkeypatch):

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: [])
monkeypatch.setattr(pathlib.Path, "is_dir", lambda x: True)
monkeypatch.setattr(os, "scandir", 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"])
monkeypatch.setattr(pathlib.Path, "is_dir", lambda x: True)
monkeypatch.setattr(os, "scandir", lambda x: ["file"])
result = valid_existing_path("this/is/some/path")
assert type(result) is PosixPath

Expand Down

0 comments on commit 63253ee

Please sign in to comment.