Skip to content

Commit f9da97f

Browse files
author
Tiago Requeijo
committed
Lint tests
1 parent 75137c6 commit f9da97f

26 files changed

Lines changed: 320 additions & 169 deletions

.github/workflows/publish.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,3 @@ jobs:
3535
run: hatch publish -y
3636
env:
3737
HATCH_INDEX_AUTH: ${{ secrets.HATCH_INDEX_AUTH }}
38-
HATCH_INDEX_USER: ${{ secrets.HATCH_INDEX_USER }}

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ All notable changes to this project will be documented in this file.
2424

2525
### Changed
2626

27-
- Enviroment files are now loaded from filenames with a suffix of `.env` or starting with `.env`
27+
- Environment files are now loaded from filenames with a suffix of `.env` or starting with `.env`
2828

2929

3030
## [0.11.0] - 2024-04-23

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ features = ["cloud", "file-formats", "validation"]
100100

101101
[tool.ruff]
102102
line-length = 88
103-
exclude = ["tests", "docs", "src/config/_version.py"]
103+
exclude = ["docs", "src/config/_version.py"]
104104

105105
[tool.ruff.lint.pydocstyle]
106106
convention = "google"

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Tests."""

tests/contrib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Contrib modules."""

tests/contrib/test_aws.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import pytest
1+
"""Tests for AWS Secrets support."""
2+
3+
# ruff: noqa: D101,D102,D103,D106,D107,E501
4+
25
import json
3-
from pytest import raises
46

7+
import pytest
8+
from pytest import raises
59

610
try:
711
import boto3 as aws
@@ -29,7 +33,7 @@ class Client:
2933
def __init__(self, val): # type: ignore
3034
self._value = val
3135

32-
def get_secret_value(self, SecretId: str): # type: ignore
36+
def get_secret_value(self, SecretId: str): # type: ignore # noqa: N803
3337
return {"SecretString": json.dumps(self._value)}
3438

3539
def client(self, *args, **kwargs): # type: ignore
@@ -44,7 +48,7 @@ class Client:
4448
def __init__(self, val): # type: ignore
4549
self._value = val
4650

47-
def get_secret_value(self, SecretId: str): # type: ignore
51+
def get_secret_value(self, SecretId: str): # type: ignore # noqa: N803
4852
return self._value
4953

5054
def client(self, *args, **kwargs): # type: ignore
@@ -66,7 +70,9 @@ def test_expiration(mocker): # type: ignore
6670
# with cache
6771
cfg = AWSSecretsManagerConfiguration(secret_name="test-secret")
6872
mocker.patch.object(
69-
cfg._client, "get_secret_value", return_value={"SecretString": json.dumps(DICT)}
73+
cfg._client,
74+
"get_secret_value",
75+
return_value={"SecretString": json.dumps(DICT)},
7076
)
7177
assert cfg["foo"] == "foo_val"
7278
cfg._client.get_secret_value.assert_called_once()
@@ -78,7 +84,9 @@ def test_expiration(mocker): # type: ignore
7884
# without cache
7985
cfg = AWSSecretsManagerConfiguration(secret_name="test-secret", cache_expiration=0)
8086
mocker.patch.object(
81-
cfg._client, "get_secret_value", return_value={"SecretString": json.dumps(DICT)}
87+
cfg._client,
88+
"get_secret_value",
89+
return_value={"SecretString": json.dumps(DICT)},
8290
)
8391
assert cfg["foo"] == "foo_val"
8492
cfg._client.get_secret_value.assert_called()

tests/contrib/test_azure.py

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
"""Tests for Azure Keyvault support."""
2+
3+
# ruff: noqa: D101,D102,D103,D107,E501
4+
15
from collections import namedtuple
2-
import pytest
3-
from pytest import raises
46

7+
import pytest
58
from config import config_from_dict
9+
from pytest import raises
610

