def test_file_checker_no_path(mock_exit, mock_echo): """Test the file check informs about console output if no file is given.""" cli._file_checker("subject", None) assert mock_echo.call_count == 1 assert "subject will be output to console." in mock_echo.call_args[0] assert mock_exit.call_count == 0
def test_file_checker(mock_exit, mock_echo, mock_exists): """Test the file checker perform the required checks and prints info.""" mock_exists.return_value = False cli._file_checker("subject", "file/path.py") mock_exists.assert_called_once_with("file/path.py") assert mock_echo.call_count == 1 assert "subject will be written to: file/path.py" in mock_echo.call_args[0] assert mock_exit.call_count == 0
def test_file_checker_existing_path(mock_exit, mock_echo, mock_exists): """Test file checker exits with error if the file exists.""" mock_exists.return_value = True cli._file_checker("subject", "file/path.py") mock_exists.assert_called_once_with("file/path.py") assert mock_echo.call_count == 1 assert ("Abort: The file/path.py file already exists." in mock_echo.call_args[0][0]) mock_exit.assert_called_once_with(1)