aboutsummaryrefslogtreecommitdiff
path: root/tests/models
diff options
context:
space:
mode:
authorMax Nanis2026-08-24 17:12:54 -0700
committerMax Nanis2026-08-24 17:12:54 -0700
commit5682f48a96b0713929a4bb52e72eec5907d5dd32 (patch)
tree3e5ba728145cf69f4ea0fde48e630b341c164cd0 /tests/models
parent979efd01b0c61d493d1fef3dff9885f5d38a8975 (diff)
downloadgeneralresearch-5682f48a96b0713929a4bb52e72eec5907d5dd32.tar.gz
generalresearch-5682f48a96b0713929a4bb52e72eec5907d5dd32.zip
pytest fixture annotations, ruf manual edits
Diffstat (limited to 'tests/models')
-rw-r--r--tests/models/custom_types/test_aware_datetime.py2
-rw-r--r--tests/models/gr/test_business.py100
-rw-r--r--tests/models/test_currency.py114
3 files changed, 69 insertions, 147 deletions
diff --git a/tests/models/custom_types/test_aware_datetime.py b/tests/models/custom_types/test_aware_datetime.py
index 7c45710..e8a5aa3 100644
--- a/tests/models/custom_types/test_aware_datetime.py
+++ b/tests/models/custom_types/test_aware_datetime.py
@@ -42,7 +42,7 @@ class TestAwareDatetimeISO:
AwareDatetimeISOModel.model_validate_json(t.model_dump_json())
def test_no_tz(self):
- dt = datetime(2023, 10, 10, 1, 1, 1)
+ dt = datetime(2023, 10, 10, 1, 1, 1) # noqa
with pytest.raises(expected_exception=ValidationError):
AwareDatetimeISOModel(dt=dt, dt_optional=None)
diff --git a/tests/models/gr/test_business.py b/tests/models/gr/test_business.py
index 9554028..48a7bb0 100644
--- a/tests/models/gr/test_business.py
+++ b/tests/models/gr/test_business.py
@@ -4,6 +4,7 @@ import os
from collections.abc import Callable
from datetime import UTC, datetime, timedelta
from decimal import Decimal
+from pathlib import Path
from uuid import uuid4
import pandas as pd
@@ -17,6 +18,8 @@ from distributed.utils_test import (
from pytest import approx
from generalresearch.currency import USDCent
+from generalresearch.incite.base import GRLDatasets
+from generalresearch.incite.mergers.pop_ledger import PopLedgerMerge
from generalresearch.managers.gr.business import BusinessBankAccountManager
from generalresearch.managers.gr.team import TeamManager
from generalresearch.managers.thl.ledger_manager.ledger import LedgerManager
@@ -31,7 +34,7 @@ from generalresearch.models.gr.business import (
BusinessBankAccount,
BusinessContact,
)
-from generalresearch.models.gr.team import Membership, Team
+from generalresearch.models.gr.team import Team
from generalresearch.models.thl.finance import (
BusinessBalances,
ProductBalances,
@@ -121,7 +124,7 @@ class TestBusiness:
ledger_manager: LedgerManager,
thl_ledger_manager: ThlLedgerManager,
business_payout_event_manager: BusinessPayoutEventManager,
- bp_payout_factory: Callable[..., Bus],
+ bp_payout_factory: Callable[..., BusinessPayoutEventManager],
start: datetime,
user_factory: Callable[..., User],
session_with_tx_factory: Callable[..., Session],
@@ -244,8 +247,8 @@ class TestBusiness:
assert business.products[0].uuid == p1.uuid
# Add two more, but list is still one until we prefetch
- p2 = product_factory(business=business)
- p3 = product_factory(business=business)
+ product_factory(business=business)
+ product_factory(business=business)
assert len(business.products) == 1
business.prefetch_products(thl_pg_config=thl_web_rr)
@@ -262,11 +265,11 @@ class TestBusiness:
def test_balance(
self,
business: Business,
- mnt_filepath,
+ mnt_filepath: GRLDatasets,
client_no_amm: DaskClient,
thl_web_rr: PostgresConfig,
ledger_manager: LedgerManager,
- pop_ledger_merge,
+ pop_ledger_merge: PopLedgerMerge,
):
assert business.balance is None
@@ -357,6 +360,7 @@ class TestBusiness:
thl_lm=thl_ledger_manager,
bpem=business_payout_event_manager,
)
+ assert isinstance(business.payouts, list)
assert len(business.payouts) == 1
assert len(business.payouts[0].bp_payouts) == 2
assert sum([p.amount for p in business.payouts]) == 246
@@ -407,6 +411,7 @@ class TestBusiness:
bpem=business_payout_event_manager,
)
+ assert isinstance(business.payouts, list)
assert len(business.payouts) == 1
assert len(business.payouts[0].bp_payouts) == 3
assert business.payouts_total == USDCent(76)
@@ -417,9 +422,9 @@ class TestBusiness:
business: Business,
thl_web_rr: PostgresConfig,
thl_ledger_manager: ThlLedgerManager,
- mnt_filepath,
+ mnt_filepath: GRLDatasets,
client_no_amm: DaskClient,
- pop_ledger_merge,
+ pop_ledger_merge: PopLedgerMerge,
):
assert business.pop_financial is None
business.prebuild_pop_financial(
@@ -479,20 +484,15 @@ class TestBusinessBalance:
product_factory: Callable[..., Product],
user_factory: Callable[..., User],
mnt_filepath,
- bp_payout_factory: Callable[..., BrokerageProductPayoutEvent],
- thl_ledger_manager: ThlLedgerManager,
ledger_manager: LedgerManager,
- duration: timedelta,
- offset,
start: datetime,
thl_web_rr: PostgresConfig,
- payout_event_manager: PayoutEventManager,
session_with_tx_factory: Callable[..., Session],
delete_ledger_db: Callable[..., None],
create_main_accounts: Callable[..., None],
client_no_amm: DaskClient,
ledger_collection,
- pop_ledger_merge,
+ pop_ledger_merge: PopLedgerMerge,
delete_df_collection: Callable[..., None],
):
delete_ledger_db()
@@ -544,15 +544,10 @@ class TestBusinessBalance:
business: Business,
product_factory: Callable[..., Product],
user_factory: Callable[..., User],
- mnt_filepath,
- bp_payout_factory: Callable[..., BrokerageProductPayoutEvent],
+ mnt_filepath: GRLDatasets,
ledger_manager: LedgerManager,
- thl_ledger_manager: ThlLedgerManager,
- duration: timedelta,
- offset,
start: datetime,
thl_web_rr: PostgresConfig,
- payout_event_manager: PayoutEventManager,
session_with_tx_factory: Callable[..., Session],
delete_ledger_db: Callable[..., None],
create_main_accounts: Callable[..., None],
@@ -633,12 +628,10 @@ class TestBusinessBalance:
business: Business,
product_factory: Callable[..., Product],
user_factory: Callable[..., User],
- mnt_filepath,
+ mnt_filepath: GRLDatasets,
bp_payout_factory: Callable[..., BrokerageProductPayoutEvent],
thl_ledger_manager: ThlLedgerManager,
ledger_manager: LedgerManager,
- duration: timedelta,
- offset,
start: datetime,
thl_web_rr: PostgresConfig,
payout_event_manager: PayoutEventManager,
@@ -709,12 +702,10 @@ class TestBusinessBalance:
business: Business,
product_factory: Callable[..., Product],
user_factory: Callable[..., User],
- mnt_filepath,
+ mnt_filepath: GRLDatasets,
bp_payout_factory: Callable[..., BrokerageProductPayoutEvent],
ledger_manager: LedgerManager,
thl_ledger_manager: ThlLedgerManager,
- duration: timedelta,
- offset,
start: datetime,
thl_web_rr: PostgresConfig,
payout_event_manager: PayoutEventManager,
@@ -724,8 +715,6 @@ class TestBusinessBalance:
ledger_collection,
task_adj_collection,
pop_ledger_merge: PopLedgerMerge,
- wall_manager: WallManager,
- session_manager: SessionManager,
adj_to_fail_with_tx_factory: Callable[..., None],
delete_df_collection: Callable[..., None],
):
@@ -837,12 +826,9 @@ class TestBusinessBalance:
def test_neg_balance_cache(
self,
- product: Product,
- mnt_filepath,
+ mnt_filepath: GRLDatasets,
thl_ledger_manager: ThlLedgerManager,
client_no_amm: DaskClient,
- thl_redis_config: RedisConfig,
- brokerage_product_payout_event_manager,
delete_ledger_db: Callable[..., None],
create_main_accounts: Callable[..., None],
delete_df_collection: Callable[..., None],
@@ -913,13 +899,14 @@ class TestBusinessBalance:
business.prebuild_balance(
thl_pg_config=thl_web_rr,
- lm=lm,
+ lm=ledger_manager,
ds=mnt_filepath,
client=client_no_amm,
pop_ledger=pop_ledger_merge,
)
# Check Product 1
+ assert isinstance(business.balance, BusinessBalances)
pb1 = business.balance.product_balances[0]
assert pb1.product_id == p1.uuid
assert pb1.payout == 71
@@ -962,25 +949,21 @@ class TestBusinessBalance:
business: Business,
product_factory: Callable[..., Product],
user_factory: Callable[..., User],
- mnt_filepath,
+ mnt_filepath: GRLDatasets,
bp_payout_factory: Callable[..., BrokerageProductPayoutEvent],
thl_ledger_manager: ThlLedgerManager,
ledger_manager: LedgerManager,
- duration: timedelta,
- offset,
start: datetime,
thl_web_rr: PostgresConfig,
payout_event_manager,
session_with_tx_factory,
- delete_ledger_db,
+ delete_ledger_db: Callable[..., None],
create_main_accounts: Callable[..., None],
client_no_amm: DaskClient,
ledger_collection,
task_adj_collection,
- pop_ledger_merge,
- wall_manager: WallManager,
- session_manager: SessionManager,
- adj_to_fail_with_tx_factory,
+ pop_ledger_merge: PopLedgerMerge,
+ adj_to_fail_with_tx_factory: Callable[..., None],
delete_df_collection: Callable[..., None],
):
"""
@@ -1205,22 +1188,21 @@ class TestBusinessMethods:
gr_db: PostgresConfig,
thl_web_rr: PostgresConfig,
client_no_amm: DaskClient,
- mnt_filepath,
+ mnt_filepath: GRLDatasets,
ledger_manager: LedgerManager,
thl_ledger_manager: ThlLedgerManager,
business_payout_event_manager,
product_factory: Callable[..., Product],
- membership_factory: Callable[..., Membership],
team: Team,
session_with_tx_factory: Callable[..., Session],
user_factory: Callable[..., User],
ledger_collection,
- pop_ledger_merge,
+ pop_ledger_merge: PopLedgerMerge,
utc_60days_ago: datetime,
delete_ledger_db: Callable[..., None],
create_main_accounts: Callable[..., None],
gr_redis_config: RedisConfig,
- mnt_gr_api_dir,
+ mnt_gr_api_dir: Path,
):
assert gr_redis.get(name=business.cache_key) is None
@@ -1263,17 +1245,13 @@ class TestBusinessMethods:
def test_set_cache_business(
self,
- gr_user: GRUser,
business: Business,
- gr_user_token: GRUserToken,
- gr_redis: RedisConfig,
gr_db: PostgresConfig,
thl_web_rr: PostgresConfig,
product_factory: Callable[..., Product],
team: Team,
- membership_factory: Callable[..., Membership],
client_no_amm: DaskClient,
- mnt_filepath,
+ mnt_filepath: GRLDatasets,
ledger_manager: LedgerManager,
thl_ledger_manager: ThlLedgerManager,
business_payout_event_manager,
@@ -1283,10 +1261,10 @@ class TestBusinessMethods:
session_with_tx_factory: Callable[..., Session],
ledger_collection,
team_manager: TeamManager,
- pop_ledger_merge,
+ pop_ledger_merge: PopLedgerMerge,
gr_redis_config: RedisConfig,
utc_60days_ago: datetime,
- mnt_gr_api_dir,
+ mnt_gr_api_dir: Path,
):
from generalresearch.models.gr.business import Business
@@ -1336,12 +1314,16 @@ class TestBusinessMethods:
gr_redis_config=gr_redis_config,
)
+ assert isinstance(business2, Business)
assert business.model_dump_json() == business2.model_dump_json()
# assert isinstance(business2.balance, BusinessBalances)
+ assert isinstance(business2.products, list)
+ assert isinstance(business2.teams, list)
assert p1.uuid in [p.uuid for p in business2.products]
assert len(business2.teams) == 1
assert team.uuid in [t.uuid for t in business2.teams]
+ assert isinstance(business2.balance, BusinessBalances)
assert business2.balance.payout == 48
assert business2.balance.balance == 48
assert business2.balance.net == 48
@@ -1354,27 +1336,26 @@ class TestBusinessMethods:
assert len(business2.bp_accounts) == 1
assert len(business2.bp_accounts) == len(business2.product_uuids)
+ assert isinstance(business2.pop_financial, list)
assert len(business2.pop_financial) == 1
assert business2.pop_financial[0].payout == business2.balance.payout
assert business2.pop_financial[0].net == business2.balance.net
def test_prebuild_enriched_session_parquet(
self,
- event_report_request,
enriched_session_merge,
client_no_amm: DaskClient,
wall_collection,
session_collection,
thl_web_rr: PostgresConfig,
- session_report_request,
user_factory: Callable[..., User],
start: datetime,
session_factory: Callable[..., Session],
product_factory: Callable[..., Product],
delete_df_collection: Callable[..., None],
business: Business,
- mnt_filepath,
- mnt_gr_api_dir,
+ mnt_filepath: GRLDatasets,
+ mnt_gr_api_dir: Path,
):
delete_df_collection(coll=wall_collection)
@@ -1418,22 +1399,19 @@ class TestBusinessMethods:
def test_prebuild_enriched_wall_parquet(
self,
- event_report_request,
- enriched_session_merge,
enriched_wall_merge,
client_no_amm: DaskClient,
wall_collection,
session_collection,
thl_web_rr: PostgresConfig,
- session_report_request,
user_factory: Callable[..., User],
start: datetime,
session_factory: Callable[..., Session],
product_factory: Callable[..., Product],
delete_df_collection: Callable[..., None],
business: Business,
- mnt_filepath,
- mnt_gr_api_dir,
+ mnt_filepath: GRLDatasets,
+ mnt_gr_api_dir: Path,
):
delete_df_collection(coll=wall_collection)
diff --git a/tests/models/test_currency.py b/tests/models/test_currency.py
index 1102717..9bc2216 100644
--- a/tests/models/test_currency.py
+++ b/tests/models/test_currency.py
@@ -8,11 +8,12 @@ from random import randint
import pytest
+from generalresearch.currency import USDCent, USDMill, format_usd_cent
+
class TestUSDCentModel:
def test_construct_int(self):
- from generalresearch.currency import USDCent
for _ in range(100):
int_val = randint(0, 999_999)
@@ -20,10 +21,9 @@ class TestUSDCentModel:
assert int_val == instance
def test_construct_float(self):
- from generalresearch.currency import USDCent
+ float_val: float = 10.6789
with pytest.warns(expected_warning=Warning) as record:
- float_val: float = 10.6789
instance = USDCent(float_val)
assert len(record) == 1
@@ -34,10 +34,9 @@ class TestUSDCentModel:
assert instance == 10
def test_construct_decimal(self):
- from generalresearch.currency import USDCent
+ decimal_val: Decimal = Decimal("10.0")
with pytest.warns(expected_warning=Warning) as record:
- decimal_val: Decimal = Decimal("10.0")
instance = USDCent(decimal_val)
assert len(record) == 1
@@ -50,8 +49,8 @@ class TestUSDCentModel:
assert instance == 10
# Now with rounding
+ decimal_val: Decimal = Decimal("10.6789")
with pytest.warns(Warning) as record:
- decimal_val: Decimal = Decimal("10.6789")
instance = USDCent(decimal_val)
assert len(record) == 1
@@ -64,16 +63,12 @@ class TestUSDCentModel:
assert instance == 10
def test_construct_negative(self):
- from generalresearch.currency import USDCent
-
with pytest.raises(expected_exception=ValueError) as cm:
USDCent(-1)
assert "USDCent not be less than zero" in str(cm.value)
def test_operation_add(self):
- from generalresearch.currency import USDCent
-
- for i in range(100):
+ for _ in range(100):
int_val1 = randint(0, 999_999)
int_val2 = randint(0, 999_999)
@@ -83,9 +78,7 @@ class TestUSDCentModel:
assert int_val1 + int_val2 == instance1 + instance2
def test_operation_subtract(self):
- from generalresearch.currency import USDCent
-
- for i in range(100):
+ for _ in range(100):
int_val1 = randint(500_000, 999_999)
int_val2 = randint(0, 499_999)
@@ -95,9 +88,7 @@ class TestUSDCentModel:
assert int_val1 - int_val2 == instance1 - instance2
def test_operation_subtract_to_neg(self):
- from generalresearch.currency import USDCent
-
- for i in range(100):
+ for _ in range(100):
int_val = randint(0, 999_999)
instance = USDCent(int_val)
@@ -107,9 +98,7 @@ class TestUSDCentModel:
assert "USDCent not be less than zero" in str(cm.value)
def test_operation_multiply(self):
- from generalresearch.currency import USDCent
-
- for i in range(100):
+ for _ in range(100):
int_val1 = randint(0, 999_999)
int_val2 = randint(0, 999_999)
@@ -119,15 +108,11 @@ class TestUSDCentModel:
assert int_val1 * int_val2 == instance1 * instance2
def test_operation_div(self):
- from generalresearch.currency import USDCent
-
with pytest.raises(ValueError) as cm:
- USDCent(10) / 2
+ _ = USDCent(10) / 2
assert "Division not allowed for USDCent" in str(cm.value)
def test_operation_result_type(self):
- from generalresearch.currency import USDCent
-
int_val = randint(1, 999_999)
instance = USDCent(int_val)
@@ -141,8 +126,6 @@ class TestUSDCentModel:
assert isinstance(res_multipy, USDCent)
def test_operation_partner_add(self):
- from generalresearch.currency import USDCent
-
int_val = randint(1, 999_999)
instance = USDCent(int_val)
@@ -159,18 +142,14 @@ class TestUSDCentModel:
_ = instance + True
def test_abs(self):
- from generalresearch.currency import USDCent
-
- for i in range(100):
+ for _ in range(100):
int_val = abs(randint(0, 999_999))
instance = abs(USDCent(int_val))
assert int_val == instance
def test_str(self):
- from generalresearch.currency import USDCent
-
- for i in range(100):
+ for _ in range(100):
int_val = randint(0, 999_999)
instance = USDCent(int_val)
@@ -180,8 +159,6 @@ class TestUSDCentModel:
"""There is no correct answer here, but we at least want to make sure
that a USDCent is returned
"""
- from generalresearch.currency import USDCent
-
res = USDCent(10) // 1.2
assert not isinstance(res, USDCent)
assert isinstance(res, float)
@@ -206,18 +183,14 @@ class TestUSDCentModel:
class TestUSDMillModel:
def test_construct_int(self):
- from generalresearch.currency import USDMill
-
- for i in range(100):
+ for _ in range(100):
int_val = randint(0, 999_999)
instance = USDMill(int_val)
assert int_val == instance
def test_construct_float(self):
- from generalresearch.currency import USDMill
-
+ float_val: float = 10.6789
with pytest.warns(expected_warning=Warning) as record:
- float_val: float = 10.6789
instance = USDMill(float_val)
assert len(record) == 1
@@ -228,10 +201,8 @@ class TestUSDMillModel:
assert instance == 10
def test_construct_decimal(self):
- from generalresearch.currency import USDMill
-
+ decimal_val: Decimal = Decimal("10.0")
with pytest.warns(expected_warning=Warning) as record:
- decimal_val: Decimal = Decimal("10.0")
instance = USDMill(decimal_val)
assert len(record) == 1
@@ -244,12 +215,11 @@ class TestUSDMillModel:
assert instance == 10
# Now with rounding
+ decimal_val: Decimal = Decimal("10.6789")
with pytest.warns(expected_warning=Warning) as record:
- decimal_val: Decimal = Decimal("10.6789")
instance = USDMill(decimal_val)
- assert isinstance(instance, USDMill)
-
+ assert isinstance(instance, USDMill)
assert len(record) == 1
assert (
"USDMill init with a Decimal. Rounding behavior may be unexpected"
@@ -260,16 +230,12 @@ class TestUSDMillModel:
assert instance == 10
def test_construct_negative(self):
- from generalresearch.currency import USDMill
-
with pytest.raises(expected_exception=ValueError) as cm:
USDMill(-1)
assert "USDMill not be less than zero" in str(cm.value)
def test_operation_add(self):
- from generalresearch.currency import USDMill
-
- for i in range(100):
+ for _ in range(100):
int_val1 = randint(0, 999_999)
int_val2 = randint(0, 999_999)
@@ -279,9 +245,7 @@ class TestUSDMillModel:
assert int_val1 + int_val2 == instance1 + instance2
def test_operation_subtract(self):
- from generalresearch.currency import USDMill
-
- for i in range(100):
+ for _ in range(100):
int_val1 = randint(500_000, 999_999)
int_val2 = randint(0, 499_999)
@@ -291,21 +255,17 @@ class TestUSDMillModel:
assert int_val1 - int_val2 == instance1 - instance2
def test_operation_subtract_to_neg(self):
- from generalresearch.currency import USDMill
-
- for i in range(100):
+ for _ in range(100):
int_val = randint(0, 999_999)
instance = USDMill(int_val)
with pytest.raises(expected_exception=ValueError) as cm:
- instance - USDMill(1_000_000)
+ _ = instance - USDMill(1_000_000)
assert "USDMill not be less than zero" in str(cm.value)
def test_operation_multiply(self):
- from generalresearch.currency import USDMill
-
- for i in range(100):
+ for _ in range(100):
int_val1 = randint(0, 999_999)
int_val2 = randint(0, 999_999)
@@ -315,15 +275,11 @@ class TestUSDMillModel:
assert int_val1 * int_val2 == instance1 * instance2
def test_operation_div(self):
- from generalresearch.currency import USDMill
-
with pytest.raises(ValueError) as cm:
- USDMill(10) / 2
+ _ = USDMill(10) / 2
assert "Division not allowed for USDMill" in str(cm.value)
def test_operation_result_type(self):
- from generalresearch.currency import USDMill
-
int_val = randint(1, 999_999)
instance = USDMill(int_val)
@@ -337,36 +293,30 @@ class TestUSDMillModel:
assert isinstance(res_multipy, USDMill)
def test_operation_partner_add(self):
- from generalresearch.currency import USDMill
-
int_val = randint(1, 999_999)
instance = USDMill(int_val)
with pytest.raises(expected_exception=AssertionError):
- instance + 0.10
+ _ = instance + 0.10
with pytest.raises(expected_exception=AssertionError):
- instance + Decimal(".10")
+ _ = instance + Decimal(".10")
with pytest.raises(expected_exception=AssertionError):
- instance + "9.9"
+ _ = instance + "9.9"
with pytest.raises(expected_exception=AssertionError):
- instance + True
+ _ = instance + True
def test_abs(self):
- from generalresearch.currency import USDMill
-
- for i in range(100):
+ for _ in range(100):
int_val = abs(randint(0, 999_999))
instance = abs(USDMill(int_val))
assert int_val == instance
def test_str(self):
- from generalresearch.currency import USDMill
-
- for i in range(100):
+ for _ in range(100):
int_val = randint(0, 999_999)
instance = USDMill(int_val)
@@ -376,8 +326,6 @@ class TestUSDMillModel:
"""There is no correct answer here, but we at least want to make sure
that a USDMill is returned
"""
- from generalresearch.currency import USDCent, USDMill
-
res = USDMill(10) // 1.2
assert not isinstance(res, USDMill)
assert isinstance(res, float)
@@ -402,11 +350,7 @@ class TestUSDMillModel:
class TestNegativeFormatting:
def test_pos(self):
- from generalresearch.currency import format_usd_cent
-
assert "-$987.65" == format_usd_cent(-98765)
def test_neg(self):
- from generalresearch.currency import format_usd_cent
-
assert "-$123.45" == format_usd_cent(-12345)