711
try:
8-
from config.contrib.azure import AzureKeyVaultConfiguration
912
from azure.core.exceptions import ResourceNotFoundError
13+
from config.contrib.azure import AzureKeyVaultConfiguration
14+
1015
azure = True
1116
except ImportError: # pragma: no cover
1217
azure = None # type: ignore
@@ -51,7 +56,10 @@ def list_properties_of_secrets(self) -> list:
5156
@pytest.mark.skipif("azure is None")
5257
def test_load_dict(): # type: ignore
5358
cfg = AzureKeyVaultConfiguration(
54-
"fake_id", "fake_secret", "fake-tenant", "fake_vault"
59+
"fake_id",
60+
"fake_secret",
61+
"fake-tenant",
62+
"fake_vault",
5563
)
5664
cfg._kv_client = FakeSecretClient(DICT)
5765
assert cfg["foo"] == "foo_val"
@@ -63,7 +71,10 @@ def test_load_dict(): # type: ignore
6371
def test_expiration(mocker): # type: ignore
6472
# with cache
6573
cfg = AzureKeyVaultConfiguration(
66-
"fake_id", "fake_secret", "fake-tenant", "fake_vault"
74+
"fake_id",
75+
"fake_secret",
76+
"fake-tenant",
77+
"fake_vault",
6778
)
6879
cfg._kv_client = FakeSecretClient(DICT)
6980

@@ -74,7 +85,11 @@ def test_expiration(mocker): # type: ignore
7485

7586
# without cache
7687
cfg = AzureKeyVaultConfiguration(
77-
"fake_id", "fake_secret", "fake-tenant", "fake_vault", cache_expiration=0
88+
"fake_id",
89+
"fake_secret",
90+
"fake-tenant",
91+
"fake_vault",
92+
cache_expiration=0,
7893
)
7994
cfg._kv_client = FakeSecretClient(DICT)
8095

@@ -87,7 +102,11 @@ def test_expiration(mocker): # type: ignore
87102
@pytest.mark.skipif("azure is None")
88103
def test_deletion(): # type: ignore
89104
cfg = AzureKeyVaultConfiguration(
90-
"fake_id", "fake_secret", "fake-tenant", "fake_vault", cache_expiration=0
105+
"fake_id",
106+
"fake_secret",
107+
"fake-tenant",
108+
"fake_vault",
109+
cache_expiration=0,
91110
)
92111
d = DICT.copy()
93112
cfg._kv_client = FakeSecretClient(d)
@@ -103,7 +122,11 @@ def test_deletion(): # type: ignore
103122
@pytest.mark.skipif("azure is None")
104123
def test_missing_key(): # type: ignore
105124
cfg = AzureKeyVaultConfiguration(
106-
"fake_id", "fake_secret", "fake-tenant", "fake_vault", cache_expiration=0
125+
"fake_id",
126+
"fake_secret",
127+
"fake-tenant",
128+
"fake_vault",
129+
cache_expiration=0,
107130
)
108131
d = DICT.copy()
109132
cfg._kv_client = FakeSecretClient(d)
@@ -117,7 +140,11 @@ def test_missing_key(): # type: ignore
117140
@pytest.mark.skipif("azure is None")
118141
def test_get_attr(): # type: ignore
119142
cfg = AzureKeyVaultConfiguration(
120-
"fake_id", "fake_secret", "fake-tenant", "fake_vault", cache_expiration=0
143+
"fake_id",
144+
"fake_secret",
145+
"fake-tenant",
146+
"fake_vault",
147+
cache_expiration=0,
121148
)
122149
d = DICT.copy()
123150
cfg._kv_client = FakeSecretClient(d)
@@ -131,7 +158,11 @@ def test_get_attr(): # type: ignore
131158
@pytest.mark.skipif("azure is None")
132159
def test_dict(): # type: ignore
133160
cfg = AzureKeyVaultConfiguration(
134-
"fake_id", "fake_secret", "fake-tenant", "fake_vault", cache_expiration=0
161+
"fake_id",
162+
"fake_secret",
163+
"fake-tenant",
164+
"fake_vault",
165+
cache_expiration=0,
135166
)
136167
d = DICT.copy()
137168
cfg._kv_client = FakeSecretClient(d)
@@ -144,7 +175,11 @@ def test_dict(): # type: ignore
144175
@pytest.mark.skipif("azure is None")
145176
def test_repr(): # type: ignore
146177
cfg = AzureKeyVaultConfiguration(
147-
"fake_id", "fake_secret", "fake-tenant", "fake_vault", cache_expiration=0
178+
"fake_id",
179+
"fake_secret",
180+
"fake-tenant",
181+
"fake_vault",
182+
cache_expiration=0,
148183
)
149184
d = DICT.copy()
150185
cfg._kv_client = FakeSecretClient(d)
@@ -155,7 +190,11 @@ def test_repr(): # type: ignore
155190
@pytest.mark.skipif("azure is None")
156191
def test_str(): # type: ignore
157192
cfg = AzureKeyVaultConfiguration(
158-
"fake_id", "fake_secret", "fake-tenant", "fake_vault", cache_expiration=0
193+
"fake_id",
194+
"fake_secret",
195+
"fake-tenant",
196+
"fake_vault",
197+
cache_expiration=0,
159198
)
160199
d = DICT.copy()
161200
cfg._kv_client = FakeSecretClient(d)
@@ -171,7 +210,10 @@ def test_str(): # type: ignore
171210
@pytest.mark.skipif("azure is None")
172211
def test_reload(): # type: ignore
173212
cfg = AzureKeyVaultConfiguration(
174-
"fake_id", "fake_secret", "fake-tenant", "fake_vault"
213+
"fake_id",
214+
"fake_secret",
215+
"fake-tenant",
216+
"fake_vault",
175217
)
176218
cfg._kv_client = FakeSecretClient(DICT)
177219
assert cfg == config_from_dict(DICT)

