Skip to content

Commit

Permalink
test: moved stray tests into tests folder, minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Nov 8, 2023
1 parent 419a43d commit cf4e795
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 56 deletions.
9 changes: 3 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions src/quantifiedme/load/activitywatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
30 changes: 9 additions & 21 deletions src/quantifiedme/load/smartertime.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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>"
filename = sys.argv.pop()
convert_csv_to_awbucket(filename)
15 changes: 0 additions & 15 deletions src/quantifiedme/load/whoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
23 changes: 23 additions & 0 deletions tests/test_load_activitywatch.py
Original file line number Diff line number Diff line change
@@ -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()
29 changes: 29 additions & 0 deletions tests/test_load_smartertime.py
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 11 additions & 0 deletions tests/test_load_whoop.py
Original file line number Diff line number Diff line change
@@ -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())

0 comments on commit cf4e795

Please sign in to comment.