From: Scirlat Danut Date: Sun, 4 Feb 2024 18:33:06 +0000 (+0200) Subject: Added type annotations to test_config.py (#2475) X-Git-Tag: 0.37.0~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=551bf867d24e61598f9ee68a34fd9b6f6103543e;p=thirdparty%2Fstarlette.git Added type annotations to test_config.py (#2475) * added type annotations to test_config.py * Apply suggestions from code review --------- Co-authored-by: Scirlat Danut Co-authored-by: Marcelo Trylesinski --- diff --git a/tests/test_config.py b/tests/test_config.py index f7b294c7..4974ffdb 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,4 +1,5 @@ import os +import typing from pathlib import Path from typing import Any, Optional @@ -39,7 +40,7 @@ def test_config_types() -> None: config("INT_DEFAULT_STR", cast=int, default="true") -def test_config(tmpdir, monkeypatch): +def test_config(tmpdir: Path, monkeypatch: pytest.MonkeyPatch) -> None: path = os.path.join(tmpdir, ".env") with open(path, "w") as file: file.write("# Do not commit to source control\n") @@ -52,7 +53,7 @@ def test_config(tmpdir, monkeypatch): config = Config(path, environ={"DEBUG": "true"}) - def cast_to_int(v) -> int: + def cast_to_int(v: typing.Any) -> int: return int(v) DEBUG = config("DEBUG", cast=bool) @@ -104,14 +105,14 @@ def test_config(tmpdir, monkeypatch): config.get("BOOL_AS_INT", cast=bool) -def test_missing_env_file_raises(tmpdir): +def test_missing_env_file_raises(tmpdir: Path) -> None: path = os.path.join(tmpdir, ".env") with pytest.raises(FileNotFoundError, match=f"Config file '{path}' not found."): Config(path) -def test_environ(): +def test_environ() -> None: environ = Environ() # We can mutate the environ at this point. @@ -136,7 +137,7 @@ def test_environ(): assert len(environ) == len(os.environ) -def test_config_with_env_prefix(tmpdir, monkeypatch): +def test_config_with_env_prefix(tmpdir: Path, monkeypatch: pytest.MonkeyPatch) -> None: config = Config( environ={"APP_DEBUG": "value", "ENVIRONMENT": "dev"}, env_prefix="APP_" )