unit test

This commit is contained in:
Jesse Bannon 2023-09-21 22:58:48 -07:00
parent a9fa2a5bf6
commit 563642eb35
2 changed files with 18 additions and 2 deletions

View file

@ -223,9 +223,10 @@ class Logger:
logger.error(str(exception))
# Log permission errors explicitly
elif isinstance(exception, PermissionError):
logger.error("A permission error occurred:\n%s", str(exception))
logger.error(
"The user running ytdl-sub must have permission to this file/directory."
"A permission error occurred:\n%s\n"
"The user running ytdl-sub must have permission to this file/directory.",
str(exception),
)
# For other uncaught errors, log as bug:
else:

View file

@ -69,6 +69,21 @@ def test_main_uncaught_error(capsys, mock_sys_exit, expected_uncaught_error_mess
assert mock_error.call_args.args[2] == Logger.debug_log_filename()
def test_main_permission_error(capsys, mock_sys_exit, expected_uncaught_error_message):
permission_error = PermissionError("test")
with mock_sys_exit(expected_exit_code=1), patch(
"src.ytdl_sub.main._main", side_effect=permission_error
), patch.object(logging.Logger, "error") as mock_error:
main()
assert mock_error.call_count == 1
assert mock_error.call_args.args[0] == (
"A permission error occurred:\n%s\n"
"The user running ytdl-sub must have permission to this file/directory."
)
assert mock_error.call_args.args[1] == "test"
def test_args_after_sub_work(mock_sys_exit):
with mock_sys_exit(expected_exit_code=0), patch.object(
sys,