diff --git a/pyproject.toml b/pyproject.toml index 862e1a6..adf3f04 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,13 +55,10 @@ pandas-stubs = "^2.1.1.230928" [tool.pytest.ini_options] minversion = "6.0" -addopts = "--cov=quantifiedme --cov-report=xml --cov-report=html --cov-report=term" # --profile --cov-report=term -testpaths = [ - "src/quantifiedme", - "tests", -] -python_files = ["*.py",] filterwarnings = ["ignore::DeprecationWarning",] +markers = [ + "slow: marks tests as slow (deselect with '-m \"not slow\"')", +] [tool.pyright] strictParameterNoneValue = false diff --git a/src/quantifiedme/load/activitywatch.py b/src/quantifiedme/load/activitywatch.py index 0ae19e3..e9856d8 100644 --- a/src/quantifiedme/load/activitywatch.py +++ b/src/quantifiedme/load/activitywatch.py @@ -51,17 +51,3 @@ def load_events( events = [e for e in events if e.data] return events - - -def test_load_events(): - awc = ActivityWatchClient("testloadevents", port=5667, testing=True) - hostname = "erb-main2-arch" - since = datetime(2020, 1, 1, tzinfo=timezone.utc) - end = datetime(2020, 1, 2, tzinfo=timezone.utc) - events = load_events(awc, hostname, since, end) - assert events - print(len(events)) - - -if __name__ == "__main__": - test_load_events() diff --git a/src/quantifiedme/load/smartertime.py b/src/quantifiedme/load/smartertime.py index 11fa0e8..ccb3cb7 100644 --- a/src/quantifiedme/load/smartertime.py +++ b/src/quantifiedme/load/smartertime.py @@ -1,13 +1,14 @@ # Code originally from now deprecated repo: https://github.com/ActivityWatch/aw-importer-smartertime import csv -from datetime import datetime, timedelta, timezone -import secrets import json +import secrets +import sys +from datetime import datetime, timedelta, timezone from pathlib import Path -from aw_core.models import Event import aw_client +from aw_core.models import Event from aw_transform.union_no_overlap import union_no_overlap from ..config import load_config @@ -130,22 +131,9 @@ def convert_csv_to_awbucket(filepath): # import_to_awserver(bucket) -def test_load_smartertime_events(): - events = _load_smartertime_events( - datetime(2020, 1, 1), - filepath=Path( - "~/Programming/quantifiedme/data/smartertime/smartertime_export_erb-f3_2022-02-01_efa36e6a.awbucket.json" - ).expanduser(), - ) - assert len(events) > 0 - - if __name__ == "__main__": - import sys - - if len(sys.argv) > 1 and sys.argv[1] == "convert": - assert len(sys.argv) > 2 - filename = sys.argv.pop() - convert_csv_to_awbucket(filename) - else: - test_load_smartertime_events() + assert len(sys.argv) > 2 and sys.argv[1] in [ + "convert" + ], "Usage: smartertime.py convert " + filename = sys.argv.pop() + convert_csv_to_awbucket(filename) diff --git a/src/quantifiedme/load/whoop.py b/src/quantifiedme/load/whoop.py index 8f850bd..18af854 100644 --- a/src/quantifiedme/load/whoop.py +++ b/src/quantifiedme/load/whoop.py @@ -68,18 +68,3 @@ def parse_during(x): df.index.name = "timestamp" return df - - -def test_load_whoop_heartrate(): - df = load_heartrate_df() - print(df.head()) - - -def test_load_whoop_sleep(): - df = load_sleep_df() - print(df.head()) - - -if __name__ == "__main__": - test_load_whoop_sleep() - test_load_whoop_heartrate() diff --git a/tests/test_load_activitywatch.py b/tests/test_load_activitywatch.py new file mode 100644 index 0000000..7f8232c --- /dev/null +++ b/tests/test_load_activitywatch.py @@ -0,0 +1,23 @@ +import os +from datetime import datetime, timezone + +from aw_client import ActivityWatchClient +from quantifiedme.load.activitywatch import load_events + +hostname = os.uname().nodename + + +def test_load_events(): + awc = ActivityWatchClient("testloadevents", port=5600, testing=False) + hostname = os.uname().nodename + now = datetime.now(tz=timezone.utc) + today = datetime.combine(now, datetime.min.time(), tzinfo=timezone.utc) + since = today + end = now + events = load_events(awc, hostname, since, end) + assert events + print(len(events)) + + +if __name__ == "__main__": + test_load_events() diff --git a/tests/test_load_smartertime.py b/tests/test_load_smartertime.py new file mode 100644 index 0000000..008db65 --- /dev/null +++ b/tests/test_load_smartertime.py @@ -0,0 +1,29 @@ +import sys +from datetime import datetime +from pathlib import Path + +import pytest +from quantifiedme.load.smartertime import ( + _load_smartertime_events, + convert_csv_to_awbucket, +) + +test_file = Path( + "~/Programming/quantifiedme/data/smartertime/smartertime_export_erb-f3_2022-02-01_efa36e6a.awbucket.json" +).expanduser() + + +@pytest.mark.skipif(not test_file.exists(), reason="test file not found") +def test_load_smartertime_events(): + events = _load_smartertime_events( + datetime(2020, 1, 1), + filepath=test_file, + ) + assert len(events) > 0 + + +if __name__ == "__main__": + if len(sys.argv) > 1 and sys.argv[1] == "convert": + assert len(sys.argv) > 2 + filename = sys.argv.pop() + convert_csv_to_awbucket(filename) diff --git a/tests/test_load_whoop.py b/tests/test_load_whoop.py new file mode 100644 index 0000000..fc2b901 --- /dev/null +++ b/tests/test_load_whoop.py @@ -0,0 +1,11 @@ +from quantifiedme.load.whoop import load_heartrate_df, load_sleep_df + + +def test_load_whoop_heartrate(): + df = load_heartrate_df() + print(df.head()) + + +def test_load_whoop_sleep(): + df = load_sleep_df() + print(df.head())