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

test: add remove_files tests #22

Merged
merged 8 commits into from
Aug 7, 2024
Merged
Changes from 1 commit
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
41 changes: 40 additions & 1 deletion tests/decryption/test_decrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
get_private_keys,
decrypt_files,
move_files,
remove_files
remove_files,
get_args
athith-g marked this conversation as resolved.
Show resolved Hide resolved
)
from tests.utils import patch_cli

Expand Down Expand Up @@ -179,3 +180,41 @@ def test_non_directory_path(self, tmp_path):
non_dir_path.touch()
with pytest.raises(ValueError):
remove_files(non_dir_path)


class TestGetArgs:
"""Test get_args."""

def test_get_args(self):
"""Test that the arguments are parsed correctly."""
with patch_cli(["decrypt.py", "--output-dir", "dir", "file.txt"]):
args = get_args()
assert args.output_dir == Path("dir")
assert args.file_paths == [Path("file.txt")]

def test_multiple_files(self):
"""Test that multiple file paths can be passed."""
files = ["file.txt", "file2.txt", "file3.txt"]
with patch_cli(["decrypt.py"] + files):
args = get_args()
assert args.file_paths == [Path(file) for file in files]

def test_default_output_dir(self):
"""Test that output_dir defaults to $TMPDIR when no directory is passed."""
with (patch_cli(["decrypt.py", "file.txt"]),
mock.patch.dict(os.environ, {"TMPDIR": "/mock/tmpdir"})):
args = get_args()
assert args.output_dir == Path("/mock/tmpdir")
assert args.file_paths == [Path("file.txt")]

def test_invalid_argument(self):
"""Test that a system exit occurs when an invalid argument is passed."""
with (patch_cli(["decrypt.py", "--bad-argument", "dir", "file.txt"]),
pytest.raises(SystemExit)):
get_args()

def test_no_file_paths(self):
"""Test that a system exit occurs when no file paths are passed."""
with (patch_cli(["decrypt.py", "--output-dir", "dir"]),
pytest.raises(SystemExit)):
get_args()
You are viewing a condensed version of this merge commit. You can view the full changes here.