From 6cf7ccbaa8306700e64ada19d6f99807743b2865 Mon Sep 17 00:00:00 2001
From: Max Nanis
Date: Fri, 21 Aug 2026 17:19:41 -0700
Subject: Ruff auto updates to 3.14
---
tests/managers/thl/test_ledger/test_lm_accounts.py | 65 +++++++++++-----------
tests/managers/thl/test_ledger/test_lm_tx_locks.py | 22 ++++----
.../thl/test_ledger/test_thl_lm_bp_payout.py | 48 ++++++++--------
tests/managers/thl/test_ledger/test_thl_lm_tx.py | 55 +++++++++---------
.../test_ledger/test_thl_lm_tx__user_payouts.py | 10 ++--
tests/managers/thl/test_ledger/test_user_txs.py | 31 ++++++-----
6 files changed, 116 insertions(+), 115 deletions(-)
(limited to 'tests/managers/thl/test_ledger')
diff --git a/tests/managers/thl/test_ledger/test_lm_accounts.py b/tests/managers/thl/test_ledger/test_lm_accounts.py
index 5cfaac1..faef5fb 100644
--- a/tests/managers/thl/test_ledger/test_lm_accounts.py
+++ b/tests/managers/thl/test_ledger/test_lm_accounts.py
@@ -1,6 +1,7 @@
+from collections.abc import Callable
from itertools import product as iproduct
from random import randint
-from typing import TYPE_CHECKING, Callable
+from typing import TYPE_CHECKING
from uuid import uuid4
import pytest
@@ -51,10 +52,10 @@ class TestLedgerAccountManagerNoResults:
def test_get_account_no_results(
self,
- currency: "LedgerCurrency",
+ currency: LedgerCurrency,
kind: str,
- acct_id: "UUIDStr",
- lm: "LedgerManager",
+ acct_id: UUIDStr,
+ lm: LedgerManager,
):
"""Try to query for accounts that we know don't exist and confirm that
we either get the expected None result or it raises the correct
@@ -74,10 +75,10 @@ class TestLedgerAccountManagerNoResults:
def test_get_account_no_results_many(
self,
- currency: "LedgerCurrency",
+ currency: LedgerCurrency,
kind: str,
- acct_id: "UUIDStr",
- lm: "LedgerManager",
+ acct_id: UUIDStr,
+ lm: LedgerManager,
):
qn = ":".join([currency, kind, acct_id])
@@ -114,10 +115,10 @@ class TestLedgerAccountManagerCreate:
def test_create_account_error_permission(
self,
- currency: "LedgerCurrency",
- account_type: "AccountType",
- direction: "Direction",
- lm: "LedgerManager",
+ currency: LedgerCurrency,
+ account_type: AccountType,
+ direction: Direction,
+ lm: LedgerManager,
):
"""Confirm that the Permission values that are set on the Ledger Manger
allow the Creation action to occur.
@@ -164,10 +165,10 @@ class TestLedgerAccountManagerCreate:
def test_create(
self,
- currency: "LedgerCurrency",
- account_type: "AccountType",
- direction: "Direction",
- lm: "LedgerManager",
+ currency: LedgerCurrency,
+ account_type: AccountType,
+ direction: Direction,
+ lm: LedgerManager,
):
"""Confirm that the Permission values that are set on the Ledger Manger
allow the Creation action to occur.
@@ -194,10 +195,10 @@ class TestLedgerAccountManagerCreate:
def test_get_or_create(
self,
- currency: "LedgerCurrency",
- account_type: "AccountType",
- direction: "Direction",
- lm: "LedgerManager",
+ currency: LedgerCurrency,
+ account_type: AccountType,
+ direction: Direction,
+ lm: LedgerManager,
):
"""Confirm that the Permission values that are set on the Ledger Manger
allow the Creation action to occur.
@@ -225,7 +226,7 @@ class TestLedgerAccountManagerCreate:
class TestLedgerAccountManagerGet:
- def test_get(self, ledger_account: "LedgerAccount", lm: "LedgerManager"):
+ def test_get(self, ledger_account: LedgerAccount, lm: LedgerManager):
res = lm.get_account(qualified_name=ledger_account.qualified_name)
assert res is not None
assert res.uuid == ledger_account.uuid
@@ -243,11 +244,11 @@ class TestLedgerAccountManagerGet:
def test_get_balance_empty(
self,
- ledger_account: "LedgerAccount",
- ledger_account_credit: "LedgerAccount",
- ledger_account_debit: "LedgerAccount",
- ledger_tx: "LedgerTransaction",
- lm: "LedgerManager",
+ ledger_account: LedgerAccount,
+ ledger_account_credit: LedgerAccount,
+ ledger_account_debit: LedgerAccount,
+ ledger_tx: LedgerTransaction,
+ lm: LedgerManager,
):
res = lm.get_account_balance(account=ledger_account)
assert res == 0
@@ -261,12 +262,12 @@ class TestLedgerAccountManagerGet:
@pytest.mark.parametrize("n_times", range(5))
def test_get_account_filtered_balance(
self,
- ledger_account: "LedgerAccount",
- ledger_account_credit: "LedgerAccount",
- ledger_account_debit: "LedgerAccount",
- ledger_tx: "LedgerTransaction",
- n_times: "PositiveInt",
- lm: "LedgerManager",
+ ledger_account: LedgerAccount,
+ ledger_account_credit: LedgerAccount,
+ ledger_account_debit: LedgerAccount,
+ ledger_tx: LedgerTransaction,
+ n_times: PositiveInt,
+ lm: LedgerManager,
):
"""Try searching for random metadata and confirm it's always 0 because
Tx can be found.
@@ -320,7 +321,7 @@ class TestLedgerAccountManagerGet:
)
def test_get_balance_timerange_empty(
- self, ledger_account: "LedgerAccount", lm: "LedgerManager"
+ self, ledger_account: LedgerAccount, lm: LedgerManager
):
res = lm.get_account_balance_timerange(account=ledger_account)
assert res == 0
diff --git a/tests/managers/thl/test_ledger/test_lm_tx_locks.py b/tests/managers/thl/test_ledger/test_lm_tx_locks.py
index df2611b..07c3712 100644
--- a/tests/managers/thl/test_ledger/test_lm_tx_locks.py
+++ b/tests/managers/thl/test_ledger/test_lm_tx_locks.py
@@ -1,7 +1,7 @@
import logging
-from datetime import datetime, timezone, timedelta
+from collections.abc import Callable
+from datetime import UTC, datetime, timedelta, timezone
from decimal import Decimal
-from typing import Callable
import pytest
@@ -9,21 +9,21 @@ from generalresearch.managers.thl.ledger_manager.conditions import (
generate_condition_mp_payment,
)
from generalresearch.managers.thl.ledger_manager.exceptions import (
+ LedgerTransactionCreateError,
LedgerTransactionCreateLockError,
LedgerTransactionFlagAlreadyExistsError,
- LedgerTransactionCreateError,
)
from generalresearch.models import Source
from generalresearch.models.thl.ledger import LedgerTransaction
from generalresearch.models.thl.session import (
- Wall,
+ Session,
Status,
StatusCode1,
- Session,
+ Wall,
WallAdjustedStatus,
)
from generalresearch.models.thl.user import User
-from test_utils.models.conftest import user_factory, session, product_user_wallet_no
+from test_utils.models.conftest import product_user_wallet_no, session, user_factory
logger = logging.getLogger("LedgerManager")
@@ -139,7 +139,7 @@ class TestLedgerLocks:
delete_ledger_db()
create_main_accounts()
- now = datetime.now(timezone.utc) - timedelta(hours=1)
+ now = datetime.now(UTC) - timedelta(hours=1)
user: User = user_factory(product=product_user_wallet_no)
# A User does a Wall complete on Session.id=1 and the transaction is
@@ -283,8 +283,8 @@ class TestLedgerLocks:
session_id=3,
status=Status.COMPLETE,
status_code_1=StatusCode1.COMPLETE,
- started=datetime.now(timezone.utc),
- finished=datetime.now(timezone.utc) + timedelta(seconds=1),
+ started=datetime.now(UTC),
+ finished=datetime.now(UTC) + timedelta(seconds=1),
)
thl_lm.create_tx_task_complete(wall=wall1, user=user, created=wall1.started)
@@ -327,8 +327,8 @@ class TestLedgerLocks:
session_id=3,
status=Status.COMPLETE,
status_code_1=StatusCode1.COMPLETE,
- started=datetime.now(timezone.utc),
- finished=datetime.now(timezone.utc) + timedelta(seconds=1),
+ started=datetime.now(UTC),
+ finished=datetime.now(UTC) + timedelta(seconds=1),
)
thl_lm.create_tx_task_complete(wall1, user, created=wall1.started)
diff --git a/tests/managers/thl/test_ledger/test_thl_lm_bp_payout.py b/tests/managers/thl/test_ledger/test_thl_lm_bp_payout.py
index 294d092..1fb9c01 100644
--- a/tests/managers/thl/test_ledger/test_thl_lm_bp_payout.py
+++ b/tests/managers/thl/test_ledger/test_thl_lm_bp_payout.py
@@ -1,5 +1,5 @@
import logging
-from datetime import datetime, timezone, timedelta
+from datetime import UTC, datetime, timedelta, timezone
from decimal import Decimal
from random import randint
from uuid import uuid4
@@ -11,22 +11,22 @@ from redis.lock import Lock
from generalresearch.currency import USDCent
from generalresearch.managers.base import Permission
-from generalresearch.managers.thl.ledger_manager.thl_ledger import ThlLedgerManager
from generalresearch.managers.thl.ledger_manager.exceptions import (
- LedgerTransactionFlagAlreadyExistsError,
LedgerTransactionConditionFailedError,
- LedgerTransactionReleaseLockError,
LedgerTransactionCreateError,
+ LedgerTransactionFlagAlreadyExistsError,
+ LedgerTransactionReleaseLockError,
)
from generalresearch.managers.thl.ledger_manager.ledger import LedgerTransaction
+from generalresearch.managers.thl.ledger_manager.thl_ledger import ThlLedgerManager
from generalresearch.models import Source
from generalresearch.models.thl.definitions import PayoutStatus
from generalresearch.models.thl.ledger import Direction, TransactionType
from generalresearch.models.thl.session import (
- Wall,
+ Session,
Status,
StatusCode1,
- Session,
+ Wall,
)
from generalresearch.models.thl.user import User
from generalresearch.models.thl.wallet import PayoutType
@@ -55,7 +55,7 @@ class TestThlLedgerManagerBPPayout:
delete_ledger_db()
create_main_accounts()
- now = datetime.now(timezone.utc) - timedelta(hours=1)
+ now = datetime.now(UTC) - timedelta(hours=1)
user: User = user_factory(product=product_user_wallet_no)
wall1 = Wall(
@@ -158,7 +158,7 @@ class TestThlLedgerManagerBPPayout:
product=product,
amount=rand_amount,
payoutevent_uuid=payoutevent_uuid,
- created=datetime.now(tz=timezone.utc),
+ created=datetime.now(tz=UTC),
skip_wallet_balance_check=True,
skip_one_per_day_check=True,
skip_flag_check=True,
@@ -189,7 +189,7 @@ class TestThlLedgerManagerBPPayout:
product=product,
amount=rand_amount,
payoutevent_uuid=uuid4().hex,
- created=datetime.now(tz=timezone.utc),
+ created=datetime.now(tz=UTC),
skip_wallet_balance_check=False,
skip_one_per_day_check=False,
skip_flag_check=False,
@@ -199,7 +199,7 @@ class TestThlLedgerManagerBPPayout:
def test_create_tx_redis_failure(self, product, thl_web_rw, thl_lm):
rand_amount: USDCent = USDCent(randint(100, 1_000))
payoutevent_uuid = uuid4().hex
- now = datetime.now(tz=timezone.utc)
+ now = datetime.now(tz=UTC)
thl_lm.create_tx_plug_bp_wallet(
product, rand_amount, now, direction=Direction.CREDIT
@@ -226,7 +226,7 @@ class TestThlLedgerManagerBPPayout:
product=product,
amount=rand_amount,
payoutevent_uuid=payoutevent_uuid,
- created=datetime.now(tz=timezone.utc),
+ created=datetime.now(tz=UTC),
)
assert e.type is redis.exceptions.TimeoutError
# No txs were created
@@ -238,7 +238,7 @@ class TestThlLedgerManagerBPPayout:
def test_create_tx_multiple_per_day(self, product, thl_lm):
rand_amount: USDCent = USDCent(randint(100, 1_000))
payoutevent_uuid = uuid4().hex
- now = datetime.now(tz=timezone.utc)
+ now = datetime.now(tz=UTC)
thl_lm.create_tx_plug_bp_wallet(
product, rand_amount * USDCent(2), now, direction=Direction.CREDIT
@@ -248,7 +248,7 @@ class TestThlLedgerManagerBPPayout:
product=product,
amount=rand_amount,
payoutevent_uuid=payoutevent_uuid,
- created=datetime.now(tz=timezone.utc),
+ created=datetime.now(tz=UTC),
)
# Try to create another
@@ -258,7 +258,7 @@ class TestThlLedgerManagerBPPayout:
product=product,
amount=rand_amount,
payoutevent_uuid=payoutevent_uuid,
- created=datetime.now(tz=timezone.utc),
+ created=datetime.now(tz=UTC),
)
assert e.type is LedgerTransactionFlagAlreadyExistsError
@@ -270,7 +270,7 @@ class TestThlLedgerManagerBPPayout:
product=product,
amount=rand_amount,
payoutevent_uuid=payoutevent_uuid2,
- created=datetime.now(tz=timezone.utc),
+ created=datetime.now(tz=UTC),
)
assert e.type is LedgerTransactionConditionFailedError
assert str(e.value) == ">1 tx per day"
@@ -280,14 +280,14 @@ class TestThlLedgerManagerBPPayout:
product=product,
amount=rand_amount,
payoutevent_uuid=payoutevent_uuid2,
- created=datetime.now(tz=timezone.utc),
+ created=datetime.now(tz=UTC),
skip_one_per_day_check=True,
)
def test_create_tx_redis_lock_release_error(self, product, thl_lm):
rand_amount: USDCent = USDCent(randint(100, 1_000))
payoutevent_uuid = uuid4().hex
- now = datetime.now(tz=timezone.utc)
+ now = datetime.now(tz=UTC)
bp_wallet_account = thl_lm.get_account_or_create_bp_wallet(product=product)
thl_lm.create_tx_plug_bp_wallet(
@@ -304,7 +304,7 @@ class TestThlLedgerManagerBPPayout:
product=product,
amount=rand_amount,
payoutevent_uuid=payoutevent_uuid,
- created=datetime.now(tz=timezone.utc),
+ created=datetime.now(tz=UTC),
)
assert e.type is LedgerTransactionCreateError
assert str(e.value) == "Redis error: Simulated timeout during acquire"
@@ -321,7 +321,7 @@ class TestThlLedgerManagerBPPayout:
product=product,
amount=rand_amount,
payoutevent_uuid=payoutevent_uuid,
- created=datetime.now(tz=timezone.utc),
+ created=datetime.now(tz=UTC),
)
assert e.type is LedgerTransactionReleaseLockError
assert str(e.value) == "Redis error: Simulated timeout during release"
@@ -337,7 +337,7 @@ class TestPayoutEventManagerBPPayout:
def test_create(self, product, thl_lm, brokerage_product_payout_event_manager):
rand_amount: USDCent = USDCent(randint(100, 1_000))
- now = datetime.now(tz=timezone.utc)
+ now = datetime.now(tz=UTC)
bp_wallet_account = thl_lm.get_account_or_create_bp_wallet(product=product)
assert thl_lm.get_account_balance(bp_wallet_account) == 0
thl_lm.create_tx_plug_bp_wallet(
@@ -369,7 +369,7 @@ class TestPayoutEventManagerBPPayout:
original_release = Lock.release
rand_amount: USDCent = USDCent(randint(100, 1_000))
- now = datetime.now(tz=timezone.utc)
+ now = datetime.now(tz=UTC)
bp_wallet_account = thl_lm.get_account_or_create_bp_wallet(product=product)
assert thl_lm.get_account_balance(bp_wallet_account) == 0
thl_lm.create_tx_plug_bp_wallet(
@@ -435,7 +435,7 @@ class TestPayoutEventManagerBPPayout:
# We wouldn't do this in practice, because this is paying out the BP again, but
# we can if want to.
# Change the timestamp so it'll create a new payout event
- now = datetime.now(tz=timezone.utc)
+ now = datetime.now(tz=UTC)
with pytest.raises(LedgerTransactionConditionFailedError) as e:
pe = brokerage_product_payout_event_manager.create_bp_payout_event(
thl_ledger_manager=thl_lm,
@@ -450,7 +450,7 @@ class TestPayoutEventManagerBPPayout:
assert pe.status == PayoutStatus.FAILED
# And if we really want to, we can make it again
- now = datetime.now(tz=timezone.utc)
+ now = datetime.now(tz=UTC)
pe = brokerage_product_payout_event_manager.create_bp_payout_event(
thl_ledger_manager=thl_lm,
product=product,
@@ -478,7 +478,7 @@ class TestPayoutEventManagerBPPayout:
original_release = Lock.release
rand_amount: USDCent = USDCent(randint(100, 1_000))
- now = datetime.now(tz=timezone.utc)
+ now = datetime.now(tz=UTC)
bp_wallet_account = thl_lm.get_account_or_create_bp_wallet(product=product)
brokerage_product_payout_event_manager.set_account_lookup_table(thl_lm=thl_lm)
diff --git a/tests/managers/thl/test_ledger/test_thl_lm_tx.py b/tests/managers/thl/test_ledger/test_thl_lm_tx.py
index 31c7107..be988a1 100644
--- a/tests/managers/thl/test_ledger/test_thl_lm_tx.py
+++ b/tests/managers/thl/test_ledger/test_thl_lm_tx.py
@@ -1,5 +1,5 @@
import logging
-from datetime import datetime, timezone, timedelta
+from datetime import UTC, datetime, timedelta, timezone
from decimal import Decimal
from random import randint
from uuid import uuid4
@@ -14,23 +14,22 @@ from generalresearch.models import Source
from generalresearch.models.thl.definitions import (
WALL_ALLOWED_STATUS_STATUS_CODE,
)
-from generalresearch.models.thl.ledger import Direction
-from generalresearch.models.thl.ledger import TransactionType
+from generalresearch.models.thl.ledger import Direction, TransactionType
+from generalresearch.models.thl.payout import UserPayoutEvent
from generalresearch.models.thl.product import (
PayoutConfig,
PayoutTransformation,
UserWalletConfig,
)
from generalresearch.models.thl.session import (
- Wall,
+ Session,
Status,
StatusCode1,
- Session,
+ Wall,
WallAdjustedStatus,
)
from generalresearch.models.thl.user import User
from generalresearch.models.thl.wallet import PayoutType
-from generalresearch.models.thl.payout import UserPayoutEvent
logger = logging.getLogger("LedgerManager")
@@ -82,7 +81,7 @@ class TestThlLedgerTxManager:
session=s1,
status=Status.COMPLETE,
status_code_1=status_code_1,
- finished=datetime.now(tz=timezone.utc) + timedelta(minutes=10),
+ finished=datetime.now(tz=UTC) + timedelta(minutes=10),
payout=bp_pay,
user_payout=user_pay,
)
@@ -127,7 +126,7 @@ class TestThlLedgerTxManager:
session=s1,
status=Status.COMPLETE,
status_code_1=status_code_1,
- finished=datetime.now(tz=timezone.utc) + timedelta(minutes=10),
+ finished=datetime.now(tz=UTC) + timedelta(minutes=10),
payout=bp_pay,
user_payout=user_pay,
)
@@ -209,7 +208,7 @@ class TestThlLedgerTxManager:
# there is no financial changes needed
session.update(
**{
- "finished": datetime.now(tz=timezone.utc) + timedelta(minutes=10),
+ "finished": datetime.now(tz=UTC) + timedelta(minutes=10),
}
)
assert session.finished
@@ -229,7 +228,7 @@ class TestThlLedgerTxManager:
product=product,
amount=rand_amount,
payoutevent_uuid=payoutevent_uuid,
- created=datetime.now(tz=timezone.utc),
+ created=datetime.now(tz=UTC),
skip_wallet_balance_check=True,
skip_one_per_day_check=True,
skip_flag_check=True,
@@ -260,7 +259,7 @@ class TestThlLedgerTxManager:
product=product,
amount=rand_amount,
payoutevent_uuid=uuid4().hex,
- created=datetime.now(tz=timezone.utc),
+ created=datetime.now(tz=UTC),
skip_wallet_balance_check=False,
skip_one_per_day_check=False,
skip_flag_check=False,
@@ -276,7 +275,7 @@ class TestThlLedgerTxManager:
product=product,
amount=rand_amount,
payoutevent_uuid=payoutevent_uuid,
- created=datetime.now(tz=timezone.utc),
+ created=datetime.now(tz=UTC),
)
# Check the basic attributes
@@ -300,7 +299,7 @@ class TestThlLedgerTxManager:
tx = thl_lm.create_tx_plug_bp_wallet(
product=product,
amount=rand_amount,
- created=datetime.now(tz=timezone.utc),
+ created=datetime.now(tz=UTC),
direction=Direction.DEBIT,
skip_flag_check=False,
)
@@ -328,7 +327,7 @@ class TestThlLedgerTxManager:
tx = thl_lm.create_tx_plug_bp_wallet_(
product=product,
amount=rand_amount,
- created=datetime.now(tz=timezone.utc),
+ created=datetime.now(tz=UTC),
direction=Direction.DEBIT,
)
@@ -345,7 +344,7 @@ class TestThlLedgerTxManager:
thl_lm.create_tx_plug_bp_wallet_(
product=product,
amount=rand_amount + rand_amount,
- created=datetime.now(tz=timezone.utc),
+ created=datetime.now(tz=UTC),
direction=Direction.CREDIT,
)
balance = thl_lm.get_account_balance(
@@ -727,8 +726,8 @@ class TestThlLedgerTxManagerFlows:
session_id=1,
status=Status.COMPLETE,
status_code_1=StatusCode1.COMPLETE,
- started=datetime.now(timezone.utc),
- finished=datetime.now(timezone.utc) + timedelta(seconds=1),
+ started=datetime.now(UTC),
+ finished=datetime.now(UTC) + timedelta(seconds=1),
)
thl_lm.create_tx_task_complete(wall=wall1, user=user, created=wall1.started)
@@ -740,8 +739,8 @@ class TestThlLedgerTxManagerFlows:
session_id=1,
status=Status.COMPLETE,
status_code_1=StatusCode1.COMPLETE,
- started=datetime.now(timezone.utc),
- finished=datetime.now(timezone.utc) + timedelta(seconds=1),
+ started=datetime.now(UTC),
+ finished=datetime.now(UTC) + timedelta(seconds=1),
)
thl_lm.create_tx_task_complete(wall=wall2, user=user, created=wall2.started)
@@ -793,8 +792,8 @@ class TestThlLedgerTxManagerFlows:
session_id=1,
status=Status.COMPLETE,
status_code_1=StatusCode1.COMPLETE,
- started=datetime.now(timezone.utc),
- finished=datetime.now(timezone.utc) + timedelta(seconds=1),
+ started=datetime.now(UTC),
+ finished=datetime.now(UTC) + timedelta(seconds=1),
)
tx = thl_lm.create_tx_task_complete(
wall=wall1, user=user, created=wall1.started
@@ -880,8 +879,8 @@ class TestThlLedgerTxManagerFlows:
session_id=3,
status=Status.COMPLETE,
status_code_1=StatusCode1.COMPLETE,
- started=datetime.now(timezone.utc),
- finished=datetime.now(timezone.utc) + timedelta(seconds=1),
+ started=datetime.now(UTC),
+ finished=datetime.now(UTC) + timedelta(seconds=1),
)
tx = thl_lm.create_tx_task_complete(
@@ -922,8 +921,8 @@ class TestThlLedgerTxManagerFlows:
session_id=3,
status=Status.COMPLETE,
status_code_1=StatusCode1.COMPLETE,
- started=datetime.now(timezone.utc),
- finished=datetime.now(timezone.utc) + timedelta(seconds=1),
+ started=datetime.now(UTC),
+ finished=datetime.now(UTC) + timedelta(seconds=1),
)
thl_lm.create_tx_task_complete(wall=wall1, user=user, created=wall1.started)
@@ -963,8 +962,8 @@ class TestThlLedgerTxManagerFlows:
session_id=3,
status=Status.COMPLETE,
status_code_1=StatusCode1.COMPLETE,
- started=datetime.now(timezone.utc),
- finished=datetime.now(timezone.utc) + timedelta(seconds=1),
+ started=datetime.now(UTC),
+ finished=datetime.now(UTC) + timedelta(seconds=1),
)
thl_lm.create_tx_task_complete(wall=wall1, user=user, created=wall1.started)
@@ -1416,7 +1415,7 @@ class TestThlLedgerManagerAdj:
delete_ledger_db()
create_main_accounts()
- now = datetime.now(timezone.utc) - timedelta(days=1)
+ now = datetime.now(UTC) - timedelta(days=1)
user: User = user_factory(product=product_user_wallet_yes)
# Create 2 Wall completes and create the respective transaction for
diff --git a/tests/managers/thl/test_ledger/test_thl_lm_tx__user_payouts.py b/tests/managers/thl/test_ledger/test_thl_lm_tx__user_payouts.py
index 1e7146a..9253ff0 100644
--- a/tests/managers/thl/test_ledger/test_thl_lm_tx__user_payouts.py
+++ b/tests/managers/thl/test_ledger/test_thl_lm_tx__user_payouts.py
@@ -1,17 +1,17 @@
import logging
-from datetime import datetime, timezone, timedelta
+from datetime import UTC, datetime, timedelta, timezone
from decimal import Decimal
from uuid import uuid4
import pytest
from generalresearch.managers.thl.ledger_manager.exceptions import (
- LedgerTransactionFlagAlreadyExistsError,
LedgerTransactionConditionFailedError,
+ LedgerTransactionFlagAlreadyExistsError,
)
+from generalresearch.models.thl.payout import UserPayoutEvent
from generalresearch.models.thl.user import User
from generalresearch.models.thl.wallet import PayoutType
-from generalresearch.models.thl.payout import UserPayoutEvent
from test_utils.managers.ledger.conftest import create_main_accounts
@@ -243,7 +243,7 @@ class TestLedgerManagerAMT:
delete_ledger_db()
create_main_accounts()
- now = datetime.now(timezone.utc) - timedelta(hours=1)
+ now = datetime.now(UTC) - timedelta(hours=1)
user: User = user_factory(product=product_amt_true)
pe = UserPayoutEvent(
@@ -394,7 +394,7 @@ class TestLedgerManagerPaypal:
delete_ledger_db()
create_main_accounts()
- now = datetime.now(tz=timezone.utc) - timedelta(hours=1)
+ now = datetime.now(tz=UTC) - timedelta(hours=1)
user: User = user_factory(product=product_amt_true)
# debit_account_uuid nothing checks they match the ledger ... todo?
diff --git a/tests/managers/thl/test_ledger/test_user_txs.py b/tests/managers/thl/test_ledger/test_user_txs.py
index ecf146f..b4b0437 100644
--- a/tests/managers/thl/test_ledger/test_user_txs.py
+++ b/tests/managers/thl/test_ledger/test_user_txs.py
@@ -1,6 +1,7 @@
-from datetime import datetime, timedelta, timezone
+from collections.abc import Callable
+from datetime import UTC, datetime, timedelta, timezone
from decimal import Decimal
-from typing import TYPE_CHECKING, Callable
+from typing import TYPE_CHECKING
from uuid import uuid4
from generalresearch.managers.thl.ledger_manager.thl_ledger import ThlLedgerManager
@@ -24,8 +25,8 @@ if TYPE_CHECKING:
def test_user_txs(
- user_factory: Callable[..., "User"],
- product_amt_true: "Product",
+ user_factory: Callable[..., User],
+ product_amt_true: Product,
create_main_accounts: Callable[..., None],
thl_lm: ThlLedgerManager,
lm,
@@ -36,7 +37,7 @@ def test_user_txs(
session_factory,
user_payout_event_manager,
utc_now: datetime,
- settings: "GRLSettings",
+ settings: GRLSettings,
):
delete_ledger_db()
create_main_accounts()
@@ -136,13 +137,13 @@ def test_user_txs(
def test_user_txs_pagination(
- user_factory: Callable[..., "User"],
- product_amt_true: "Product",
+ user_factory: Callable[..., User],
+ product_amt_true: Product,
create_main_accounts: Callable[..., None],
- thl_lm: "ThlLedgerManager",
- lm: "LedgerManager",
+ thl_lm: ThlLedgerManager,
+ lm: LedgerManager,
delete_ledger_db: Callable[..., None],
- session_with_tx_factory: Callable[..., "Session"],
+ session_with_tx_factory: Callable[..., Session],
adj_to_fail_with_tx_factory,
user_payout_event_manager,
utc_now: datetime,
@@ -187,7 +188,7 @@ def test_user_txs_pagination(
assert txs.summary.user_bonus.entry_count == 12
# Test filtering. We should pull back only this one
- now = datetime.now(tz=timezone.utc)
+ now = datetime.now(tz=UTC)
user_compensate(
ledger_manager=thl_lm,
user=user,
@@ -203,7 +204,7 @@ def test_user_txs_pagination(
assert txs.summary.user_bonus.entry_count == 1
# And filtering with 0 results
- now = datetime.now(tz=timezone.utc)
+ now = datetime.now(tz=UTC)
txs = thl_lm.get_user_txs(user, page=1, size=5, time_start=now)
assert len(txs.transactions) == 0
assert txs.total == 0
@@ -215,8 +216,8 @@ def test_user_txs_pagination(
def test_user_txs_rolling_balance(
- user_factory: Callable[..., "User"],
- product_amt_true: "Product",
+ user_factory: Callable[..., User],
+ product_amt_true: Product,
create_main_accounts,
thl_lm,
lm,
@@ -224,7 +225,7 @@ def test_user_txs_rolling_balance(
session_with_tx_factory,
adj_to_fail_with_tx_factory,
user_payout_event_manager,
- settings: "GRLSettings",
+ settings: GRLSettings,
):
"""
Creates 3 $1.00 bonuses (postive),
--
cgit v1.2.3
From e2c5de703be45746bacaea4136f24440ff5a291c Mon Sep 17 00:00:00 2001
From: Max Nanis
Date: Mon, 24 Aug 2026 12:35:35 -0700
Subject: Ruff std replacements
---
generalresearch/__init__.py | 2 +-
generalresearch/config.py | 2 +-
generalresearch/grliq/managers/event_plotter.py | 4 +-
generalresearch/grliq/managers/forensic_data.py | 4 +-
generalresearch/grliq/managers/forensic_events.py | 76 ++++++++++------------
generalresearch/grliq/managers/forensic_results.py | 7 +-
generalresearch/grliq/models/custom_types.py | 3 +-
generalresearch/grliq/models/forensic_data.py | 1 -
generalresearch/grliq/models/forensic_summary.py | 3 +-
generalresearch/grliq/utils.py | 2 +-
generalresearch/grpc.py | 2 +-
generalresearch/incite/base.py | 10 +--
generalresearch/incite/collections/__init__.py | 18 ++---
generalresearch/incite/defaults.py | 2 +-
.../incite/mergers/foundations/__init__.py | 2 +-
.../incite/mergers/foundations/enriched_session.py | 10 +--
.../mergers/foundations/enriched_task_adjust.py | 5 +-
.../incite/mergers/foundations/enriched_wall.py | 8 +--
generalresearch/incite/mergers/ym_survey_wall.py | 10 ++-
generalresearch/incite/mergers/ym_wall_summary.py | 3 +-
generalresearch/incite/schemas/thl_web.py | 2 +-
generalresearch/locales/setup_json.py | 1 +
generalresearch/locales/timezone.py | 1 -
generalresearch/managers/cint/survey.py | 2 +-
generalresearch/managers/criteria.py | 4 +-
generalresearch/managers/dynata/survey.py | 2 +-
generalresearch/managers/events.py | 4 +-
generalresearch/managers/gr/authentication.py | 5 +-
generalresearch/managers/gr/team.py | 2 +-
generalresearch/managers/innovate/survey.py | 2 +-
generalresearch/managers/leaderboard/__init__.py | 3 +-
generalresearch/managers/leaderboard/manager.py | 2 +-
generalresearch/managers/morning/survey.py | 2 +-
generalresearch/managers/network/label.py | 9 ++-
generalresearch/managers/network/tool_run.py | 22 +++----
generalresearch/managers/precision/survey.py | 10 +--
generalresearch/managers/prodege/survey.py | 2 +-
generalresearch/managers/repdata/survey.py | 4 +-
generalresearch/managers/sago/survey.py | 2 +-
generalresearch/managers/spectrum/survey.py | 2 +-
generalresearch/managers/survey.py | 2 -
generalresearch/managers/thl/buyer.py | 2 +-
generalresearch/managers/thl/cashout_method.py | 2 +-
generalresearch/managers/thl/contest_manager.py | 3 +-
.../managers/thl/ledger_manager/conditions.py | 4 +-
.../managers/thl/ledger_manager/exceptions.py | 5 --
.../managers/thl/ledger_manager/ledger.py | 15 ++---
.../managers/thl/ledger_manager/thl_ledger.py | 22 +++----
generalresearch/managers/thl/product.py | 10 +--
generalresearch/managers/thl/profiling/question.py | 2 +-
generalresearch/managers/thl/profiling/uqa.py | 2 +-
generalresearch/managers/thl/profiling/user_upk.py | 2 +-
generalresearch/managers/thl/session.py | 11 +---
generalresearch/managers/thl/survey.py | 25 ++++---
generalresearch/managers/thl/task_adjustment.py | 7 +-
generalresearch/managers/thl/user_compensate.py | 2 +-
.../thl/user_manager/mysql_user_manager.py | 2 +-
.../managers/thl/user_manager/user_manager.py | 1 -
generalresearch/managers/thl/userhealth.py | 2 +-
generalresearch/managers/thl/wall.py | 2 +-
generalresearch/managers/thl/wallet/tango.py | 2 +-
generalresearch/models/admin/request.py | 2 +-
generalresearch/models/custom_types.py | 3 +-
generalresearch/models/dynata/survey.py | 4 +-
generalresearch/models/gr/authentication.py | 5 +-
generalresearch/models/gr/business.py | 6 +-
generalresearch/models/gr/team.py | 7 +-
generalresearch/models/legacy/questions.py | 3 -
generalresearch/models/network/mtr/execute.py | 2 +-
generalresearch/models/network/nmap/parser.py | 2 +-
generalresearch/models/network/rdns/execute.py | 2 +-
generalresearch/models/spectrum/survey.py | 2 +-
generalresearch/models/string_utils.py | 1 -
generalresearch/models/thl/contest/contest.py | 4 +-
.../models/thl/contest/contest_entry.py | 2 +-
generalresearch/models/thl/contest/examples.py | 7 --
generalresearch/models/thl/contest/io.py | 2 +-
generalresearch/models/thl/contest/leaderboard.py | 2 +-
generalresearch/models/thl/contest/milestone.py | 3 +-
generalresearch/models/thl/contest/raffle.py | 2 +-
generalresearch/models/thl/finance.py | 5 +-
generalresearch/models/thl/ipinfo.py | 2 +-
generalresearch/models/thl/ledger_example.py | 2 +-
generalresearch/models/thl/offerwall/cache.py | 2 +-
generalresearch/models/thl/payout_format.py | 12 ++--
generalresearch/models/thl/product.py | 2 -
.../models/thl/profiling/marketplace.py | 2 +-
.../models/thl/profiling/upk_question.py | 2 +-
.../models/thl/profiling/upk_question_answer.py | 2 +-
.../models/thl/profiling/user_question_answer.py | 2 +-
generalresearch/models/thl/session.py | 2 +-
generalresearch/models/thl/survey/__init__.py | 3 -
generalresearch/models/thl/survey/buyer.py | 2 +-
generalresearch/models/thl/survey/model.py | 2 +-
generalresearch/models/thl/survey/penalty.py | 2 +-
generalresearch/models/thl/task_adjustment.py | 2 +-
generalresearch/models/thl/user.py | 2 +-
generalresearch/models/thl/user_iphistory.py | 3 +-
generalresearch/models/thl/wallet/payout.py | 2 +-
generalresearch/pg_helper.py | 12 ++--
generalresearch/schemas/survey_stats.py | 2 +-
generalresearch/sql_helper.py | 19 ++----
generalresearch/thl_django/apps.py | 14 ++--
generalresearch/thl_django/fields.py | 3 +-
.../thl_django/migrations/0001_initial.py | 3 +-
..._live_alter_surveycategory_strength_and_more.py | 2 +-
...rveystat_surveystat_live_survey_idx_and_more.py | 2 +-
...ssion_thl_session_status_d578b7_idx_and_more.py | 2 +-
...p_portscanport_iplabel_mtr_portscan_and_more.py | 5 +-
generalresearch/thl_django/network/models.py | 5 +-
generalresearch/utils/enum.py | 4 +-
generalresearch/wall_status_codes/lucid.py | 2 +-
generalresearch/wall_status_codes/morning.py | 2 +-
generalresearch/wall_status_codes/pollfish.py | 2 +-
generalresearch/wall_status_codes/precision.py | 2 +-
generalresearch/wall_status_codes/repdata.py | 2 +-
test_utils/conftest.py | 3 +-
test_utils/grliq/conftest.py | 2 +-
test_utils/incite/conftest.py | 2 +-
test_utils/managers/conftest.py | 2 -
test_utils/models/conftest.py | 9 +--
test_utils/models/contest/conftest.py | 2 +-
test_utils/models/network/conftest.py | 2 +-
test_utils/models/thl/conftest.py | 2 +-
test_utils/spectrum/conftest.py | 2 +-
.../incite/collections/test_df_collection_base.py | 3 +-
.../collections/test_df_collection_item_base.py | 2 +-
.../collections/test_df_collection_item_thl_web.py | 11 +---
.../test_df_collection_thl_marketplaces.py | 7 +-
.../collections/test_df_collection_thl_web.py | 2 -
.../mergers/foundations/test_enriched_session.py | 7 +-
.../foundations/test_enriched_task_adjust.py | 7 --
.../mergers/foundations/test_enriched_wall.py | 23 +------
.../mergers/foundations/test_user_id_product.py | 15 +----
tests/incite/mergers/test_merge_collection.py | 3 +-
tests/incite/mergers/test_merge_collection_item.py | 9 +--
tests/incite/mergers/test_pop_ledger.py | 8 +--
tests/incite/mergers/test_ym_survey_merge.py | 17 +----
tests/incite/test_collection_base.py | 3 +-
tests/incite/test_collection_base_item.py | 2 +-
tests/incite/test_grl_flow.py | 11 ++--
tests/incite/test_interval_idx.py | 3 +-
tests/managers/gr/test_authentication.py | 3 -
tests/managers/gr/test_business.py | 4 +-
tests/managers/gr/test_team.py | 2 -
tests/managers/leaderboard.py | 2 +-
tests/managers/network/test_label.py | 2 +-
tests/managers/test_events.py | 15 ++---
tests/managers/test_userpid.py | 4 +-
.../managers/thl/test_contest/test_leaderboard.py | 8 +--
tests/managers/thl/test_contest/test_milestone.py | 14 +---
tests/managers/thl/test_contest/test_raffle.py | 14 +---
tests/managers/thl/test_harmonized_uqa.py | 2 +-
tests/managers/thl/test_ipinfo.py | 2 +-
tests/managers/thl/test_ledger/test_lm_accounts.py | 6 --
tests/managers/thl/test_ledger/test_lm_tx_locks.py | 23 ++-----
.../thl/test_ledger/test_thl_lm_accounts.py | 32 ++++-----
.../thl/test_ledger/test_thl_lm_bp_payout.py | 10 +--
tests/managers/thl/test_ledger/test_thl_lm_tx.py | 64 +++---------------
.../test_ledger/test_thl_lm_tx__user_payouts.py | 3 +-
tests/managers/thl/test_ledger/test_thl_pem.py | 7 +-
tests/managers/thl/test_ledger/test_user_txs.py | 3 +-
tests/managers/thl/test_ledger/test_wallet.py | 2 +-
tests/managers/thl/test_product.py | 9 ++-
tests/managers/thl/test_product_prod.py | 2 -
tests/managers/thl/test_profiling/test_user_upk.py | 2 +-
tests/managers/thl/test_session_manager.py | 7 +-
tests/managers/thl/test_survey.py | 2 +-
tests/managers/thl/test_survey_penalty.py | 1 -
tests/managers/thl/test_task_adjustment.py | 2 +-
tests/managers/thl/test_task_status.py | 2 +-
tests/managers/thl/test_user_manager/test_base.py | 4 +-
tests/managers/thl/test_user_manager/test_mysql.py | 1 -
.../thl/test_user_manager/test_user_fetch.py | 1 -
.../thl/test_user_manager/test_user_metadata.py | 1 -
tests/managers/thl/test_user_streak.py | 2 +-
tests/managers/thl/test_userhealth.py | 2 +-
tests/managers/thl/test_wall_manager.py | 13 ++--
tests/models/admin/test_report_request.py | 2 +-
tests/models/custom_types/test_aware_datetime.py | 2 +-
tests/models/custom_types/test_dsn.py | 1 -
tests/models/dynata/test_eligbility.py | 2 +-
tests/models/gr/test_authentication.py | 2 +-
tests/models/gr/test_business.py | 3 +-
tests/models/innovate/test_question.py | 6 +-
.../models/legacy/test_user_question_answer_in.py | 4 +-
tests/models/morning/test.py | 2 +-
tests/models/network/test_mtr.py | 4 +-
tests/models/network/test_nmap_parser.py | 1 +
tests/models/prodege/test_survey_participation.py | 2 +-
tests/models/spectrum/test_question.py | 2 +-
tests/models/spectrum/test_survey.py | 2 +-
tests/models/spectrum/test_survey_manager.py | 2 +-
tests/models/test_finance.py | 2 +-
tests/models/thl/question/test_question_info.py | 2 +-
tests/models/thl/test_adjustments.py | 30 ++-------
.../thl/test_contest/test_leaderboard_contest.py | 2 +-
tests/models/thl/test_ledger.py | 2 +-
tests/models/thl/test_payout.py | 5 +-
tests/models/thl/test_product.py | 2 +-
tests/models/thl/test_upkquestion.py | 12 +---
tests/models/thl/test_user.py | 6 +-
tests/models/thl/test_user_iphistory.py | 2 +-
tests/models/thl/test_user_streak.py | 2 +-
tests/models/thl/test_wall.py | 2 +-
tests/models/thl/test_wall_session.py | 2 +-
tests/sql_helper.py | 4 +-
207 files changed, 398 insertions(+), 725 deletions(-)
(limited to 'tests/managers/thl/test_ledger')
diff --git a/generalresearch/__init__.py b/generalresearch/__init__.py
index 604b7e2..3b2ec3d 100644
--- a/generalresearch/__init__.py
+++ b/generalresearch/__init__.py
@@ -129,7 +129,7 @@ def synchronized(wrapped):
if lock is None:
lock = threading.RLock()
- setattr(context, "_synchronized_lock", lock)
+ context._synchronized_lock = lock
return lock
diff --git a/generalresearch/config.py b/generalresearch/config.py
index 76e3995..c6f41e8 100644
--- a/generalresearch/config.py
+++ b/generalresearch/config.py
@@ -1,7 +1,7 @@
from __future__ import annotations
import os
-from datetime import UTC, datetime, timezone
+from datetime import UTC, datetime
from pathlib import Path
from pydantic import DirectoryPath, Field, MariaDBDsn, PostgresDsn, RedisDsn
diff --git a/generalresearch/grliq/managers/event_plotter.py b/generalresearch/grliq/managers/event_plotter.py
index 0bba7c5..94b70ef 100644
--- a/generalresearch/grliq/managers/event_plotter.py
+++ b/generalresearch/grliq/managers/event_plotter.py
@@ -13,7 +13,7 @@ def make_events_svg(
mouse_events: list[MouseEvent], keyboard_events: list[KeyboardEvent]
) -> str:
if len(mouse_events) + len(keyboard_events) == 0:
- return f'"
+ return '"
t = np.array([pm.timeStamp for pm in mouse_events])
t_diff = t.max() - t.min()
@@ -88,7 +88,7 @@ def make_events_svg(
svg_elements.append(svg_multiline_text(text, cx + 5, cy - 5, font_size))
svg = (
- f'