tests/contrib/test_gcp.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
"""Tests for GCP support."""
2+
3+
# ruff: noqa: D101,D102,D103,D107,E501
4+
15
from collections import namedtuple
26
from typing import Any, Dict
3-
import pytest
4-
from pytest import raises
57

8+
import pytest
69
from config import config_from_dict
10+
from pytest import raises
711

812
try:
9-
from google.cloud import secretmanager_v1
10-
from google.api_core.exceptions import NotFound
1113
from config.contrib.gcp import GCPSecretManagerConfiguration
14+
from google.api_core.exceptions import NotFound
15+
from google.cloud import secretmanager_v1
1216
except ImportError: # pragma: no cover
1317
secretmanager_v1 = None # type: ignore
1418

@@ -36,14 +40,14 @@ def __init__(self, dct: dict):
3640
self._dict = dct
3741

3842
def list_secrets(self, request: Dict[str, str]) -> list:
39-
return [Secret(f"prefix/{x}", "") for x in self._dict.keys()]
43+
return [Secret(f"prefix/{x}", "") for x in self._dict]
4044

4145
def access_secret_version(self, request: Dict[str, str]) -> Secret:
4246
name = request["name"]
4347
try:
4448
return Secret(name, self._dict[name.split("/")[3]])
4549
except KeyError:
46-
raise NotFound("") # type: ignore
50+
raise NotFound("") from None # type: ignore
4751

4852

4953
def fake_client(val: dict) -> Any:

tests/contrib/test_vault.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
"""Tests for Hashicorp Vault support."""
2+
3+
# ruff: noqa: D101,D102,D103,D107,E501
4+
15
from collections import namedtuple
2-
import pytest
3-
from pytest import raises
46

7+
import pytest
58
from config import config_from_dict
9+
from pytest import raises
610

711
try:
812
import hvac

tests/python_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Example file to import as a config."""
2+
13
import sys
24

35
CONFIG_SYS_VERSION = sys.hexversion

0 commit comments

Comments
 (0)