From 989e7461203ad3c248457d21d2740587fdc7d3cb Mon Sep 17 00:00:00 2001 From: Evan Doyle Date: Wed, 7 Feb 2024 19:35:42 -0800 Subject: [PATCH] Update CLI tests --- tests/test_cli.py | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 3f13433e..45f3fba2 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -25,25 +25,20 @@ def mock_isdir(path: str) -> bool: mocker.patch("modguard.cli.os.path.isdir", mock_isdir) -@pytest.fixture -def parser(): - return cli.build_parser() - - -def test_execute_with_valid_dir(capfd, parser, mock_isdir, mock_check): +def test_execute_with_valid_dir(capfd, mock_isdir, mock_check): # Test with a valid path as mocked - args = parser.parse_args(["valid_dir"]) + args = cli.parse_base_arguments(["valid_dir"]) with pytest.raises(SystemExit) as sys_exit: - cli.main(args) + cli.modguard(args) captured = capfd.readouterr() assert sys_exit.value.code == 0 assert "✅" in captured.out assert "All modules safely guarded!" in captured.out -def test_execute_with_error(capfd, parser, mock_isdir, mock_check): +def test_execute_with_error(capfd, mock_isdir, mock_check): # Test with a valid path as mocked - args = parser.parse_args(["valid_dir"]) + args = cli.parse_base_arguments(["valid_dir"]) # Mock an error returned from check location = "valid_dir/file.py" message = "Import valid_dir in valid_dir/file.py is blocked by boundary" @@ -53,40 +48,40 @@ def test_execute_with_error(capfd, parser, mock_isdir, mock_check): ) ] with pytest.raises(SystemExit) as sys_exit: - cli.main(args) + cli.modguard(args) captured = capfd.readouterr() assert sys_exit.value.code == 1 assert location in captured.err assert message in captured.err -def test_execute_with_invalid_dir(capfd, mock_isdir, parser): +def test_execute_with_invalid_dir(capfd, mock_isdir): # Test with an invalid path as mocked - args = parser.parse_args(["invalid_dir"]) + args = cli.parse_base_arguments(["invalid_dir"]) with pytest.raises(SystemExit) as sys_exit: - cli.main(args) + cli.modguard(args) captured = capfd.readouterr() assert sys_exit.value.code == 1 assert "invalid_dir is not a valid directory" in captured.err -def test_execute_with_valid_exclude(capfd, parser, mock_isdir, mock_check): +def test_execute_with_valid_exclude(capfd, mock_isdir, mock_check): # Test with a valid path as mocked - args = parser.parse_args(["valid_dir", "--exclude", "valid_dir"]) + args = cli.parse_base_arguments(["valid_dir", "--exclude", "valid_dir"]) with pytest.raises(SystemExit) as sys_exit: - cli.main(args) + cli.modguard(args) captured = capfd.readouterr() assert sys_exit.value.code == 0 assert "✅" in captured.out assert "All modules safely guarded!" in captured.out -def test_execute_with_invalid_exclude(capfd, parser, mock_isdir): +def test_execute_with_invalid_exclude(capfd, mock_isdir): # Test with a valid path as mocked - args = parser.parse_args(["valid_dir", "--exclude", "invalid_dir"]) + args = cli.parse_base_arguments(["valid_dir", "--exclude", "invalid_dir"]) # Mock a valid return from check with pytest.raises(SystemExit) as sys_exit: - cli.main(args) + cli.modguard(args) captured = capfd.readouterr() assert sys_exit.value.code == 1 assert "invalid_dir is not a valid dir or file" in captured.err