File: test_helpers.py

package info (click to toggle)
python-aiowithings 3.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 8,976 kB
  • sloc: python: 2,471; makefile: 5
file content (65 lines) | stat: -rw-r--r-- 2,076 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""Asynchronous Python client for Withings."""

from __future__ import annotations

import json
from typing import TYPE_CHECKING, Any

from aiowithings import MeasurementGroup, SleepSummary, aggregate_measurements
from aiowithings.helpers import aggregate_sleep_summary

from . import load_fixture

if TYPE_CHECKING:
    from syrupy import SnapshotAssertion


def test_aggregate_measurements(snapshot: SnapshotAssertion) -> None:
    """Test aggregation."""
    json_file: list[dict[str, Any]] = json.loads(load_fixture("measurement_list.json"))

    measurements = [MeasurementGroup.from_api(measurement) for measurement in json_file]

    assert aggregate_measurements(measurements) == snapshot


def test_aggregate_positional_measurements(snapshot: SnapshotAssertion) -> None:
    """Test aggregation of positional measurements."""
    json_file: list[dict[str, Any]] = json.loads(
        load_fixture("measurement_positions.json")
    )

    measurements = [MeasurementGroup.from_api(measurement) for measurement in json_file]

    aggregation = aggregate_measurements(measurements)
    assert len(aggregation.items()) == 26
    assert aggregate_measurements(measurements) == snapshot


def test_aggregate_sleep_summary(snapshot: SnapshotAssertion) -> None:
    """Test aggregation."""
    json_file: list[dict[str, Any]] = json.loads(load_fixture("sleep_summary.json"))[
        "body"
    ]["series"]

    sleep_summaries = [
        SleepSummary.from_api(sleep_summary) for sleep_summary in json_file
    ]

    assert aggregate_sleep_summary(sleep_summaries) == snapshot


def test_aggregate_single_sleep_summary(snapshot: SnapshotAssertion) -> None:
    """Test aggregation."""
    json_file: dict[str, Any] = json.loads(load_fixture("sleep_summary.json"))["body"][
        "series"
    ][0]

    sleep_summary = SleepSummary.from_api(json_file)

    assert aggregate_sleep_summary([sleep_summary]) == snapshot


def test_aggregate_no_sleep_summary(snapshot: SnapshotAssertion) -> None:
    """Test aggregation."""
    assert aggregate_sleep_summary([]) == snapshot