Skip to content

Commit 3399c94

Browse files
authored
MPT-15271: add flake8 pyproject and flake8 aaa (#134)
Add: * https://pypi.org/project/Flake8-pyproject/ * https://pypi.org/project/flake8-aaa/ Fix the tests to follow the flake8-aaa rules. Note that we are following these solutions to address rules AAA01 and AAA03 rule AAA01: <img width="751" height="485" alt="image" src="https://github.com/user-attachments/assets/e7662617-9837-4f66-81ab-efdd4bb47d08" /> <img width="729" height="132" alt="image" src="https://github.com/user-attachments/assets/bb9657e7-83e2-4dc7-8741-677fda82dad2" /> AAA03: we follow the large-style act block approach <img width="765" height="344" alt="image" src="https://github.com/user-attachments/assets/c09b0032-f4c8-40fd-8ffd-bff11ff63e14" />
2 parents 8994da6 + d37226f commit 3399c94

145 files changed

Lines changed: 2408 additions & 1850 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pre-commit-config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ repos:
2222
hooks:
2323
- id: uv-lock
2424

25+
- repo: https://github.com/pycqa/flake8
26+
rev: 7.3.0
27+
hooks:
28+
- id: flake8
29+
additional_dependencies: [Flake8-pyproject, Flake8-AAA, wemake-python-styleguide==1.3.*]
30+
2531
- repo: https://github.com/pre-commit/mirrors-mypy
2632
rev: v1.17.0
2733
hooks:
2834
- id: mypy
2935
args: ["--config-file=pyproject.toml", "."]
3036
pass_filenames: false
31-
32-
- repo: https://github.com/pycqa/flake8
33-
rev: 7.3.0
34-
hooks:
35-
- id: flake8
36-
additional_dependencies: [wemake-python-styleguide==1.3.*]

pyproject.toml

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ dependencies = [
2727
[dependency-groups]
2828
dev = [
2929
"dependency-injector>=4.48.2",
30+
"flake8-aaa>=0.17.2",
31+
"flake8-pyproject>=1.2.3",
3032
"freezegun==1.5.*",
3133
"ipdb==0.13.*",
3234
"ipython==9.*",
@@ -61,7 +63,7 @@ build-backend = "hatchling.build"
6163
[tool.pytest.ini_options]
6264
testpaths = "tests"
6365
pythonpath = "."
64-
addopts = "--cov=mpt_api_client --cov-report=term-missing --cov-report=html --cov-report=xml --import-mode=importlib"
66+
addopts = "--cov=mpt_api_client --cov-report=term-missing --cov-report=xml --import-mode=importlib"
6567
log_cli = false
6668
asyncio_mode = "auto"
6769
asyncio_default_fixture_loop_scope = "function"
@@ -81,18 +83,59 @@ exclude_also = [
8183
"if __name__ == \"__main__\":",
8284
"raise NotImplementedError",
8385
]
84-
include = [
85-
"mpt_api_client/**",
86-
]
8786
omit = [
8887
"*/__init__.py"
8988
]
9089

90+
[tool.flake8]
91+
allowed-domain-names = ["result"]
92+
aaa_act_block_style = "large"
93+
doctests = true
94+
extend-ignore = ["WPS226", "WPS412"]
95+
extend-exclude = [
96+
".coverage",
97+
".github",
98+
".idea",
99+
".mypy_cache",
100+
".pytest_cache",
101+
".ruff_cache",
102+
"uv.lock",
103+
".venv"
104+
]
105+
format = "wemake"
106+
max-imports = 17
107+
max-line-length = 100
108+
select = ["AAA", "E999", "WPS"]
109+
show-source = true
110+
statistics = false
111+
per-file-ignores = [
112+
"mpt_api_client/mpt_client.py: WPS214 WPS235",
113+
"mpt_api_client/http/mixins.py: WPS202 WPS204 WPS235",
114+
"mpt_api_client/resources/*: WPS215",
115+
"mpt_api_client/models/model.py: WPS215 WPS110",
116+
"mpt_api_client/resources/accounts/*.py: WPS202 WPS215 WPS214 WPS235",
117+
"mpt_api_client/resources/billing/*.py: WPS202 WPS204 WPS214 WPS215",
118+
"mpt_api_client/resources/catalog/*.py: WPS110 WPS214 WPS215 WPS235",
119+
"mpt_api_client/resources/catalog/mixins.py: WPS110 WPS202 WPS214 WPS215 WPS235",
120+
"mpt_api_client/resources/catalog/products.py: WPS204 WPS214 WPS215 WPS235",
121+
"mpt_api_client/rql/query_builder.py: WPS110 WPS115 WPS210 WPS214",
122+
"tests/unit/http/test_async_service.py: WPS204 WPS202",
123+
"tests/unit/http/test_service.py: WPS204 WPS202",
124+
"tests/unit/http/test_mixins.py: WPS204 WPS202 WPS210",
125+
"tests/unit/resources/catalog/test_products.py: WPS202 WPS210",
126+
"tests/unit/resources/accounts/*.py: WPS204 WPS202 WPS210",
127+
"tests/unit/resources/*/test_mixins.py: WPS118 WPS202 WPS204 WPS235",
128+
"tests/unit/test_mpt_client.py: WPS235",
129+
"tests/e2e/accounts/*.py: WPS430 WPS202",
130+
"tests/e2e/catalog/*.py: WPS202 WPS421",
131+
"tests/e2e/catalog/items/*.py: WPS110 WPS202",
132+
"tests/*: WPS432 WPS202"
133+
]
134+
91135
[tool.ruff]
92136
# Ruff config: https://docs.astral.sh/ruff/settings
93137
preview = true
94138
target-version = "py312"
95-
extend-exclude = [".vscode", ".devcontainer", "swo"]
96139
output-format = "full"
97140
line-length = 100
98141

@@ -165,7 +208,7 @@ ignore = [
165208
"PT011", # pytest.raises({exception}) is too broad, set the match parameter or use a more specific exception
166209
"TRY003", # long exception messages from `tryceratops`
167210
]
168-
external = [ "WPS" ]
211+
external = [ "AAA", "WPS" ]
169212

170213
# Plugin configs:
171214
flake8-import-conventions.banned-from = [ "datetime" ]

setup.cfg

Lines changed: 0 additions & 60 deletions
This file was deleted.

tests/e2e/accounts/account/test_async_account.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,33 @@ async def test_get_account_by_id_not_found(async_mpt_ops):
2626

2727

2828
async def test_get_account_by_id(async_mpt_ops, account_id):
29-
account = await async_mpt_ops.accounts.accounts.get(account_id)
30-
assert account is not None
29+
result = await async_mpt_ops.accounts.accounts.get(account_id)
30+
31+
assert result is not None
3132

3233

3334
async def test_list_accounts(async_mpt_ops):
3435
limit = 10
35-
accounts_page = await async_mpt_ops.accounts.accounts.fetch_page(limit=limit)
36-
assert len(accounts_page) > 0
36+
37+
result = await async_mpt_ops.accounts.accounts.fetch_page(limit=limit)
38+
39+
assert len(result) > 0
3740

3841

3942
def test_create_account(async_created_account):
40-
account = async_created_account
41-
assert account is not None
43+
result = async_created_account
44+
45+
assert result is not None
4246

4347

4448
async def test_update_account(async_mpt_ops, async_created_account, account_factory, account_icon):
4549
updated_data = account_factory(name="Updated Account Name")
4650

47-
updated_account = await async_mpt_ops.accounts.accounts.update(
51+
result = await async_mpt_ops.accounts.accounts.update(
4852
async_created_account.id, updated_data, logo=account_icon
4953
)
5054

51-
assert updated_account is not None
55+
assert result is not None
5256

5357

5458
async def test_update_account_invalid_data(
@@ -76,9 +80,9 @@ async def test_update_account_not_found(
7680
async def test_account_enable(async_mpt_ops, account_factory, async_created_account):
7781
await async_mpt_ops.accounts.accounts.disable(async_created_account.id)
7882

79-
account = await async_mpt_ops.accounts.accounts.enable(async_created_account.id)
83+
result = await async_mpt_ops.accounts.accounts.enable(async_created_account.id)
8084

81-
assert account is not None
85+
assert result is not None
8286

8387

8488
async def test_account_enable_not_found(async_mpt_ops, invalid_account_id):
@@ -87,9 +91,9 @@ async def test_account_enable_not_found(async_mpt_ops, invalid_account_id):
8791

8892

8993
async def test_account_disable(async_mpt_ops, async_created_account):
90-
account = await async_mpt_ops.accounts.accounts.disable(async_created_account.id)
94+
result = await async_mpt_ops.accounts.accounts.disable(async_created_account.id)
9195

92-
assert account is not None
96+
assert result is not None
9397

9498

9599
async def test_account_disable_not_found(async_mpt_ops, invalid_account_id):
@@ -105,6 +109,6 @@ async def test_account_rql_filter(async_mpt_ops, account_id):
105109
.select(*selected_fields)
106110
)
107111

108-
accounts = [account async for account in filtered_accounts.iterate()]
112+
result = [account async for account in filtered_accounts.iterate()]
109113

110-
assert len(accounts) > 0
114+
assert len(result) > 0

tests/e2e/accounts/account/test_sync_account.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,31 @@ def test_get_account_by_id_not_found(mpt_ops):
2626

2727

2828
def test_get_account_by_id(mpt_ops, account_id):
29-
account = mpt_ops.accounts.accounts.get(account_id)
30-
assert account is not None
29+
result = mpt_ops.accounts.accounts.get(account_id)
30+
31+
assert result is not None
3132

3233

3334
def test_list_accounts(mpt_ops):
3435
limit = 10
35-
accounts_page = mpt_ops.accounts.accounts.fetch_page(limit=limit)
36-
assert len(accounts_page) > 0
36+
37+
result = mpt_ops.accounts.accounts.fetch_page(limit=limit)
38+
39+
assert len(result) > 0
3740

3841

3942
def test_create_account(created_account):
40-
account = created_account
41-
assert account is not None
43+
result = created_account
44+
45+
assert result is not None
4246

4347

4448
def test_update_account(mpt_ops, created_account, account_factory, account_icon):
4549
updated_data = account_factory(name="Updated Account Name")
4650

47-
updated_account = mpt_ops.accounts.accounts.update(
48-
created_account.id, updated_data, logo=account_icon
49-
)
51+
result = mpt_ops.accounts.accounts.update(created_account.id, updated_data, logo=account_icon)
5052

51-
assert updated_account is not None
53+
assert result is not None
5254

5355

5456
def test_update_account_invalid_data(mpt_ops, account_factory, created_account, account_icon):
@@ -70,9 +72,9 @@ def test_update_account_not_found(mpt_ops, account_factory, invalid_account_id,
7072
def test_account_enable(mpt_ops, account_factory, created_account):
7173
mpt_ops.accounts.accounts.disable(created_account.id)
7274

73-
account = mpt_ops.accounts.accounts.enable(created_account.id)
75+
result = mpt_ops.accounts.accounts.enable(created_account.id)
7476

75-
assert account is not None
77+
assert result is not None
7678

7779

7880
def test_account_enable_not_found(mpt_ops, invalid_account_id):
@@ -81,9 +83,9 @@ def test_account_enable_not_found(mpt_ops, invalid_account_id):
8183

8284

8385
def test_account_disable(mpt_ops, created_account):
84-
account = mpt_ops.accounts.accounts.disable(created_account.id)
86+
result = mpt_ops.accounts.accounts.disable(created_account.id)
8587

86-
assert account is not None
88+
assert result is not None
8789

8890

8991
def test_account_disable_not_found(mpt_ops, invalid_account_id):
@@ -99,6 +101,6 @@ def test_account_rql_filter(mpt_ops, account_id):
99101
.select(*selected_fields)
100102
)
101103

102-
accounts = list(filtered_accounts.iterate())
104+
result = list(filtered_accounts.iterate())
103105

104-
assert len(accounts) > 0
106+
assert len(result) > 0

0 commit comments

Comments
 (0)