Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ asyncio_default_fixture_loop_scope = "session"
[tool.coverage.run]
omit = [
"tests/*"
]
]

[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"

[tool.setuptools.packages.find]
where = ["src"]
4 changes: 3 additions & 1 deletion src/hrm/ts_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def clear(self):
"""
self.data.clear()

def time_bucket(self, start: float, end: float, bucket_size: float) -> List[tuple[float, float]]:
def time_bucket(
self, start: float, end: float, bucket_size: float
) -> List[tuple[float, float]]:
"""
Bucket the data from the given start timestamp to the given end timestamp into the given time bucket size.
"""
Expand Down
15 changes: 10 additions & 5 deletions tests/mcp/test_bt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

from hrm.bt_client import HEART_RATE_SERVICE_UUID, BtClient, upload_file

import os


@pytest.fixture
def bt_client():
Expand Down Expand Up @@ -192,6 +190,7 @@ def test_build_heart_rate_chart_upload_fail(mock_plt, mock_upload_file, bt_clien
def fake_savefig(buf, format=None):
if hasattr(buf, "write"):
buf.write("<svg>mocked</svg>")

mock_plt.savefig.side_effect = fake_savefig
# Call the method
result = bt_client.build_heart_rate_chart(since_from=2.0)
Expand All @@ -211,7 +210,9 @@ def test_build_heart_rate_chart_bucket_size(mock_plt, mock_upload_file, bt_clien
since = 100.0
url = bt_client.build_heart_rate_chart(since_from=since)
assert url == "http://fake.url/chart.png"
mock_bucket.assert_called_once_with(since_from=since, bucket_size=math.ceil(since / 60))
mock_bucket.assert_called_once_with(
since_from=since, bucket_size=math.ceil(since / 60)
)


def test_upload_file_success(monkeypatch):
Expand All @@ -222,8 +223,12 @@ def test_upload_file_success(monkeypatch):
monkeypatch.setenv("QINIU_BUCKET_DOMAIN", "http://fake.domain")

# Patch QiniuAuth and QiniuPutFile
with patch("hrm.bt_client.QiniuAuth") as MockAuth, \
patch("hrm.bt_client.QiniuPutFile", return_value=({"key": "somekey"}, MagicMock())) as mock_put_file:
with (
patch("hrm.bt_client.QiniuAuth") as MockAuth,
patch(
"hrm.bt_client.QiniuPutFile", return_value=({"key": "somekey"}, MagicMock())
) as mock_put_file,
):
mock_auth_instance = MockAuth.return_value
mock_auth_instance.upload_token.return_value = "fake_token"
file_path = "/tmp/test.png"
Expand Down
8 changes: 6 additions & 2 deletions tests/mcp/test_ts_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,13 @@ def test_query_invalid_range():
db = TsDB()
db.insert(1.0, 10.0)
db.insert(2.0, 20.0)
with pytest.raises(ValueError, match="Start timestamp must be less than end timestamp"):
with pytest.raises(
ValueError, match="Start timestamp must be less than end timestamp"
):
db.query(2.0, 2.0)
with pytest.raises(ValueError, match="Start timestamp must be less than end timestamp"):
with pytest.raises(
ValueError, match="Start timestamp must be less than end timestamp"
):
db.query(3.0, 2.0)


Expand Down