chore: update python packages + formatting + cleanup (#3221)

This commit is contained in:
dni ⚡ 2025-06-30 14:53:11 +02:00
parent c4c03d96a3
commit a16078a6ba
No known key found for this signature in database
GPG key ID: D1F416F29AD26E87
53 changed files with 1159 additions and 576 deletions

View file

@ -1,4 +1,4 @@
from typing import Dict, List, Optional, Union
from typing import Optional, Union
from pydantic import BaseModel
@ -41,24 +41,24 @@ class Mock(FunctionMock, TestMock):
class FunctionMocks(BaseModel):
mocks: Dict[str, FunctionMock]
mocks: dict[str, FunctionMock]
class FunctionTest(BaseModel):
description: str
call_params: dict
expect: dict
mocks: Dict[str, List[Dict[str, TestMock]]]
mocks: dict[str, list[dict[str, TestMock]]]
class FunctionData(BaseModel):
"""Data required for testing this function"""
"Function level mocks that apply for all tests of this function"
mocks: List[FunctionMock] = []
mocks: list[FunctionMock] = []
"All the tests for this function"
tests: List[FunctionTest] = []
tests: list[FunctionTest] = []
class WalletTest(BaseModel):
@ -69,7 +69,7 @@ class WalletTest(BaseModel):
call_params: Optional[dict] = {}
expect: Optional[dict]
expect_error: Optional[dict]
mocks: List[Mock] = []
mocks: list[Mock] = []
@staticmethod
def tests_for_funding_source(
@ -77,7 +77,7 @@ class WalletTest(BaseModel):
fn_name: str,
fn,
test,
) -> List["WalletTest"]:
) -> list["WalletTest"]:
t = WalletTest(
**{
"funding_source": fs,
@ -96,7 +96,7 @@ class WalletTest(BaseModel):
return [t]
def _tests_from_fs_mocks(self, fn, test, fs_name: str) -> List["WalletTest"]:
def _tests_from_fs_mocks(self, fn, test, fs_name: str) -> list["WalletTest"]:
fs_mocks = fn["mocks"][fs_name]
test_mocks = test["mocks"][fs_name]
@ -132,7 +132,7 @@ class WalletTest(BaseModel):
def _tests_from_mock(self, mock_obj) -> "WalletTest":
test_mocks: List[Mock] = [
test_mocks: list[Mock] = [
Mock.combine_mocks(
mock_name,
mock_obj[mock_name]["fs_mock"],

View file

@ -2,7 +2,6 @@ import functools
import importlib
import json
import operator
from typing import Dict, List
import pytest
@ -12,7 +11,7 @@ from tests.wallets.fixtures.models import FundingSourceConfig, WalletTest
wallets_module = importlib.import_module("lnbits.wallets")
def wallet_fixtures_from_json(path) -> List["WalletTest"]:
def wallet_fixtures_from_json(path) -> list["WalletTest"]:
with open(path) as f:
data = json.load(f)
@ -20,7 +19,7 @@ def wallet_fixtures_from_json(path) -> List["WalletTest"]:
FundingSourceConfig(name=fs_name, **data["funding_sources"][fs_name])
for fs_name in data["funding_sources"]
]
tests: Dict[str, List[WalletTest]] = {}
tests: dict[str, list[WalletTest]] = {}
for fn_name in data["functions"]:
fn = data["functions"][fn_name]
fn_tests = _tests_for_function(funding_sources, fn_name, fn)
@ -33,9 +32,9 @@ def wallet_fixtures_from_json(path) -> List["WalletTest"]:
def _tests_for_function(
funding_sources: List[FundingSourceConfig], fn_name: str, fn
) -> Dict[str, List[WalletTest]]:
tests: Dict[str, List[WalletTest]] = {}
funding_sources: list[FundingSourceConfig], fn_name: str, fn
) -> dict[str, list[WalletTest]]:
tests: dict[str, list[WalletTest]] = {}
for test in fn["tests"]:
"""create an unit test for each funding source"""
@ -46,9 +45,9 @@ def _tests_for_function(
def _tests_for_funding_source(
funding_sources: List[FundingSourceConfig], fn_name: str, fn, test
) -> Dict[str, List[WalletTest]]:
tests: Dict[str, List[WalletTest]] = {fs.name: [] for fs in funding_sources}
funding_sources: list[FundingSourceConfig], fn_name: str, fn, test
) -> dict[str, list[WalletTest]]:
tests: dict[str, list[WalletTest]] = {fs.name: [] for fs in funding_sources}
for fs in funding_sources:
tests[fs.name] += WalletTest.tests_for_funding_source(fs, fn_name, fn, test)
return tests
@ -132,7 +131,7 @@ async def _assert_error(wallet, tested_func, call_params, expect_error):
assert e_info.match(expect_error["message"])
def _merge_dict_of_lists(v1: Dict[str, List], v2: Dict[str, List]):
def _merge_dict_of_lists(v1: dict[str, list], v2: dict[str, list]):
"""Merge v2 into v1"""
for k in v2:
v1[k] = v2[k] if k not in v1 else v1[k] + v2[k]

View file

@ -2,14 +2,14 @@ import base64
import hashlib
import json
import time
from typing import Dict, cast
from typing import cast
import pytest
import secp256k1
from Cryptodome import Random
from Cryptodome.Cipher import AES
from Cryptodome.Util.Padding import pad, unpad
from websockets.server import serve as ws_serve
from websockets.legacy.server import serve as ws_serve
from lnbits.wallets.nwc import NWCWallet
from tests.wallets.helpers import (
@ -49,7 +49,7 @@ def decrypt_content(priv_key, source_pub_key, content):
def json_dumps(data):
if isinstance(data, Dict):
if isinstance(data, dict):
data = {k: v for k, v in data.items() if v is not None}
return json.dumps(data, separators=(",", ":"), ensure_ascii=False)

View file

@ -1,5 +1,5 @@
import json
from typing import Dict, Union
from typing import Union
from urllib.parse import urlencode
import pytest
@ -59,7 +59,7 @@ async def test_rest_wallet(httpserver: HTTPServer, test_data: WalletTest):
def _apply_mock(httpserver: HTTPServer, mock: Mock):
request_data: Dict[str, Union[str, dict, list]] = {}
request_data: dict[str, Union[str, dict, list]] = {}
request_type = getattr(mock.dict(), "request_type", None)
# request_type = mock.request_type <--- this des not work for whatever reason!!!

View file

@ -1,5 +1,5 @@
import importlib
from typing import Dict, List, Optional
from typing import Optional
from unittest.mock import AsyncMock, Mock
import pytest
@ -93,7 +93,7 @@ def _check_calls(expected_calls):
def _spy_mocks(mocker: MockerFixture, test_data: WalletTest, wallet: BaseWallet):
expected_calls: Dict[str, List] = {}
expected_calls: dict[str, list] = {}
for mock in test_data.mocks:
client_field = getattr(wallet, mock.name)
spy = _spy_mock(mocker, mock, client_field)
@ -104,7 +104,7 @@ def _spy_mocks(mocker: MockerFixture, test_data: WalletTest, wallet: BaseWallet)
def _spy_mock(mocker: MockerFixture, mock: RpcMock, client_field):
expected_calls: Dict[str, List] = {}
expected_calls: dict[str, list] = {}
assert isinstance(mock.response, dict), "Expected data RPC response"
for field_name in mock.response:
value = mock.response[field_name]