diff --git a/mypy.ini b/mypy.ini index 313e479..3a36ba2 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,4 +1,35 @@ [mypy] +check_untyped_defs = True +disallow_any_generics = True +disallow_incomplete_defs = True +disallow_subclassing_any = True +disallow_untyped_calls = True +disallow_untyped_decorators = True +disallow_untyped_defs = True +no_implicit_optional = True +no_implicit_reexport = True +pretty = True +show_column_numbers = True +show_error_codes = True +show_error_context = True +strict_equality = True +warn_redundant_casts = True +warn_return_any = True +warn_unreachable = True +warn_unused_configs = True +warn_unused_ignores = True -[mypy-tomlkit.*,pytest,pytest_mock,_pytest.*] +[mypy-_pytest.*] +ignore_missing_imports = True + +[mypy-pytest] +ignore_missing_imports = True + +[mypy-pytest_mock] +ignore_missing_imports = True + +[mypy-tests.*] +disallow_untyped_decorators = False + +[mypy-tomlkit.*] ignore_missing_imports = True diff --git a/src/toml_validator/py.typed b/src/toml_validator/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_main.py b/tests/test_main.py index 420fc16..d152eb9 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,27 +1,28 @@ """Test cases for the __main__ module.""" +from typing import Any from unittest.mock import Mock +import click.testing import pytest -from click.testing import CliRunner from pytest_mock import MockFixture from toml_validator import __main__ @pytest.fixture -def runner() -> CliRunner: +def runner() -> click.testing.CliRunner: """Fixture for invoking command-line interfaces.""" - return CliRunner() + return click.testing.CliRunner() @pytest.fixture -def mock_validation_validate_extension(mocker: MockFixture) -> Mock: +def mock_validation_validate_extension(mocker: MockFixture) -> Any: """Fixture for mocking validation.validate_extension.""" return mocker.patch("toml_validator.validation.validate_extension") @pytest.fixture -def mock_validation_validate_toml_no_error(mocker: MockFixture) -> Mock: +def mock_validation_validate_toml_no_error(mocker: MockFixture) -> Any: """Fixture for mocking validation.validate_toml with no errors.""" mock = mocker.patch("toml_validator.validation.validate_toml") mock.return_value = "" @@ -29,24 +30,24 @@ def mock_validation_validate_toml_no_error(mocker: MockFixture) -> Mock: @pytest.fixture -def mock_validation_validate_toml_with_error(mocker: MockFixture) -> Mock: +def mock_validation_validate_toml_with_error(mocker: MockFixture) -> Any: """Fixture for mocking validation.validate_toml with error.""" mock = mocker.patch("toml_validator.validation.validate_toml") mock.return_value = "|some error description|" return mock -def test_main_without_argument(runner: CliRunner): +def test_main_without_argument(runner: click.testing.CliRunner) -> None: """It exits with a status code of 2.""" result = runner.invoke(__main__.main) assert result.exit_code == 2 def test_main_with_argument_success( - runner: CliRunner, + runner: click.testing.CliRunner, mock_validation_validate_extension: Mock, mock_validation_validate_toml_no_error: Mock, -): +) -> None: """It exits with a status code of zero.""" with runner.isolated_filesystem(): with open("file.toml", "w") as f: @@ -60,10 +61,10 @@ def test_main_with_argument_success( def test_main_with_argument_fail( - runner: CliRunner, + runner: click.testing.CliRunner, mock_validation_validate_extension: Mock, mock_validation_validate_toml_with_error: Mock, -): +) -> None: """It outputs error.""" with runner.isolated_filesystem(): with open("file.toml", "w") as f: @@ -77,7 +78,9 @@ def test_main_with_argument_fail( @pytest.mark.e2e -def test_main_without_arguments_in_production_env(runner: CliRunner): +def test_main_without_arguments_in_production_env( + runner: click.testing.CliRunner, +) -> None: """It exits with a status code of 2 (e2e).""" result = runner.invoke(__main__.main) assert result.exit_code == 2 diff --git a/tests/test_validation.py b/tests/test_validation.py index 9526f8b..8420319 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -1,4 +1,5 @@ """Test cases for the validation module.""" +from typing import Any from unittest.mock import Mock import pytest @@ -9,13 +10,13 @@ @pytest.fixture -def mock_tomlkit_parse(mocker: MockFixture) -> Mock: +def mock_tomlkit_parse(mocker: MockFixture) -> Any: """Fixture for mocking tomlkit.parse.""" return mocker.patch("tomlkit.parse") @pytest.fixture -def mock_tomlkit_parse_exception(mocker: MockFixture) -> Mock: +def mock_tomlkit_parse_exception(mocker: MockFixture) -> Any: """Fixture for mocking tomlkit.parse.""" mock = mocker.patch("tomlkit.parse") mock.side_effect = TOMLKitError("|some tomlkit error|") @@ -23,13 +24,13 @@ def mock_tomlkit_parse_exception(mocker: MockFixture) -> Mock: @pytest.fixture -def mock_open_valid_file(mocker: MockFixture) -> Mock: +def mock_open_valid_file(mocker: MockFixture) -> Any: """Fixture for mocking build-in open for valid TOML file.""" return mocker.patch("builtins.open", mocker.mock_open(read_data="[x]\na = 3")) @pytest.fixture -def mock_open_invalid_file(mocker: MockFixture) -> Mock: +def mock_open_invalid_file(mocker: MockFixture) -> Any: """Fixture for mocking build-in open for valid TOML file.""" return mocker.patch( "builtins.open", mocker.mock_open(read_data="[x]\na = 3\n[x]\na = 3") @@ -62,12 +63,12 @@ def test_validate_toml_with_error( @pytest.mark.e2e -def test_validate_toml_no_error_production(mock_open_valid_file) -> None: +def test_validate_toml_no_error_production(mock_open_valid_file: Mock) -> None: """It returns no errors when valid TOML (e2e).""" assert validation.validate_toml("file.toml") == "" @pytest.mark.e2e -def test_validate_toml_with_error_production(mock_open_invalid_file) -> None: +def test_validate_toml_with_error_production(mock_open_invalid_file: Mock) -> None: """It returns errors when invalid TOML (e2e).""" assert validation.validate_toml("file.toml") == 'Key "x" already exists.'