aboutsummaryrefslogtreecommitdiff
path: root/tests/incite
diff options
context:
space:
mode:
authorMax Nanis2026-08-28 00:22:17 -0700
committerMax Nanis2026-08-28 00:22:17 -0700
commitba544e2ba31432aad4d2acaba3e1f90c27137ded (patch)
treeec04289750280c2cba02216ccc6cd6a5d7695225 /tests/incite
parentaeeb7fef2594ccd34fbe96a77f6c5b392299fed7 (diff)
downloadgeneralresearch-ba544e2ba31432aad4d2acaba3e1f90c27137ded.tar.gz
generalresearch-ba544e2ba31432aad4d2acaba3e1f90c27137ded.zip
Ruff evening!
Diffstat (limited to 'tests/incite')
-rw-r--r--tests/incite/collections/test_df_collection_base.py17
-rw-r--r--tests/incite/collections/test_df_collection_item_base.py19
-rw-r--r--tests/incite/collections/test_df_collection_thl_marketplaces.py14
-rw-r--r--tests/incite/collections/test_df_collection_thl_web.py120
-rw-r--r--tests/incite/mergers/foundations/test_user_id_product.py21
-rw-r--r--tests/incite/mergers/test_pop_ledger.py6
-rw-r--r--tests/incite/test_collection_base.py2
7 files changed, 145 insertions, 54 deletions
diff --git a/tests/incite/collections/test_df_collection_base.py b/tests/incite/collections/test_df_collection_base.py
index b9f0181..c236700 100644
--- a/tests/incite/collections/test_df_collection_base.py
+++ b/tests/incite/collections/test_df_collection_base.py
@@ -9,6 +9,7 @@ from generalresearch.incite.collections import (
DFCollection,
DFCollectionType,
)
+from generalresearch.pg_helper import PostgresConfig
if TYPE_CHECKING:
from generalresearch.incite.base import GRLDatasets
@@ -45,7 +46,9 @@ class TestDFCollectionBase:
class TestDFCollectionBaseProperties:
@pytest.mark.skip
- def test_df_collection_items(self, mnt_filepath: GRLDatasets, df_coll_type):
+ def test_df_collection_items(
+ self, mnt_filepath: GRLDatasets, df_coll_type: DFCollectionType
+ ):
instance = DFCollection(
data_type=df_coll_type,
start=datetime(year=1800, month=1, day=1, tzinfo=UTC),
@@ -57,7 +60,9 @@ class TestDFCollectionBaseProperties:
assert len(instance.interval_range) == len(instance.items)
assert len(instance.items) == 366
- def test_df_collection_progress(self, mnt_filepath: GRLDatasets, df_coll_type):
+ def test_df_collection_progress(
+ self, mnt_filepath: GRLDatasets, df_coll_type: DFCollectionType
+ ):
instance = DFCollection(
data_type=df_coll_type,
start=datetime(year=1800, month=1, day=1, tzinfo=UTC),
@@ -70,7 +75,9 @@ class TestDFCollectionBaseProperties:
assert isinstance(instance.progress, pd.DataFrame)
assert instance.progress.shape == (366, 6)
- def test_df_collection_schema(self, mnt_filepath: GRLDatasets, df_coll_type):
+ def test_df_collection_schema(
+ self, mnt_filepath: GRLDatasets, df_coll_type: DFCollectionType
+ ):
instance1 = DFCollection(
data_type=DFCollectionType.WALL, archive_path=mnt_filepath.data_src
)
@@ -87,9 +94,9 @@ class TestDFCollectionBaseProperties:
class TestDFCollectionBaseMethods:
@pytest.mark.skip
- def test_initial_load(self, mnt_filepath: GRLDatasets, thl_web_rr):
+ def test_initial_load(self, mnt_filepath: GRLDatasets, thl_web_rr: PostgresConfig):
instance = DFCollection(
- pg_config=thl_web_rr: PostgresConfig,
+ pg_config=thl_web_rr,
data_type=DFCollectionType.USER,
start=datetime(year=2022, month=1, day=1, minute=0, tzinfo=UTC),
finished=datetime(year=2022, month=1, day=1, minute=5, tzinfo=UTC),
diff --git a/tests/incite/collections/test_df_collection_item_base.py b/tests/incite/collections/test_df_collection_item_base.py
index 9a2ecf3..e0171c2 100644
--- a/tests/incite/collections/test_df_collection_item_base.py
+++ b/tests/incite/collections/test_df_collection_item_base.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
from datetime import UTC, datetime
from typing import TYPE_CHECKING
@@ -19,7 +21,7 @@ df_collection_types = [e for e in DFCollectionType if e is not DFCollectionType.
@pytest.mark.parametrize("df_coll_type", df_collection_types)
class TestDFCollectionItemBase:
- def test_init(self, mnt_filepath: GRLDatasets, df_coll_type):
+ def test_init(self, mnt_filepath: GRLDatasets, df_coll_type: DFCollectionType):
collection = DFCollection(
data_type=df_coll_type,
offset="100d",
@@ -38,14 +40,16 @@ class TestDFCollectionItemBase:
class TestDFCollectionItemProperties:
@pytest.mark.skip
- def test_filename(self, df_coll_type):
+ def test_filename(self, df_coll_type: DFCollectionType):
pass
@pytest.mark.parametrize("df_coll_type", df_collection_types)
class TestDFCollectionItemMethods:
- def test_has_mysql_false(self, mnt_filepath: GRLDatasets, df_coll_type):
+ def test_has_mysql_false(
+ self, mnt_filepath: GRLDatasets, df_coll_type: DFCollectionType
+ ):
collection = DFCollection(
data_type=df_coll_type,
offset="100d",
@@ -58,7 +62,10 @@ class TestDFCollectionItemMethods:
assert not instance1.has_mysql()
def test_has_mysql_true(
- self, thl_web_rr: PostgresConfig, mnt_filepath: GRLDatasets, df_coll_type
+ self,
+ thl_web_rr: PostgresConfig,
+ mnt_filepath: GRLDatasets,
+ df_coll_type: DFCollectionType,
):
collection = DFCollection(
data_type=df_coll_type,
@@ -66,7 +73,7 @@ class TestDFCollectionItemMethods:
start=datetime(year=1800, month=1, day=1, tzinfo=UTC),
finished=datetime(year=1900, month=1, day=1, tzinfo=UTC),
archive_path=mnt_filepath.archive_path(enum_type=df_coll_type),
- pg_config=thl_web_rr: PostgresConfig,
+ pg_config=thl_web_rr,
)
# Has RR, assume unittest server is online
@@ -74,5 +81,5 @@ class TestDFCollectionItemMethods:
assert instance2.has_mysql()
@pytest.mark.skip
- def test_update_partial_archive(self, df_coll_type):
+ def test_update_partial_archive(self, df_coll_type: DFCollectionType):
pass
diff --git a/tests/incite/collections/test_df_collection_thl_marketplaces.py b/tests/incite/collections/test_df_collection_thl_marketplaces.py
index d2d3ce4..b4b5b00 100644
--- a/tests/incite/collections/test_df_collection_thl_marketplaces.py
+++ b/tests/incite/collections/test_df_collection_thl_marketplaces.py
@@ -4,6 +4,7 @@ from itertools import product
import pytest
from pandera.pandas import Column, DataFrameSchema, Index
+from generalresearch.incite.base import GRLDatasets
from generalresearch.incite.collections import DFCollection, DFCollectionType
from generalresearch.incite.collections.thl_marketplaces import (
InnovateSurveyHistoryCollection,
@@ -11,6 +12,7 @@ from generalresearch.incite.collections.thl_marketplaces import (
SagoSurveyHistoryCollection,
SpectrumSurveyTimeseriesCollection,
)
+from generalresearch.pg_helper import PostgresConfig
def combo_object():
@@ -29,7 +31,13 @@ def combo_object():
@pytest.mark.parametrize("df_coll, offset", combo_object())
class TestDFCollection_thl_marketplaces:
- def test_init(self, mnt_filepath, df_coll, offset, spectrum_rw):
+ def test_init(
+ self,
+ mnt_filepath: GRLDatasets,
+ df_coll: DFCollection,
+ offset: str,
+ spectrum_rw: PostgresConfig,
+ ):
assert issubclass(df_coll, DFCollection)
# This is stupid, but we need to pull the default from the
@@ -38,7 +46,7 @@ class TestDFCollection_thl_marketplaces:
assert isinstance(data_type, DFCollectionType)
# (1) Can't be totally empty, needs a path...
- with pytest.raises(expected_exception=Exception) as cm:
+ with pytest.raises(expected_exception=Exception):
instance = df_coll()
# (2) Confirm it only needs the archive_path
@@ -61,7 +69,7 @@ class TestDFCollection_thl_marketplaces:
assert isinstance(instance._schema, DataFrameSchema)
assert isinstance(instance._schema.index, Index)
- for c in instance._schema.columns.keys():
+ for c in instance._schema.columns:
assert isinstance(c, str)
col = instance._schema.columns[c]
assert isinstance(col, Column)
diff --git a/tests/incite/collections/test_df_collection_thl_web.py b/tests/incite/collections/test_df_collection_thl_web.py
index bcdeb83..6d509bc 100644
--- a/tests/incite/collections/test_df_collection_thl_web.py
+++ b/tests/incite/collections/test_df_collection_thl_web.py
@@ -3,19 +3,16 @@ from __future__ import annotations
from collections.abc import Generator
from datetime import datetime
from itertools import product
-from typing import TYPE_CHECKING
import dask.dataframe as dd
import pandas as pd
import pytest
from pandera.pandas import DataFrameSchema
-from generalresearch.incite.collections import DFCollection, DFCollectionType
-
-if TYPE_CHECKING:
- from generalresearch.incite.collections import (
- DFCollectionType,
- )
+from generalresearch.incite.collections import (
+ DFCollection,
+ DFCollectionType,
+)
def combo_object() -> Generator[tuple]:
@@ -39,7 +36,10 @@ def combo_object() -> Generator[tuple]:
class TestDFCollection_thl_web:
def test_init(
- self, df_collection_data_type: DFCollectionType, offset: str, df_collection
+ self,
+ df_collection_data_type: DFCollectionType,
+ offset: str,
+ df_collection: DFCollection,
):
assert isinstance(df_collection_data_type, DFCollectionType)
assert isinstance(df_collection, DFCollection)
@@ -50,12 +50,12 @@ class TestDFCollection_thl_web:
)
class TestDFCollection_thl_web_Properties:
- def test_items(self, df_collection):
+ def test_items(self, df_collection: DFCollection):
assert isinstance(df_collection.items, list)
for i in df_collection.items:
assert i._collection == df_collection
- def test__schema(self, df_collection):
+ def test__schema(self, df_collection: DFCollection):
assert isinstance(df_collection._schema, DataFrameSchema)
@@ -65,16 +65,16 @@ class TestDFCollection_thl_web_Properties:
class TestDFCollection_thl_web_BaseProperties:
@pytest.mark.skip
- def test__interval_range(self, df_collection):
+ def test__interval_range(self, df_collection: DFCollection):
pass
- def test_interval_start(self, df_collection):
+ def test_interval_start(self, df_collection: DFCollection):
assert isinstance(df_collection.interval_start, datetime)
- def test_interval_range(self, df_collection):
+ def test_interval_range(self, df_collection: DFCollection):
assert isinstance(df_collection.interval_range, list)
- def test_progress(self, df_collection):
+ def test_progress(self, df_collection: DFCollection):
assert isinstance(df_collection.progress, pd.DataFrame)
@@ -84,17 +84,21 @@ class TestDFCollection_thl_web_BaseProperties:
class TestDFCollection_thl_web_Methods:
@pytest.mark.skip
- def test_initial_loads(self, df_collection_data_type, df_collection, offset):
+ def test_initial_loads(
+ self, df_collection_data_type, df_collection: DFCollection, offset: str
+ ):
pass
@pytest.mark.skip
def test_fetch_force_rr_latest(
- self, df_collection_data_type, df_collection, offset: str
+ self, df_collection_data_type, df_collection: DFCollection, offset: str
):
pass
@pytest.mark.skip
- def test_force_rr_latest(self, df_collection_data_type, df_collection, offset):
+ def test_force_rr_latest(
+ self, df_collection_data_type, df_collection: DFCollection, offset: str
+ ):
pass
@@ -103,63 +107,108 @@ class TestDFCollection_thl_web_Methods:
)
class TestDFCollection_thl_web_BaseMethods:
- def test_fetch_all_paths(self, df_collection_data_type, offset: str, df_collection):
+ def test_fetch_all_paths(
+ self,
+ df_collection_data_type: DFCollectionType,
+ offset: str,
+ df_collection: DFCollection,
+ ):
res = df_collection.fetch_all_paths(
items=None, force_rr_latest=False, include_partial=False
)
assert isinstance(res, list)
@pytest.mark.skip
- def test_ddf(self, df_collection_data_type, offset: str, df_collection):
+ def test_ddf(
+ self,
+ df_collection_data_type: DFCollectionType,
+ offset: str,
+ df_collection: DFCollection,
+ ):
res = df_collection.ddf()
assert isinstance(res, dd.DataFrame)
# -- cleanup --
@pytest.mark.skip
def test_schedule_cleanup(
- self, df_collection_data_type, offset: str, df_collection
+ self,
+ df_collection_data_type: DFCollectionType,
+ offset: str,
+ df_collection: DFCollection,
):
pass
@pytest.mark.skip
- def test_cleanup(self, df_collection_data_type, offset: str, df_collection):
+ def test_cleanup(
+ self,
+ df_collection_data_type: DFCollectionType,
+ offset: str,
+ df_collection: DFCollection,
+ ):
pass
@pytest.mark.skip
def test_cleanup_partials(
- self, df_collection_data_type, offset: str, df_collection
+ self,
+ df_collection_data_type: DFCollectionType,
+ offset: str,
+ df_collection: DFCollection,
):
pass
@pytest.mark.skip
def test_clear_tmp_archives(
- self, df_collection_data_type, offset: str, df_collection
+ self,
+ df_collection_data_type: DFCollectionType,
+ offset: str,
+ df_collection: DFCollection,
):
pass
@pytest.mark.skip
def test_clear_corrupt_archives(
- self, df_collection_data_type, offset: str, df_collection
+ self,
+ df_collection_data_type: DFCollectionType,
+ offset: str,
+ df_collection: DFCollection,
):
pass
@pytest.mark.skip
def test_rebuild_symlinks(
- self, df_collection_data_type, offset: str, df_collection
+ self,
+ df_collection_data_type: DFCollectionType,
+ offset: str,
+ df_collection: DFCollection,
):
pass
# -- Source timing --
@pytest.mark.skip
- def test_get_item(self, df_collection_data_type, offset: str, df_collection):
+ def test_get_item(
+ self,
+ df_collection_data_type: DFCollectionType,
+ offset: str,
+ df_collection: DFCollection,
+ ):
pass
@pytest.mark.skip
- def test_get_item_start(self, df_collection_data_type, offset: str, df_collection):
+ def test_get_item_start(
+ self,
+ df_collection_data_type: DFCollectionType,
+ offset: str,
+ df_collection: DFCollection,
+ ):
pass
@pytest.mark.skip
- def test_get_items(self, df_collection_data_type, offset: str, df_collection):
+ def test_get_items(
+ self,
+ df_collection_data_type: DFCollectionType,
+ offset: str,
+ df_collection: DFCollection,
+ ):
# If we get all the items from the start of the collection, it
# should include all the items!
res1 = df_collection.items
@@ -168,18 +217,27 @@ class TestDFCollection_thl_web_BaseMethods:
@pytest.mark.skip
def test_get_items_from_year(
- self, df_collection_data_type, offset: str, df_collection
+ self,
+ df_collection_data_type: DFCollectionType,
+ offset: str,
+ df_collection: DFCollection,
):
pass
@pytest.mark.skip
def test_get_items_last90(
- self, df_collection_data_type, offset: str, df_collection
+ self,
+ df_collection_data_type: DFCollectionType,
+ offset: str,
+ df_collection: DFCollection,
):
pass
@pytest.mark.skip
def test_get_items_last365(
- self, df_collection_data_type, offset: str, df_collection
+ self,
+ df_collection_data_type: DFCollectionType,
+ offset: str,
+ df_collection: DFCollection,
):
pass
diff --git a/tests/incite/mergers/foundations/test_user_id_product.py b/tests/incite/mergers/foundations/test_user_id_product.py
index 10802e5..7367056 100644
--- a/tests/incite/mergers/foundations/test_user_id_product.py
+++ b/tests/incite/mergers/foundations/test_user_id_product.py
@@ -1,11 +1,15 @@
+from __future__ import annotations
+
from datetime import UTC, datetime, timedelta
from itertools import product
import pandas as pd
import pytest
+from dask.distributed import Client as DaskClient
# noinspection PyUnresolvedReferences
from generalresearch.incite.mergers.foundations.user_id_product import (
+ UserIdProductMerge,
UserIdProductMergeItem,
)
@@ -23,14 +27,21 @@ from generalresearch.incite.mergers.foundations.user_id_product import (
class TestUserIDProduct:
@pytest.mark.skip
- def test_base(self, client_no_amm, user_id_product_merge):
+ def test_base(
+ self, client_no_amm: DaskClient, user_id_product_merge: UserIdProductMerge
+ ):
ddf = user_id_product_merge.ddf()
df = client_no_amm.compute(collections=ddf, sync=True)
assert isinstance(df, pd.DataFrame)
assert not df.empty
@pytest.mark.skip
- def test_base_item(self, client_no_amm, user_id_product_merge, user_collection):
+ def test_base_item(
+ self,
+ client_no_amm: DaskClient,
+ user_id_product_merge: UserIdProductMerge,
+ user_collection,
+ ):
assert len(user_id_product_merge.items) == 1
for item in user_id_product_merge.items:
@@ -40,7 +51,7 @@ class TestUserIDProduct:
try:
modified_time1 = path.stat().st_mtime
- except Exception:
+ except OSError:
modified_time1 = 0
user_id_product_merge.build(client=client_no_amm, user_coll=user_collection)
@@ -49,7 +60,9 @@ class TestUserIDProduct:
assert modified_time2 > modified_time1
@pytest.mark.skip
- def test_read(self, client_no_amm, user_id_product_merge):
+ def test_read(
+ self, client_no_amm: DaskClient, user_id_product_merge: UserIdProductMerge
+ ):
users_ddf = user_id_product_merge.ddf()
df = client_no_amm.compute(collections=users_ddf, sync=True)
diff --git a/tests/incite/mergers/test_pop_ledger.py b/tests/incite/mergers/test_pop_ledger.py
index 529a641..2146344 100644
--- a/tests/incite/mergers/test_pop_ledger.py
+++ b/tests/incite/mergers/test_pop_ledger.py
@@ -86,9 +86,7 @@ class TestMergePOPLedger:
# --
- user_wallet_account: LedgerAccount = (
- thl_ledger_manager.get_account_or_create_user_wallet(user=u)
- )
+ thl_ledger_manager.get_account_or_create_user_wallet(user=u)
cash_account: LedgerAccount = thl_ledger_manager.get_account_cash()
rev_account: LedgerAccount = (
thl_ledger_manager.get_account_task_complete_revenue()
@@ -295,7 +293,7 @@ class TestMergePOPLedger:
assert isinstance(df.index, pd.Index)
assert isinstance(df.index, pd.DatetimeIndex)
- bp_account_balance = thl_ledger_manager.get_account_balance(account=bp_account)
+ thl_ledger_manager.get_account_balance(account=bp_account)
# Initial sum
initial_sum = df.sum().sum()
diff --git a/tests/incite/test_collection_base.py b/tests/incite/test_collection_base.py
index d6ce2b1..577eda9 100644
--- a/tests/incite/test_collection_base.py
+++ b/tests/incite/test_collection_base.py
@@ -241,7 +241,7 @@ class TestCollectionBaseMethodsCleanup:
assert "Must override" in str(cm.value)
-class TestCollectionBaseMethodsCleanup:
+class TestCollectionBaseMethodsCleanup2:
@pytest.mark.skip
def test_cleanup_partials(self, mnt_filepath: GRLDatasets):