"""Tests for cli.main.""" import logging from typing import Any from unittest.mock import MagicMock, patch import pytest from typer.testing import CliRunner from backfill import config from backfill.cli.main import app, setup runner = CliRunner() @pytest.mark.parametrize( "sentry_env_value", [ pytest.param( None, id="sentry should not be initialized when the SENTRY env is not defined.", ), pytest.param( "no.such.dsn", id="sentry should be initialized when the SENTRY env is defined.", ), ], ) @patch("backfill.cli.main.sentry_sdk") @patch("backfill.cli.main.configure_logging") def test_setup( mock_configure_logging: MagicMock, sentry_sdk: MagicMock, monkeypatch: Any, caplog: pytest.LogCaptureFixture, sentry_env_value: str | None, ) -> None: """Test the setup method.""" monkeypatch.setattr(config, "SENTRY", sentry_env_value) caplog.set_level(logging.DEBUG) setup() mock_configure_logging.assert_called() with caplog.at_level(logging.DEBUG): assert "setup() complete" in caplog.text if sentry_env_value: sentry_sdk.init.assert_called() assert "SENTRY enabled" in caplog.text else: sentry_sdk.init.assert_not_called() assert "SENTRY disabled" in caplog.text def test_backfill_command() -> None: """Test the `backfill` main function.""" result = runner.invoke(app, ["backfill", "process", "--help"]) assert result.exit_code == 0 assert "--bucket-name" in result.stdout assert "--manifest-file" in result.stdout def test_greetings_command() -> None: """Test the `greetings` main function.""" result = runner.invoke(app, ["greetings", "hello", "unittest"]) assert result.exit_code == 0 assert "Hello unittest" in result.stdout