Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hydration #61

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Hydration #61

wants to merge 9 commits into from

Conversation

matin
Copy link
Owner

@matin matin commented Jun 29, 2024

Add hydration stats.

Closes issue #54

Summary by CodeRabbit

  • Tests
    • Updated various test functions to use @pytest.mark.vcr() decorator for enhanced consistency in testing.

Copy link

coderabbitai bot commented Jun 29, 2024

Walkthrough

The changes across multiple test files involve updating the @pytest.mark.vcr decorator to include parentheses (@pytest.mark.vcr()). This ensures that the decorator is consistently used, possibly affecting how VCR (virtual cassette recorder) handles HTTP interactions for test recordings and replays.

Changes

File Change Summary
tests/stats/test_sleep_stats.py Updated @pytest.mark.vcr to @pytest.mark.vcr() in test_daily_sleep function.
tests/stats/test_steps.py Updated @pytest.mark.vcr to @pytest.mark.vcr() in test_daily_steps and test_weekly_steps.
tests/stats/test_stress.py Updated @pytest.mark.vcr to @pytest.mark.vcr() in multiple stress test functions.
tests/test_http.py Updated @pytest.mark.vcr to @pytest.mark.vcr() in multiple HTTP-related test functions.
tests/test_sso.py Updated @pytest.mark.vcr to @pytest.mark.vcr() in multiple SSO-related test functions.
tests/test_users.py Updated @pytest.mark.vcr to @pytest.mark.vcr() in test_user_profile and test_user_setttings.

Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI gpt-4o model for code reviews and chat: OpenAI claims that this model is better at understanding and generating code than the previous models. We seek your feedback over the next few weeks before making it generally available.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jun 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (87abab3) to head (4546623).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #61   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           34        36    +2     
  Lines         1267      1285   +18     
=========================================
+ Hits          1267      1285   +18     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range comments (2)
garth/stats/_base.py (2)

Line range hint 19-19: Add type annotation for cls.

The class method list is missing a type annotation for cls.

-    def list(
+    def list(
+        cls: Type["Stats"],

Line range hint 41-41: Remove unnecessary assignment before return statement.

The assignment to page before the return statement is unnecessary.

-            page = (
-                cls.list(
-                    end - timedelta(**{period_type: cls._page_size}),
-                    period - cls._page_size,
-                    client=client,
-                )
-                + page
-            )
-            return page
+            return cls.list(
+                end - timedelta(**{period_type: cls._page_size}),
+                period - cls._page_size,
+                client=client,
+            ) + page
Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 87abab3 and 1cae471.

Files selected for processing (3)
  • garth/stats/init.py (1 hunks)
  • garth/stats/_base.py (1 hunks)
  • garth/stats/hydration.py (1 hunks)
Additional context used
Ruff
garth/stats/_base.py

19-19: Missing type annotation for cls in classmethod

(ANN102)


41-41: Unnecessary assignment to page before return statement

Remove unnecessary assignment

(RET504)

Additional comments not posted (1)
garth/stats/hydration.py (1)

1-16: LGTM!

Ensure that the new DailyHydration class is integrated and used correctly in the codebase.

garth/stats/__init__.py Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 1cae471 and 402add5.

Files selected for processing (1)
  • garth/stats/init.py (1 hunks)

garth/stats/__init__.py Show resolved Hide resolved
@matin matin self-assigned this Jun 29, 2024
@matin matin linked an issue Jun 29, 2024 that may be closed by this pull request
garth/stats/hydration.py Outdated Show resolved Hide resolved
@matin
Copy link
Owner Author

matin commented Jun 29, 2024

@coderabbitai suggest changes to the README

Copy link

coderabbitai bot commented Jun 29, 2024

@matin: Based on the recent changes, I suggest adding the following section to the README to document the new DailyHydration class:

Hydration

Daily hydration statistics

garth.DailyHydration.list("2023-07-23", 2)
[
    DailyHydration(
        calendar_date=datetime.date(2023, 7, 22),
        value_in_ml=2000,
        goal_in_ml=2500
    ),
    DailyHydration(
        calendar_date=datetime.date(2023, 7, 23),
        value_in_ml=2100,
        goal_in_ml=2500
    )
]

This addition will help users understand how to access and use the new hydration stats feature.

Analysis chain
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Locate and display the contents of the README file to understand its current structure and content.
fd -I -H -t f -i 'readme' | xargs cat

Length of output: 22495

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 402add5 and 89eaa14.

Files selected for processing (5)
  • garth/init.py (2 hunks)
  • garth/stats/init.py (2 hunks)
  • garth/stats/_base.py (3 hunks)
  • tests/stats/cassettes/test_daily_hydration.yaml (1 hunks)
  • tests/stats/test_hydration.py (1 hunks)
Additional context used
Ruff
tests/stats/test_hydration.py

9-9: Use @pytest.mark.vcr() over @pytest.mark.vcr

Add/remove parentheses

(PT023)


10-10: Missing return type annotation for public function test_daily_hydration

Add return type annotation: None

(ANN201)


13-13: Use of assert detected

(S101)

yamllint
tests/stats/cassettes/test_daily_hydration.yaml

[error] 2-2: wrong indentation: expected at least 1

(indentation)


[error] 6-6: wrong indentation: expected 8 but found 6

(indentation)


[error] 8-8: wrong indentation: expected 8 but found 6

(indentation)


[error] 10-10: wrong indentation: expected 8 but found 6

(indentation)


[error] 12-12: wrong indentation: expected 8 but found 6

(indentation)


[error] 14-14: wrong indentation: expected 8 but found 6

(indentation)


[error] 23-23: wrong indentation: expected 8 but found 6

(indentation)


[error] 25-25: wrong indentation: expected 8 but found 6

(indentation)


[error] 27-27: wrong indentation: expected 8 but found 6

(indentation)


[error] 29-29: wrong indentation: expected 8 but found 6

(indentation)


[error] 31-31: wrong indentation: expected 8 but found 6

(indentation)


[error] 33-33: wrong indentation: expected 8 but found 6

(indentation)


[error] 35-35: wrong indentation: expected 8 but found 6

(indentation)


[error] 37-37: wrong indentation: expected 8 but found 6

(indentation)


[error] 39-39: wrong indentation: expected 8 but found 6

(indentation)


[error] 41-41: wrong indentation: expected 8 but found 6

(indentation)


[error] 53-53: wrong indentation: expected 8 but found 6

(indentation)


[error] 55-55: wrong indentation: expected 8 but found 6

(indentation)


[error] 57-57: wrong indentation: expected 8 but found 6

(indentation)


[error] 59-59: wrong indentation: expected 8 but found 6

(indentation)

Additional comments not posted (4)
garth/stats/__init__.py (1)

3-3: Ensure DailyHydration is correctly imported and used.

The addition of DailyHydration to the __all__ list is incomplete without the corresponding import statement. Please add the following import statement to garth/stats/__init__.py:

from .hydration import DailyHydration
garth/__init__.py (1)

5-5: LGTM!

The import of DailyHydration and its inclusion in the __all__ list are correct.

garth/stats/_base.py (1)

2-2: LGTM!

The removal of BASE_PATH constant and updates to the Stats class are correct.

tests/stats/cassettes/test_daily_hydration.yaml (1)

73-73: LGTM!

tests/stats/test_hydration.py Show resolved Hide resolved
tests/stats/test_hydration.py Outdated Show resolved Hide resolved
tests/stats/test_hydration.py Show resolved Hide resolved
@matin
Copy link
Owner Author

matin commented Jun 30, 2024

@coderabbitai review

Copy link

coderabbitai bot commented Jun 30, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 18

Outside diff range comments (23)
tests/stats/test_steps.py (2)

Line range hint 14-15: Avoid using assert statements in tests.

Replace assert statements with pytest's assert methods for better error messages.

- assert daily_steps[-1].calendar_date == end
- assert len(daily_steps) == days
+ assert daily_steps[-1].calendar_date == end, f"Expected {end}, got {daily_steps[-1].calendar_date}"
+ assert len(daily_steps) == days, f"Expected {days}, got {len(daily_steps)}"
Tools
Ruff

15-15: Use of assert detected

(S101)


19-19: Missing return type annotation for public function test_weekly_steps

Add return type annotation: None

(ANN201)


Line range hint 23-24: Avoid using assert statements in tests.

Replace assert statements with pytest's assert methods for better error messages.

- assert len(weekly_steps) == weeks
- assert weekly_steps[-1].calendar_date == end - timedelta(days=6)
+ assert len(weekly_steps) == weeks, f"Expected {weeks}, got {len(weekly_steps)}"
+ assert weekly_steps[-1].calendar_date == end - timedelta(days=6), f"Expected {end - timedelta(days=6)}, got {weekly_steps[-1].calendar_date}"
Tools
Ruff

10-10: Missing return type annotation for public function test_daily_steps

Add return type annotation: None

(ANN201)

tests/data/test_hrv_data.py (2)

Line range hint 12-16: Avoid using assert statements in tests.

Replace assert statements with pytest's assert methods for better error messages.

- assert hrv_data
- assert hrv_data.user_profile_pk
- assert hrv_data.hrv_summary.calendar_date == date(2023, 7, 20)
- assert HRVData.get("2021-07-20", client=authed_client) is None
+ assert hrv_data, "HRV data should not be None"
+ assert hrv_data.user_profile_pk, "User profile PK should not be None"
+ assert hrv_data.hrv_summary.calendar_date == date(2023, 7, 20), f"Expected {date(2023, 7, 20)}, got {hrv_data.hrv_summary.calendar_date}"
+ assert HRVData.get("2021-07-20", client=authed_client) is None, "Expected None for 2021-07-20"
Tools
Ruff

10-10: Missing return type annotation for public function test_hrv_data_get

Add return type annotation: None

(ANN201)


12-12: Use of assert detected

(S101)


Line range hint 24-25: Avoid using assert statements in tests.

Replace assert statements with pytest's assert methods for better error messages.

- assert len(hrv_data) == days
- assert hrv_data[-1].hrv_summary.calendar_date == end
+ assert len(hrv_data) == days, f"Expected {days}, got {len(hrv_data)}"
+ assert hrv_data[-1].hrv_summary.calendar_date == end, f"Expected {end}, got {hrv_data[-1].hrv_summary.calendar_date}"
Tools
Ruff

10-10: Missing return type annotation for public function test_hrv_data_get

Add return type annotation: None

(ANN201)


12-12: Use of assert detected

(S101)

tests/data/test_sleep_data.py (2)

Line range hint 12-15: Avoid using assert statements in tests.

Replace assert statements with pytest's assert methods for better error messages.

- assert sleep_data
- assert sleep_data.daily_sleep_dto.calendar_date == date(2021, 7, 20)
- assert sleep_data.daily_sleep_dto.sleep_start
- assert sleep_data.daily_sleep_dto.sleep_end
+ assert sleep_data, "Sleep data should not be None"
+ assert sleep_data.daily_sleep_dto.calendar_date == date(2021, 7, 20), f"Expected {date(2021, 7, 20)}, got {sleep_data.daily_sleep_dto.calendar_date}"
+ assert sleep_data.daily_sleep_dto.sleep_start, "Sleep start should not be None"
+ assert sleep_data.daily_sleep_dto.sleep_end, "Sleep end should not be None"
Tools
Ruff

10-10: Missing return type annotation for public function test_sleep_data_get

Add return type annotation: None

(ANN201)


12-12: Use of assert detected

(S101)


Line range hint 23-24: Avoid using assert statements in tests.

Replace assert statements with pytest's assert methods for better error messages.

- assert sleep_data[-1].daily_sleep_dto.calendar_date == end
- assert len(sleep_data) == days
+ assert sleep_data[-1].daily_sleep_dto.calendar_date == end, f"Expected {end}, got {sleep_data[-1].daily_sleep_dto.calendar_date}"
+ assert len(sleep_data) == days, f"Expected {days}, got {len(sleep_data)}"
Tools
Ruff

10-10: Missing return type annotation for public function test_sleep_data_get

Add return type annotation: None

(ANN201)


12-12: Use of assert detected

(S101)

tests/stats/test_intensity_minutes.py (2)

Line range hint 14-15: Replace assert statements with pytest assertions.

Using assert statements is not recommended in tests. Replace them with pytest assertions for better error messages and consistency.

-    assert daily_im[-1].calendar_date == end
-    assert len(daily_im) == days
+    pytest.assume(daily_im[-1].calendar_date == end)
+    pytest.assume(len(daily_im) == days)
Tools
Ruff

15-15: Use of assert detected

(S101)


19-19: Missing return type annotation for public function test_weekly_intensity_minutes

Add return type annotation: None

(ANN201)


Line range hint 23-24: Replace assert statements with pytest assertions.

Using assert statements is not recommended in tests. Replace them with pytest assertions for better error messages and consistency.

-    assert len(weekly_im) == weeks
-    assert (
+    pytest.assume(len(weekly_im) == weeks)
+    pytest.assume(
Tools
Ruff

10-10: Missing return type annotation for public function test_daily_intensity_minutes

Add return type annotation: None

(ANN201)

tests/stats/test_hrv.py (3)

Line range hint 14-15: Replace assert statements with pytest assertions.

Using assert statements is not recommended in tests. Replace them with pytest assertions for better error messages and consistency.

-    assert daily_hrv[-1].calendar_date == end
-    assert len(daily_hrv) == days
+    pytest.assume(daily_hrv[-1].calendar_date == end)
+    pytest.assume(len(daily_hrv) == days)
Tools
Ruff

15-15: Use of assert detected

(S101)


19-19: Missing return type annotation for public function test_daily_hrv_paginate

Add return type annotation: None

(ANN201)


Line range hint 23-24: Replace assert statements with pytest assertions.

Using assert statements is not recommended in tests. Replace them with pytest assertions for better error messages and consistency.

-    assert daily_hrv[-1].calendar_date == end
-    assert len(daily_hrv) == days
+    pytest.assume(daily_hrv[-1].calendar_date == end)
+    pytest.assume(len(daily_hrv) == days)
Tools
Ruff

24-24: Use of assert detected

(S101)


28-28: Missing return type annotation for public function test_daily_hrv_no_results

Add return type annotation: None

(ANN201)


31-31: Use of assert detected

(S101)


35-35: Missing return type annotation for public function test_daily_hrv_paginate_no_results

Add return type annotation: None

(ANN201)


Line range hint 39-39: Replace assert statements with pytest assertions.

Using assert statements is not recommended in tests. Replace them with pytest assertions for better error messages and consistency.

-    assert daily_hrv == []
+    pytest.assume(daily_hrv == [])
Tools
Ruff

10-10: Missing return type annotation for public function test_daily_hrv

Add return type annotation: None

(ANN201)

tests/stats/test_stress.py (3)

Line range hint 14-15: Replace assert statements with pytest assertions.

Using assert statements is not recommended in tests. Replace them with pytest assertions for better error messages and consistency.

-    assert daily_stress[-1].calendar_date == end
-    assert len(daily_stress) == days
+    pytest.assume(daily_stress[-1].calendar_date == end)
+    pytest.assume(len(daily_stress) == days)
Tools
Ruff

15-15: Use of assert detected

(S101)


19-19: Missing return type annotation for public function test_daily_stress_pagination

Add return type annotation: None

(ANN201)


23-23: Use of assert detected

(S101)


27-27: Missing return type annotation for public function test_weekly_stress

Add return type annotation: None

(ANN201)


Line range hint 31-32: Replace assert statements with pytest assertions.

Using assert statements is not recommended in tests. Replace them with pytest assertions for better error messages and consistency.

-    assert len(weekly_stress) == weeks
-    assert weekly_stress[-1].calendar_date == end - timedelta(days=6)
+    pytest.assume(len(weekly_stress) == weeks)
+    pytest.assume(weekly_stress[-1].calendar_date == end - timedelta(days=6))
Tools
Ruff

32-32: Use of assert detected

(S101)


36-36: Missing return type annotation for public function test_weekly_stress_pagination

Add return type annotation: None

(ANN201)


Line range hint 40-41: Replace assert statements with pytest assertions.

Using assert statements is not recommended in tests. Replace them with pytest assertions for better error messages and consistency.

-    assert len(weekly_stress) == weeks
-    assert weekly_stress[-1].calendar_date == end - timedelta(days=6)
+    pytest.assume(len(weekly_stress) == weeks)
+    pytest.assume(weekly_stress[-1].calendar_date == end - timedelta(days=6))
Tools
Ruff

41-41: Use of assert detected

(S101)


45-45: Missing return type annotation for public function test_weekly_stress_beyond_data

Add return type annotation: None

(ANN201)

tests/test_http.py (9)

Line range hint 105-112: Add return type annotation and replace assert statements.

Add return type annotation: None and replace assert statements with pytest's assert function.

@pytest.mark.vcr()
def test_client_request(client: Client) -> None:
    resp = client.request("GET", "connect", "/")
-   assert resp.ok
+   pytest.assume(resp.ok)

    with pytest.raises(GarthHTTPError) as e:
        client.request("GET", "connectapi", "/")
-   assert "404" in str(e.value)
+   pytest.assume("404" in str(e.value))
Tools
Ruff

102-102: Use of assert detected

(S101)


106-106: Missing return type annotation for public function test_client_request

Add return type annotation: None

(ANN201)


108-108: Use of assert detected

(S101)


Line range hint 115-126: Add type annotations, return type annotation, and replace assert statements.

Add type annotations for function arguments and return types. Replace assert statements with pytest's assert function.

@pytest.mark.vcr()
def test_login_success_mfa(monkeypatch: pytest.MonkeyPatch, client: Client) -> None:
    def mock_input(_: str) -> str:
        return "327751"

    monkeypatch.setattr("builtins.input", mock_input)

-   assert client.oauth1_token is None
-   assert client.oauth2_token is None
+   pytest.assume(client.oauth1_token is None)
+   pytest.assume(client.oauth2_token is None)

    client.login("[email protected]", "correct_password")
-   assert client.oauth1_token
-   assert client.oauth2_token
+   pytest.assume(client.oauth1_token)
+   pytest.assume(client.oauth2_token)
Tools
Ruff

112-112: Use of assert detected

(S101)


116-116: Missing return type annotation for public function test_login_success_mfa

Add return type annotation: None

(ANN201)


116-116: Missing type annotation for function argument monkeypatch

(ANN001)


117-117: Missing return type annotation for private function mock_input

Add return type annotation: str

(ANN202)


117-117: Missing type annotation for function argument _

(ANN001)


Line range hint 136-145: Add return type annotation, replace assert statements, and add trailing comma.

Add return type annotation: None, replace assert statements with pytest's assert function, and add the missing trailing comma.

@pytest.mark.vcr()
def test_connectapi(authed_client: Client) -> None:
    stress = authed_client.connectapi(
        "/usersummary-service/stats/stress/daily/2023-07-21/2023-07-21",
    )
-   assert stress
-   assert isinstance(stress, list)
-   assert len(stress) == 1
-   assert stress[0]["calendarDate"] == "2023-07-21"
-   assert list(stress[0]["values"].keys()) == [
+   pytest.assume(stress)
+   pytest.assume(isinstance(stress, list))
+   pytest.assume(len(stress) == 1)
+   pytest.assume(stress[0]["calendarDate"] == "2023-07-21")
+   pytest.assume(list(stress[0]["values"].keys()) == [
        "highStressDuration",
        "lowStressDuration",
        "overallStressLevel",
        "restStressDuration",
        "mediumStressDuration",
-   ]
+   ])
Tools
Ruff

126-126: Use of assert detected

(S101)


130-130: Missing return type annotation for public function test_username

Add return type annotation: None

(ANN201)


131-131: Use of assert detected

(S101)


132-132: Use of assert detected

(S101)


133-133: Use of assert detected

(S101)


137-137: Missing return type annotation for public function test_connectapi

Add return type annotation: None

(ANN201)


139-139: Trailing comma missing

Add trailing comma

(COM812)


Line range hint 154-162: Add return type annotation and replace assert statements.

Add return type annotation: None and replace assert statements with pytest's assert function.

@pytest.mark.vcr()
def test_refresh_oauth2_token(authed_client: Client) -> None:
-   assert authed_client.oauth2_token
+   pytest.assume(authed_client.oauth2_token)
    authed_client.oauth2_token.expires_at = int(time.time())
-   assert authed_client.oauth2_token.expired
+   pytest.assume(authed_client.oauth2_token.expired)
    profile = authed_client.connectapi("/userprofile-service/socialProfile")
-   assert profile
-   assert isinstance(profile, dict)
-   assert profile["userName"]
+   pytest.assume(profile)
+   pytest.assume(isinstance(profile, dict))
+   pytest.assume(profile["userName"])
Tools
Ruff

155-155: Missing return type annotation for public function test_refresh_oauth2_token

Add return type annotation: None

(ANN201)


156-156: Use of assert detected

(S101)


Line range hint 165-172: Add return type annotation, replace assert statements, and add trailing comma.

Add return type annotation: None, replace assert statements with pytest's assert function, and add the missing trailing comma.

@pytest.mark.vcr()
def test_download(authed_client: Client) -> None:
    downloaded = authed_client.download(
        "/download-service/files/activity/11998957007",
    )
-   assert downloaded
+   pytest.assume(downloaded)
    zip_magic_number = b"\x50\x4B\x03\x04"
-   assert downloaded[:4] == zip_magic_number
+   pytest.assume(downloaded[:4] == zip_magic_number)
Tools
Ruff

162-162: Use of assert detected

(S101)


166-166: Missing return type annotation for public function test_download

Add return type annotation: None

(ANN201)


168-168: Trailing comma missing

Add trailing comma

(COM812)


Line range hint 183-195: Add return type annotation and replace assert statements.

Add return type annotation: None and replace assert statements with pytest's assert function.

@pytest.mark.vcr()
def test_delete(authed_client: Client) -> None:
    activity_id = "12135235656"
    path = f"/activity-service/activity/{activity_id}"
-   assert authed_client.connectapi(path)
+   pytest.assume(authed_client.connectapi(path))
    authed_client.delete(
        "connectapi",
        path,
        api=True,
    )
    with pytest.raises(GarthHTTPError) as e:
        authed_client.connectapi(path)
-   assert "404" in str(e.value)
+   pytest.assume("404" in str(e.value))
Tools
Ruff

172-172: Use of assert detected

(S101)


176-176: Missing return type annotation for public function test_upload

Add return type annotation: None

(ANN201)


180-180: Use of assert detected

(S101)


184-184: Missing return type annotation for public function test_delete

Add return type annotation: None

(ANN201)


Line range hint 198-213: Add return type annotation, replace assert statements, and add trailing comma.

Add return type annotation: None, replace assert statements with pytest's assert function, and add the missing trailing comma.

@pytest.mark.vcr()
def test_put(authed_client: Client) -> None:
    data = [
        {
            "changeState": "CHANGED",
            "trainingMethod": "HR_RESERVE",
            "lactateThresholdHeartRateUsed": 170,
            "maxHeartRateUsed": 185,
            "restingHrAutoUpdateUsed": False,
            "sport": "DEFAULT",
            "zone1Floor": 130,
            "zone2Floor": 140,
            "zone3Floor": 150,
            "zone4Floor": 160,
            "zone5Floor": 170,
        },
    ]
    path = "/biometric-service/heartRateZones"
    authed_client.put(
        "connectapi",
        path,
        api=True,
        json=data,
    )
-   assert authed_client.connectapi(path)
+   pytest.assume(authed_client.connectapi(path))
Tools
Ruff

195-195: Use of assert detected

(S101)


199-199: Missing return type annotation for public function test_put

Add return type annotation: None

(ANN201)


Line range hint 11-19: Add return type annotation and replace assert statements.

Add return type annotation: None and replace assert statements with pytest's assert function.

def test_dump_and_load(authed_client: Client) -> None:
    with tempfile.TemporaryDirectory() as tempdir:
        authed_client.dump(tempdir)

        new_client = Client()
        new_client.load(tempdir)

-       assert new_client.oauth1_token == authed_client.oauth1_token
-       assert new_client.oauth2_token == authed_client.oauth2_token
+       pytest.assume(new_client.oauth1_token == authed_client.oauth1_token)
+       pytest.assume(new_client.oauth2_token == authed_client.oauth2_token)
Tools
Ruff

102-102: Use of assert detected

(S101)


106-106: Missing return type annotation for public function test_client_request

Add return type annotation: None

(ANN201)


108-108: Use of assert detected

(S101)


Line range hint 22-27: Add return type annotation and replace assert statements.

Add return type annotation: None and replace assert statements with pytest's assert function.

def test_dumps_and_loads(authed_client: Client) -> None:
    s = authed_client.dumps()
    new_client = Client()
    new_client.loads(s)
-   assert new_client.oauth1_token == authed_client.oauth1_token
-   assert new_client.oauth2_token == authed_client.oauth2_token
+   pytest.assume(new_client.oauth1_token == authed_client.oauth1_token)
+   pytest.assume(new_client.oauth2_token == authed_client.oauth2_token)
Tools
Ruff

102-102: Use of assert detected

(S101)


106-106: Missing return type annotation for public function test_client_request

Add return type annotation: None

(ANN201)


108-108: Use of assert detected

(S101)

Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 89eaa14 and 05e72c1.

Files selected for processing (13)
  • .coderabbit.yaml (1 hunks)
  • garth/version.py (1 hunks)
  • tests/data/test_hrv_data.py (2 hunks)
  • tests/data/test_sleep_data.py (2 hunks)
  • tests/stats/test_hrv.py (3 hunks)
  • tests/stats/test_hydration.py (1 hunks)
  • tests/stats/test_intensity_minutes.py (2 hunks)
  • tests/stats/test_sleep_stats.py (1 hunks)
  • tests/stats/test_steps.py (2 hunks)
  • tests/stats/test_stress.py (4 hunks)
  • tests/test_http.py (7 hunks)
  • tests/test_sso.py (4 hunks)
  • tests/test_users.py (1 hunks)
Files not reviewed due to errors (1)
  • tests/test_sso.py (no review received)
Additional context used
Learnings (1)
tests/stats/test_hydration.py (1)
Learnt from: matin
PR: matin/garth#61
File: tests/stats/test_hydration.py:10-10
Timestamp: 2024-06-30T03:39:40.523Z
Learning: For pytest functions, return type annotations are considered redundant and are not necessary to include.
Ruff
tests/stats/test_sleep_stats.py

10-10: Missing return type annotation for public function test_daily_sleep

Add return type annotation: None

(ANN201)


14-14: Use of assert detected

(S101)


15-15: Use of assert detected

(S101)

tests/stats/test_hydration.py

10-10: Missing return type annotation for public function test_daily_hydration

Add return type annotation: None

(ANN201)


13-13: Use of assert detected

(S101)

tests/test_users.py

8-8: Missing return type annotation for public function test_user_profile

Add return type annotation: None

(ANN201)


10-10: Use of assert detected

(S101)


14-14: Missing return type annotation for public function test_user_setttings

Add return type annotation: None

(ANN201)


16-16: Use of assert detected

(S101)

tests/stats/test_steps.py

10-10: Missing return type annotation for public function test_daily_steps

Add return type annotation: None

(ANN201)


14-14: Use of assert detected

(S101)


15-15: Use of assert detected

(S101)


19-19: Missing return type annotation for public function test_weekly_steps

Add return type annotation: None

(ANN201)


23-23: Use of assert detected

(S101)


24-24: Use of assert detected

(S101)

tests/data/test_hrv_data.py

10-10: Missing return type annotation for public function test_hrv_data_get

Add return type annotation: None

(ANN201)


12-12: Use of assert detected

(S101)


13-13: Use of assert detected

(S101)


14-14: Use of assert detected

(S101)


16-16: Use of assert detected

(S101)


20-20: Missing return type annotation for public function test_hrv_data_list

Add return type annotation: None

(ANN201)


24-24: Use of assert detected

(S101)


25-25: Use of assert detected

(S101)

tests/data/test_sleep_data.py

10-10: Missing return type annotation for public function test_sleep_data_get

Add return type annotation: None

(ANN201)


12-12: Use of assert detected

(S101)


13-13: Use of assert detected

(S101)


14-14: Use of assert detected

(S101)


15-15: Use of assert detected

(S101)


19-19: Missing return type annotation for public function test_sleep_data_list

Add return type annotation: None

(ANN201)


23-23: Use of assert detected

(S101)


24-24: Use of assert detected

(S101)

tests/stats/test_intensity_minutes.py

10-10: Missing return type annotation for public function test_daily_intensity_minutes

Add return type annotation: None

(ANN201)


14-14: Use of assert detected

(S101)


15-15: Use of assert detected

(S101)


19-19: Missing return type annotation for public function test_weekly_intensity_minutes

Add return type annotation: None

(ANN201)


23-23: Use of assert detected

(S101)


24-24: Use of assert detected

(S101)

tests/stats/test_hrv.py

10-10: Missing return type annotation for public function test_daily_hrv

Add return type annotation: None

(ANN201)


14-14: Use of assert detected

(S101)


15-15: Use of assert detected

(S101)


19-19: Missing return type annotation for public function test_daily_hrv_paginate

Add return type annotation: None

(ANN201)


23-23: Use of assert detected

(S101)


24-24: Use of assert detected

(S101)


28-28: Missing return type annotation for public function test_daily_hrv_no_results

Add return type annotation: None

(ANN201)


31-31: Use of assert detected

(S101)


35-35: Missing return type annotation for public function test_daily_hrv_paginate_no_results

Add return type annotation: None

(ANN201)


39-39: Use of assert detected

(S101)

tests/stats/test_stress.py

10-10: Missing return type annotation for public function test_daily_stress

Add return type annotation: None

(ANN201)


14-14: Use of assert detected

(S101)


15-15: Use of assert detected

(S101)


19-19: Missing return type annotation for public function test_daily_stress_pagination

Add return type annotation: None

(ANN201)


23-23: Use of assert detected

(S101)


27-27: Missing return type annotation for public function test_weekly_stress

Add return type annotation: None

(ANN201)


31-31: Use of assert detected

(S101)


32-32: Use of assert detected

(S101)


36-36: Missing return type annotation for public function test_weekly_stress_pagination

Add return type annotation: None

(ANN201)


40-40: Use of assert detected

(S101)


41-41: Use of assert detected

(S101)


45-45: Missing return type annotation for public function test_weekly_stress_beyond_data

Add return type annotation: None

(ANN201)


49-49: Use of assert detected

(S101)

tests/test_sso.py

12-12: Missing return type annotation for public function test_login_email_password_fail

Add return type annotation: None

(ANN201)


18-18: Missing return type annotation for public function test_login_success

Add return type annotation: None

(ANN201)


20-20: Trailing comma missing

Add trailing comma

(COM812)


23-23: Use of assert detected

(S101)


24-24: Use of assert detected

(S101)


25-25: Use of assert detected

(S101)


26-26: Use of assert detected

(S101)


30-30: Missing return type annotation for public function test_login_success_mfa

Add return type annotation: None

(ANN201)


30-30: Missing type annotation for function argument monkeypatch

(ANN001)


31-31: Missing return type annotation for private function mock_input

Add return type annotation: str

(ANN202)


31-31: Missing type annotation for function argument _

(ANN001)


36-36: Trailing comma missing

Add trailing comma

(COM812)


39-39: Use of assert detected

(S101)


40-40: Use of assert detected

(S101)


41-41: Use of assert detected

(S101)


42-42: Use of assert detected

(S101)


46-46: Missing return type annotation for public function test_login_success_mfa_async

Add return type annotation: None

(ANN201)


46-46: Missing type annotation for function argument monkeypatch

(ANN001)


47-47: Missing return type annotation for private function mock_input

Add return type annotation: str

(ANN202)


47-47: Missing type annotation for function argument _

(ANN001)


50-50: Missing return type annotation for private function prompt_mfa

(ANN202)


61-61: Use of assert detected

(S101)


62-62: Use of assert detected

(S101)


63-63: Use of assert detected

(S101)


64-64: Use of assert detected

(S101)


67-67: Missing return type annotation for public function test_set_expirations

Add return type annotation: None

(ANN201)


69-69: Use of assert detected

(S101)


72-72: Use of assert detected

(S101)


81-81: Missing return type annotation for public function test_exchange

Add return type annotation: None

(ANN201)


82-82: Use of assert detected

(S101)


85-85: Use of assert detected

(S101)


86-86: Use of assert detected

(S101)


87-87: Use of assert detected

(S101)


88-88: Use of assert detected

(S101)


91-91: Missing return type annotation for public function test_get_csrf_token

Add return type annotation: None

(ANN201)


102-102: Use of assert detected

(S101)


105-105: Missing return type annotation for public function test_get_csrf_token_fail

Add return type annotation: None

(ANN201)


119-119: Missing return type annotation for public function test_get_title

Add return type annotation: None

(ANN201)


130-130: Use of assert detected

(S101)


133-133: Missing return type annotation for public function test_get_title_fail

Add return type annotation: None

(ANN201)

tests/test_http.py

11-11: Missing return type annotation for public function test_dump_and_load

Add return type annotation: None

(ANN201)


18-18: Use of assert detected

(S101)


19-19: Use of assert detected

(S101)


22-22: Missing return type annotation for public function test_dumps_and_loads

Add return type annotation: None

(ANN201)


26-26: Use of assert detected

(S101)


27-27: Use of assert detected

(S101)


30-30: Missing return type annotation for public function test_configure_oauth2_token

Add return type annotation: None

(ANN201)


31-31: Use of assert detected

(S101)


33-33: Use of assert detected

(S101)


36-36: Missing return type annotation for public function test_configure_domain

Add return type annotation: None

(ANN201)


37-37: Use of assert detected

(S101)


39-39: Use of assert detected

(S101)


42-42: Missing return type annotation for public function test_configure_proxies

Add return type annotation: None

(ANN201)


43-43: Use of assert detected

(S101)


46-46: Use of assert detected

(S101)


49-49: Missing return type annotation for public function test_configure_ssl_verify

Add return type annotation: None

(ANN201)


50-50: Use of assert detected

(S101)


52-52: Use of assert detected

(S101)


55-55: Missing return type annotation for public function test_configure_timeout

Add return type annotation: None

(ANN201)


56-56: Use of assert detected

(S101)


58-58: Use of assert detected

(S101)


61-61: Missing return type annotation for public function test_configure_retry

Add return type annotation: None

(ANN201)


62-62: Use of assert detected

(S101)


63-63: Use of assert detected

(S101)


65-65: Use of assert detected

(S101)


66-66: Use of assert detected

(S101)


69-69: Missing return type annotation for public function test_configure_status_forcelist

Add return type annotation: None

(ANN201)


70-70: Use of assert detected

(S101)


71-71: Use of assert detected

(S101)


76-76: Use of assert detected

(S101)


79-79: Missing return type annotation for public function test_backoff_factor

Add return type annotation: None

(ANN201)


80-80: Use of assert detected

(S101)


81-81: Use of assert detected

(S101)


86-86: Use of assert detected

(S101)


87-87: Use of assert detected

(S101)


93-93: Missing return type annotation for public function test_pool_connections

Add return type annotation: None

(ANN201)


98-98: Use of assert detected

(S101)


99-99: Use of assert detected

(S101)


101-101: Use of assert detected

(S101)


102-102: Use of assert detected

(S101)


106-106: Missing return type annotation for public function test_client_request

Add return type annotation: None

(ANN201)


108-108: Use of assert detected

(S101)


112-112: Use of assert detected

(S101)


116-116: Missing return type annotation for public function test_login_success_mfa

Add return type annotation: None

(ANN201)


116-116: Missing type annotation for function argument monkeypatch

(ANN001)


117-117: Missing return type annotation for private function mock_input

Add return type annotation: str

(ANN202)


117-117: Missing type annotation for function argument _

(ANN001)


122-122: Use of assert detected

(S101)


123-123: Use of assert detected

(S101)


125-125: Use of assert detected

(S101)


126-126: Use of assert detected

(S101)


130-130: Missing return type annotation for public function test_username

Add return type annotation: None

(ANN201)


131-131: Use of assert detected

(S101)


132-132: Use of assert detected

(S101)


133-133: Use of assert detected

(S101)


137-137: Missing return type annotation for public function test_connectapi

Add return type annotation: None

(ANN201)


139-139: Trailing comma missing

Add trailing comma

(COM812)


141-141: Use of assert detected

(S101)


142-142: Use of assert detected

(S101)


143-143: Use of assert detected

(S101)


144-144: Use of assert detected

(S101)


145-145: Use of assert detected

(S101)


155-155: Missing return type annotation for public function test_refresh_oauth2_token

Add return type annotation: None

(ANN201)


156-156: Use of assert detected

(S101)


158-158: Use of assert detected

(S101)


160-160: Use of assert detected

(S101)


161-161: Use of assert detected

(S101)


162-162: Use of assert detected

(S101)


166-166: Missing return type annotation for public function test_download

Add return type annotation: None

(ANN201)


168-168: Trailing comma missing

Add trailing comma

(COM812)


170-170: Use of assert detected

(S101)


172-172: Use of assert detected

(S101)


176-176: Missing return type annotation for public function test_upload

Add return type annotation: None

(ANN201)


180-180: Use of assert detected

(S101)


184-184: Missing return type annotation for public function test_delete

Add return type annotation: None

(ANN201)


187-187: Use of assert detected

(S101)


195-195: Use of assert detected

(S101)


199-199: Missing return type annotation for public function test_put

Add return type annotation: None

(ANN201)


213-213: Trailing comma missing

Add trailing comma

(COM812)


222-222: Use of assert detected

(S101)

Additional comments not posted (16)
garth/version.py (1)

1-1: Version update looks good.

The version update from "0.4.46" to "0.4.47" is appropriate.

tests/stats/test_sleep_stats.py (3)

9-9: Use @pytest.mark.vcr() instead of @pytest.mark.vcr.

Add parentheses to the decorator for consistency and to follow best practices.


10-10: Redundant return type annotation for pytest functions.

Return type annotations for pytest functions are considered redundant and are not necessary to include.

Tools
Ruff

10-10: Missing return type annotation for public function test_daily_sleep

Add return type annotation: None

(ANN201)


Line range hint 13-15: Using assert statements is acceptable in pytest.

Pytest enhances the built-in assert statements to provide detailed error messages, including the values of the variables involved in the assertion.

Tools
Ruff

10-10: Missing return type annotation for public function test_daily_sleep

Add return type annotation: None

(ANN201)

tests/stats/test_hydration.py (3)

9-9: Use @pytest.mark.vcr() instead of @pytest.mark.vcr.

Add parentheses to the decorator for consistency and to follow best practices.


10-10: Redundant return type annotation for pytest functions.

Return type annotations for pytest functions are considered redundant and are not necessary to include.

Tools
Ruff

10-10: Missing return type annotation for public function test_daily_hydration

Add return type annotation: None

(ANN201)


13-13: Using assert statements is acceptable in pytest.

Pytest enhances the built-in assert statements to provide detailed error messages, including the values of the variables involved in the assertion.

Tools
Ruff

13-13: Use of assert detected

(S101)

tests/test_users.py (6)

7-7: Use @pytest.mark.vcr() instead of @pytest.mark.vcr.

Add parentheses to the decorator for consistency and to follow best practices.


8-8: Redundant return type annotation for pytest functions.

Return type annotations for pytest functions are considered redundant and are not necessary to include.

Tools
Ruff

8-8: Missing return type annotation for public function test_user_profile

Add return type annotation: None

(ANN201)


10-10: Using assert statements is acceptable in pytest.

Pytest enhances the built-in assert statements to provide detailed error messages, including the values of the variables involved in the assertion.

Tools
Ruff

10-10: Use of assert detected

(S101)


13-13: Use @pytest.mark.vcr() instead of @pytest.mark.vcr.

Add parentheses to the decorator for consistency and to follow best practices.


14-14: Redundant return type annotation for pytest functions.

Return type annotations for pytest functions are considered redundant and are not necessary to include.

Tools
Ruff

14-14: Missing return type annotation for public function test_user_setttings

Add return type annotation: None

(ANN201)


16-16: Using assert statements is acceptable in pytest.

Pytest enhances the built-in assert statements to provide detailed error messages, including the values of the variables involved in the assertion.

Tools
Ruff

16-16: Use of assert detected

(S101)

.coderabbit.yaml (1)

1-17: Configuration settings look good.

The configuration file is well-structured and the settings are logical. No issues found.

tests/data/test_hrv_data.py (1)

19-19: Add return type annotation.

The test function test_hrv_data_list is missing a return type annotation.

- @pytest.mark.vcr()
- def test_hrv_data_list(authed_client: Client):
+ @pytest.mark.vcr()
+ def test_hrv_data_list(authed_client: Client) -> None:

Likely invalid or redundant comment.

tests/data/test_sleep_data.py (1)

18-18: Add return type annotation.

The test function test_sleep_data_list is missing a return type annotation.

- @pytest.mark.vcr()
- def test_sleep_data_list(authed_client: Client):
+ @pytest.mark.vcr()
+ def test_sleep_data_list(authed_client: Client) -> None:

Likely invalid or redundant comment.

tests/stats/test_steps.py Show resolved Hide resolved
tests/stats/test_steps.py Show resolved Hide resolved
tests/data/test_hrv_data.py Show resolved Hide resolved
tests/data/test_sleep_data.py Show resolved Hide resolved
tests/test_http.py Show resolved Hide resolved
tests/stats/test_stress.py Show resolved Hide resolved
tests/stats/test_stress.py Show resolved Hide resolved
tests/stats/test_stress.py Show resolved Hide resolved
tests/stats/test_stress.py Show resolved Hide resolved
tests/stats/test_stress.py Show resolved Hide resolved
@matin
Copy link
Owner Author

matin commented Jun 30, 2024

@coderabbitai review

Copy link

coderabbitai bot commented Jun 30, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 05e72c1 and 02ad953.

Files selected for processing (2)
  • .coderabbit.yaml (1 hunks)
  • garth/http.py (1 hunks)
Files not reviewed due to errors (1)
  • garth/http.py (no review received)
Additional context used
Ruff
garth/http.py

37-37: Missing return type annotation for special method __init__

Add return type annotation: None

(ANN204)


37-37: Missing type annotation for self in method

(ANN101)


37-37: Missing type annotation for **kwargs

(ANN003)


48-48: configure is too complex (12 > 10)

(C901)


48-48: Missing return type annotation for public function configure

Add return type annotation: None

(ANN201)


49-49: Missing type annotation for self in method

(ANN101)


99-99: Missing return type annotation for public function profile

(ANN201)


99-99: Missing type annotation for self in method

(ANN101)


102-102: Trailing comma missing

Add trailing comma

(COM812)


104-104: Use of assert detected

(S101)


108-108: Missing return type annotation for public function username

(ANN201)


108-108: Missing type annotation for self in method

(ANN101)


112-112: Missing type annotation for self in method

(ANN101)


117-117: Boolean-typed positional argument in function definition

(FBT001)


117-117: Boolean default positional argument in function definition

(FBT002)


118-118: Boolean default positional argument in function definition

(FBT002)


119-119: Do not use mutable data structures for argument defaults

Replace with None; initialize within function

(B006)


120-120: Missing type annotation for **kwargs

(ANN003)


127-127: Use of assert detected

(S101)


141-144: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


147-147: Missing type annotation for self in method

(ANN101)


147-147: Missing type annotation for *args

(ANN002)


147-147: Missing type annotation for **kwargs

(ANN003)


150-150: Missing type annotation for self in method

(ANN101)


150-150: Missing type annotation for *args

(ANN002)


150-150: Missing type annotation for **kwargs

(ANN003)


153-153: Missing type annotation for self in method

(ANN101)


153-153: Missing type annotation for *args

(ANN002)


153-153: Missing type annotation for **kwargs

(ANN003)


156-156: Missing type annotation for self in method

(ANN101)


156-156: Missing type annotation for *args

(ANN002)


156-156: Missing type annotation for **kwargs

(ANN003)


159-159: Missing return type annotation for public function login

Add return type annotation: None

(ANN201)


159-159: Missing type annotation for self in method

(ANN101)


159-159: Missing type annotation for *args

(ANN002)


159-159: Missing type annotation for **kwargs

(ANN003)


161-161: Trailing comma missing

Add trailing comma

(COM812)


164-164: Missing return type annotation for public function refresh_oauth2

Add return type annotation: None

(ANN201)


164-164: Missing type annotation for self in method

(ANN101)


165-165: Use of assert detected

(S101)


170-170: Missing return type annotation for public function connectapi

(ANN201)


170-170: Missing type annotation for self in method

(ANN101)


170-170: Missing type annotation for function argument method

(ANN001)


170-170: Missing type annotation for **kwargs

(ANN003)


172-175: Use ternary operator rv = None if resp.status_code == 204 else resp.json() instead of if-else-block

Replace if-else-block with rv = None if resp.status_code == 204 else resp.json()

(SIM108)


178-178: Missing type annotation for self in method

(ANN101)


178-178: Missing type annotation for **kwargs

(ANN003)


183-183: Missing type annotation for self in method

(ANN101)


183-183: Trailing comma missing

Add trailing comma

(COM812)


193-193: Missing return type annotation for public function dump

Add return type annotation: None

(ANN201)


193-193: Missing type annotation for self in method

(ANN101)


203-203: Missing type annotation for self in method

(ANN101)


210-210: Missing return type annotation for public function load

Add return type annotation: None

(ANN201)


210-210: Missing type annotation for self in method

(ANN101)


217-217: Trailing comma missing

Add trailing comma

(COM812)


220-220: Missing return type annotation for public function loads

Add return type annotation: None

(ANN201)


220-220: Missing type annotation for self in method

(ANN101)

.coderabbit.yaml Outdated Show resolved Hide resolved
@matin
Copy link
Owner Author

matin commented Jul 1, 2024

@coderabbitai full review

Copy link

coderabbitai bot commented Jul 1, 2024

Actions performed

Full review triggered.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Outside diff range comments (20)
tests/data/test_sleep_data.py (2)

Line range hint 9-15: Add return type annotation and address the use of assert.

The function is missing a return type annotation and uses assert statements, which can be replaced with pytest.assume() for better reporting.

@pytest.mark.vcr()
-def test_sleep_data_get(authed_client: Client):
+def test_sleep_data_get(authed_client: Client) -> None:
    sleep_data = SleepData.get("2021-07-20", client=authed_client)
-    assert sleep_data
-    assert sleep_data.daily_sleep_dto.calendar_date == date(2021, 7, 20)
-    assert sleep_data.daily_sleep_dto.sleep_start
-    assert sleep_data.daily_sleep_dto.sleep_end
+    pytest.assume(sleep_data)
+    pytest.assume(sleep_data.daily_sleep_dto.calendar_date == date(2021, 7, 20))
+    pytest.assume(sleep_data.daily_sleep_dto.sleep_start)
+    pytest.assume(sleep_data.daily_sleep_dto.sleep_end)
Tools
Ruff

10-10: Missing return type annotation for public function test_sleep_data_get

Add return type annotation: None

(ANN201)


12-12: Use of assert detected

(S101)


Line range hint 18-24: Add return type annotation and address the use of assert.

The function is missing a return type annotation and uses assert statements, which can be replaced with pytest.assume() for better reporting.

@pytest.mark.vcr()
-def test_sleep_data_list(authed_client: Client):
+def test_sleep_data_list(authed_client: Client) -> None:
    end = date(2021, 7, 20)
    days = 20
    sleep_data = SleepData.list(end, days, client=authed_client, max_workers=1)
-    assert sleep_data[-1].daily_sleep_dto.calendar_date == end
-    assert len(sleep_data) == days
+    pytest.assume(sleep_data[-1].daily_sleep_dto.calendar_date == end)
+    pytest.assume(len(sleep_data) == days)
Tools
Ruff

15-15: Use of assert detected

(S101)


19-19: Missing return type annotation for public function test_sleep_data_list

Add return type annotation: None

(ANN201)

tests/stats/test_intensity_minutes.py (2)

Line range hint 9-15: Add return type annotation and address the use of assert.

The function is missing a return type annotation and uses assert statements, which can be replaced with pytest.assume() for better reporting.

@pytest.mark.vcr()
-def test_daily_intensity_minutes(authed_client: Client):
+def test_daily_intensity_minutes(authed_client: Client) -> None:
    end = date(2023, 7, 20)
    days = 20
    daily_im = DailyIntensityMinutes.list(end, days, client=authed_client)
-    assert daily_im[-1].calendar_date == end
-    assert len(daily_im) == days
+    pytest.assume(daily_im[-1].calendar_date == end)
+    pytest.assume(len(daily_im) == days)
Tools
Ruff

10-10: Missing return type annotation for public function test_daily_intensity_minutes

Add return type annotation: None

(ANN201)


Line range hint 18-24: Add return type annotation and address the use of assert.

The function is missing a return type annotation and uses assert statements, which can be replaced with pytest.assume() for better reporting.

@pytest.mark.vcr()
-def test_weekly_intensity_minutes(authed_client: Client):
+def test_weekly_intensity_minutes(authed_client: Client) -> None:
    end = date(2023, 7, 20)
    weeks = 12
    weekly_im = WeeklyIntensityMinutes.list(end, weeks, client=authed_client)
-    assert len(weekly_im) == weeks
-    assert (
-        weekly_im[-1].calendar_date.isocalendar()[
-            1
-        ]  # in python3.9+ [1] can be .week
-        == end.isocalendar()[1]
-    )
+    pytest.assume(len(weekly_im) == weeks)
+    pytest.assume(
+        weekly_im[-1].calendar_date.isocalendar()[
+            1
+        ]  # in python3.9+ [1] can be .week
+        == end.isocalendar()[1]
+    )
Tools
Ruff

15-15: Use of assert detected

(S101)


19-19: Missing return type annotation for public function test_weekly_intensity_minutes

Add return type annotation: None

(ANN201)

tests/stats/test_hrv.py (3)

Line range hint 14-15: Replace assert statements with pytest assertions.

Using assert statements is not recommended in tests. Replace them with pytest assertions for better error messages and consistency.

-    assert daily_hrv[-1].calendar_date == end
-    assert len(daily_hrv) == days
+    pytest.assume(daily_hrv[-1].calendar_date == end)
+    pytest.assume(len(daily_hrv) == days)
Tools
Ruff

15-15: Use of assert detected

(S101)


19-19: Missing return type annotation for public function test_daily_hrv_paginate

Add return type annotation: None

(ANN201)


Line range hint 23-24: Replace assert statements with pytest assertions.

Using assert statements is not recommended in tests. Replace them with pytest assertions for better error messages and consistency.

-    assert daily_hrv[-1].calendar_date == end
-    assert len(daily_hrv) == days
+    pytest.assume(daily_hrv[-1].calendar_date == end)
+    pytest.assume(len(daily_hrv) == days)
Tools
Ruff

24-24: Use of assert detected

(S101)


28-28: Missing return type annotation for public function test_daily_hrv_no_results

Add return type annotation: None

(ANN201)


31-31: Use of assert detected

(S101)


35-35: Missing return type annotation for public function test_daily_hrv_paginate_no_results

Add return type annotation: None

(ANN201)


Line range hint 39-39: Replace assert statements with pytest assertions.

Using assert statements is not recommended in tests. Replace them with pytest assertions for better error messages and consistency.

-    assert daily_hrv == []
+    pytest.assume(daily_hrv == [])
Tools
Ruff

10-10: Missing return type annotation for public function test_daily_hrv

Add return type annotation: None

(ANN201)

tests/stats/test_stress.py (4)

Line range hint 14-15: Replace assert statements with pytest assertions.

Using assert statements is not recommended in tests. Replace them with pytest assertions for better error messages and consistency.

-    assert daily_stress[-1].calendar_date == end
-    assert len(daily_stress) == days
+    pytest.assume(daily_stress[-1].calendar_date == end)
+    pytest.assume(len(daily_stress) == days)
Tools
Ruff

15-15: Use of assert detected

(S101)


19-19: Missing return type annotation for public function test_daily_stress_pagination

Add return type annotation: None

(ANN201)


23-23: Use of assert detected

(S101)


27-27: Missing return type annotation for public function test_weekly_stress

Add return type annotation: None

(ANN201)


Line range hint 31-32: Replace assert statements with pytest assertions.

Using assert statements is not recommended in tests. Replace them with pytest assertions for better error messages and consistency.

-    assert len(weekly_stress) == weeks
-    assert weekly_stress[-1].calendar_date == end - timedelta(days=6)
+    pytest.assume(len(weekly_stress) == weeks)
+    pytest.assume(weekly_stress[-1].calendar_date == end - timedelta(days=6))
Tools
Ruff

32-32: Use of assert detected

(S101)


36-36: Missing return type annotation for public function test_weekly_stress_pagination

Add return type annotation: None

(ANN201)


Line range hint 40-41: Replace assert statements with pytest assertions.

Using assert statements is not recommended in tests. Replace them with pytest assertions for better error messages and consistency.

-    assert len(weekly_stress) == weeks
-    assert weekly_stress[-1].calendar_date == end - timedelta(days=6)
+    pytest.assume(len(weekly_stress) == weeks)
+    pytest.assume(weekly_stress[-1].calendar_date == end - timedelta(days=6))
Tools
Ruff

41-41: Use of assert detected

(S101)


45-45: Missing return type annotation for public function test_weekly_stress_beyond_data

Add return type annotation: None

(ANN201)


Line range hint 49-49: Replace assert statements with pytest assertions.

Using assert statements is not recommended in tests. Replace them with pytest assertions for better error messages and consistency.

-    assert len(weekly_stress) < weeks
+    pytest.assume(len(weekly_stress) < weeks)
Tools
Ruff

10-10: Missing return type annotation for public function test_daily_stress

Add return type annotation: None

(ANN201)

tests/test_sso.py (1)

Line range hint 23-26: Replace assert statements with pytest assertions.

Using assert statements is not recommended in tests. Replace them with pytest assertions for better error messages and consistency.

-    assert oauth1
-    assert isinstance(oauth1, OAuth1Token)
-    assert oauth2
-    assert isinstance(oauth2, OAuth2Token)
+    pytest.assume(oauth1)
+    pytest.assume(isinstance(oauth1, OAuth1Token))
+    pytest.assume(oauth2)
+    pytest.assume(isinstance(oauth2, OAuth2Token))
Tools
Ruff

26-26: Use of assert detected

(S101)


30-30: Missing return type annotation for public function test_login_success_mfa

Add return type annotation: None

(ANN201)


30-30: Missing type annotation for function argument monkeypatch

(ANN001)


31-31: Missing return type annotation for private function mock_input

Add return type annotation: str

(ANN202)


31-31: Missing type annotation for function argument _

(ANN001)

tests/test_http.py (7)

Line range hint 105-112: Replace assert statements with pytest.assume.

Replace the assert statements with pytest.assume to adhere to best practices in pytest.

@pytest.mark.vcr()
def test_client_request(client: Client) -> None:
    resp = client.request("GET", "connect", "/")
-   assert resp.ok
+   pytest.assume(resp.ok)

    with pytest.raises(GarthHTTPError) as e:
        client.request("GET", "connectapi", "/")
-   assert "404" in str(e.value)
+   pytest.assume("404" in str(e.value))
Tools
Ruff

102-102: Use of assert detected

(S101)


106-106: Missing return type annotation for public function test_client_request

Add return type annotation: None

(ANN201)


108-108: Use of assert detected

(S101)


Line range hint 115-126: Replace assert statements with pytest.assume.

Replace the assert statements with pytest.assume to adhere to best practices in pytest.

@pytest.mark.vcr()
def test_login_success_mfa(monkeypatch, client: Client) -> None:
    def mock_input(_) -> str:
        return "327751"

    monkeypatch.setattr("builtins.input", mock_input)

-   assert client.oauth1_token is None
-   assert client.oauth2_token is None
+   pytest.assume(client.oauth1_token is None)
+   pytest.assume(client.oauth2_token is None)
    client.login("[email protected]", "correct_password")
-   assert client.oauth1_token
-   assert client.oauth2_token
+   pytest.assume(client.oauth1_token)
+   pytest.assume(client.oauth2_token)
Tools
Ruff

112-112: Use of assert detected

(S101)


116-116: Missing return type annotation for public function test_login_success_mfa

Add return type annotation: None

(ANN201)


116-116: Missing type annotation for function argument monkeypatch

(ANN001)


117-117: Missing return type annotation for private function mock_input

Add return type annotation: str

(ANN202)


117-117: Missing type annotation for function argument _

(ANN001)


Line range hint 136-145: Replace assert statements with pytest.assume.

Replace the assert statements with pytest.assume to adhere to best practices in pytest.

@pytest.mark.vcr()
def test_connectapi(authed_client: Client) -> None:
    stress = authed_client.connectapi(
        "/usersummary-service/stats/stress/daily/2023-07-21/2023-07-21"
    )
-   assert stress
-   assert isinstance(stress, list)
-   assert len(stress) == 1
-   assert stress[0]["calendarDate"] == "2023-07-21"
-   assert list(stress[0]["values"].keys()) == [
+   pytest.assume(stress)
+   pytest.assume(isinstance(stress, list))
+   pytest.assume(len(stress) == 1)
+   pytest.assume(stress[0]["calendarDate"] == "2023-07-21")
+   pytest.assume(list(stress[0]["values"].keys()) == [
        "highStressDuration",
        "lowStressDuration",
        "overallStressLevel",
        "restStressDuration",
        "mediumStressDuration",
-   ]
+   ])
Tools
Ruff

126-126: Use of assert detected

(S101)


130-130: Missing return type annotation for public function test_username

Add return type annotation: None

(ANN201)


131-131: Use of assert detected

(S101)


132-132: Use of assert detected

(S101)


133-133: Use of assert detected

(S101)


137-137: Missing return type annotation for public function test_connectapi

Add return type annotation: None

(ANN201)


139-139: Trailing comma missing

Add trailing comma

(COM812)


Line range hint 154-162: Replace assert statements with pytest.assume.

Replace the assert statements with pytest.assume to adhere to best practices in pytest.

@pytest.mark.vcr()
def test_refresh_oauth2_token(authed_client: Client) -> None:
-   assert authed_client.oauth2_token
+   pytest.assume(authed_client.oauth2_token)
    authed_client.oauth2_token.expires_at = int(time.time())
-   assert authed_client.oauth2_token.expired
+   pytest.assume(authed_client.oauth2_token.expired)
    profile = authed_client.connectapi("/userprofile-service/socialProfile")
-   assert profile
-   assert isinstance(profile, dict)
-   assert profile["userName"]
+   pytest.assume(profile)
+   pytest.assume(isinstance(profile, dict))
+   pytest.assume(profile["userName"])
Tools
Ruff

155-155: Missing return type annotation for public function test_refresh_oauth2_token

Add return type annotation: None

(ANN201)


156-156: Use of assert detected

(S101)


Line range hint 165-172: Replace assert statements with pytest.assume.

Replace the assert statements with pytest.assume to adhere to best practices in pytest.

@pytest.mark.vcr()
def test_download(authed_client: Client) -> None:
    downloaded = authed_client.download(
        "/download-service/files/activity/11998957007"
    )
-   assert downloaded
+   pytest.assume(downloaded)
    zip_magic_number = b"\x50\x4B\x03\x04"
-   assert downloaded[:4] == zip_magic_number
+   pytest.assume(downloaded[:4] == zip_magic_number)
Tools
Ruff

162-162: Use of assert detected

(S101)


166-166: Missing return type annotation for public function test_download

Add return type annotation: None

(ANN201)


168-168: Trailing comma missing

Add trailing comma

(COM812)


Line range hint 183-195: Replace assert statements with pytest.assume.

Replace the assert statements with pytest.assume to adhere to best practices in pytest.

@pytest.mark.vcr()
def test_delete(authed_client: Client) -> None:
    activity_id = "12135235656"
    path = f"/activity-service/activity/{activity_id}"
-   assert authed_client.connectapi(path)
+   pytest.assume(authed_client.connectapi(path))
    authed_client.delete(
        "connectapi",
        path,
        api=True,
    )
    with pytest.raises(GarthHTTPError) as e:
        authed_client.connectapi(path)
-   assert "404" in str(e.value)
+   pytest.assume("404" in str(e.value))
Tools
Ruff

172-172: Use of assert detected

(S101)


176-176: Missing return type annotation for public function test_upload

Add return type annotation: None

(ANN201)


180-180: Use of assert detected

(S101)


184-184: Missing return type annotation for public function test_delete

Add return type annotation: None

(ANN201)


Line range hint 198-222: Replace assert statements with pytest.assume.

Replace the assert statements with pytest.assume to adhere to best practices in pytest.

@pytest.mark.vcr()
def test_put(authed_client: Client) -> None:
    data = [
        {
            "changeState": "CHANGED",
            "trainingMethod": "HR_RESERVE",
            "lactateThresholdHeartRateUsed": 170,
            "maxHeartRateUsed": 185,
            "restingHrAutoUpdateUsed": False,
            "sport": "DEFAULT",
            "zone1Floor": 130,
            "zone2Floor": 140,
            "zone3Floor": 150,
            "zone4Floor": 160,
            "zone5Floor": 170,
        }
    ]
    path = "/biometric-service/heartRateZones"
    authed_client.put(
        "connectapi",
        path,
        api=True,
        json=data,
    )
-   assert authed_client.connectapi(path)
+   pytest.assume(authed_client.connectapi(path))
Tools
Ruff

195-195: Use of assert detected

(S101)


199-199: Missing return type annotation for public function test_put

Add return type annotation: None

(ANN201)

garth/http.py (1)

Line range hint 184-188: Add type annotations and handle file paths more robustly.

Add type annotations for the method parameters and ensure file paths are handled correctly.

def upload(
-    self, fp: IO[bytes], /, path: str = "/upload-service/upload"
+    self, fp: IO[bytes], /, path: str = "/upload-service/upload"
) -> Optional[Dict[str, Any]]:
    fname = os.path.basename(fp.name)
    files = {"file": (fname, fp)}
    return self.connectapi(
        path,
        method="POST",
        files=files,
    )
Tools
Ruff

183-183: Missing type annotation for self in method

(ANN101)


183-183: Trailing comma missing

Add trailing comma

(COM812)

Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 87abab3 and 4546623.

Files ignored due to path filters (1)
  • tests/stats/cassettes/test_daily_hydration.yaml is excluded by !tests/**/cassettes/**
Files selected for processing (18)
  • .coderabbit.yaml (1 hunks)
  • garth/init.py (2 hunks)
  • garth/http.py (1 hunks)
  • garth/stats/init.py (2 hunks)
  • garth/stats/_base.py (3 hunks)
  • garth/stats/hydration.py (1 hunks)
  • garth/version.py (1 hunks)
  • tests/data/test_hrv_data.py (2 hunks)
  • tests/data/test_sleep_data.py (2 hunks)
  • tests/stats/test_hrv.py (3 hunks)
  • tests/stats/test_hydration.py (1 hunks)
  • tests/stats/test_intensity_minutes.py (2 hunks)
  • tests/stats/test_sleep_stats.py (1 hunks)
  • tests/stats/test_steps.py (2 hunks)
  • tests/stats/test_stress.py (4 hunks)
  • tests/test_http.py (7 hunks)
  • tests/test_sso.py (4 hunks)
  • tests/test_users.py (1 hunks)
Additional context used
Path-based instructions (11)
tests/stats/test_sleep_stats.py (1)

Pattern tests/**: - test functions shouldn't have a return type hint

  • it's ok to use assert instead of pytest.assume()
tests/stats/test_hydration.py (1)

Pattern tests/**: - test functions shouldn't have a return type hint

  • it's ok to use assert instead of pytest.assume()
tests/test_users.py (1)

Pattern tests/**: - test functions shouldn't have a return type hint

  • it's ok to use assert instead of pytest.assume()
tests/stats/test_steps.py (1)

Pattern tests/**: - test functions shouldn't have a return type hint

  • it's ok to use assert instead of pytest.assume()
tests/data/test_hrv_data.py (1)

Pattern tests/**: - test functions shouldn't have a return type hint

  • it's ok to use assert instead of pytest.assume()
tests/data/test_sleep_data.py (1)

Pattern tests/**: - test functions shouldn't have a return type hint

  • it's ok to use assert instead of pytest.assume()
tests/stats/test_intensity_minutes.py (1)

Pattern tests/**: - test functions shouldn't have a return type hint

  • it's ok to use assert instead of pytest.assume()
tests/stats/test_hrv.py (1)

Pattern tests/**: - test functions shouldn't have a return type hint

  • it's ok to use assert instead of pytest.assume()
tests/stats/test_stress.py (1)

Pattern tests/**: - test functions shouldn't have a return type hint

  • it's ok to use assert instead of pytest.assume()
tests/test_sso.py (1)

Pattern tests/**: - test functions shouldn't have a return type hint

  • it's ok to use assert instead of pytest.assume()
tests/test_http.py (1)

Pattern tests/**: - test functions shouldn't have a return type hint

  • it's ok to use assert instead of pytest.assume()
Learnings (2)
tests/stats/test_hydration.py (1)
Learnt from: matin
PR: matin/garth#61
File: tests/stats/test_hydration.py:10-10
Timestamp: 2024-06-30T03:39:40.523Z
Learning: For pytest functions, return type annotations are considered redundant and are not necessary to include.
tests/stats/test_stress.py (1)
Learnt from: matin
PR: matin/garth#61
File: tests/stats/test_stress.py:26-26
Timestamp: 2024-06-30T03:56:29.941Z
Learning: matin prefers not to add return type hints for pytest functions and has requested guidance on configuring CodeRabbit to avoid such suggestions.
Ruff
tests/stats/test_sleep_stats.py

10-10: Missing return type annotation for public function test_daily_sleep

Add return type annotation: None

(ANN201)


14-14: Use of assert detected

(S101)


15-15: Use of assert detected

(S101)

tests/stats/test_hydration.py

10-10: Missing return type annotation for public function test_daily_hydration

Add return type annotation: None

(ANN201)


13-13: Use of assert detected

(S101)

tests/test_users.py

8-8: Missing return type annotation for public function test_user_profile

Add return type annotation: None

(ANN201)


10-10: Use of assert detected

(S101)


14-14: Missing return type annotation for public function test_user_setttings

Add return type annotation: None

(ANN201)


16-16: Use of assert detected

(S101)

tests/stats/test_steps.py

10-10: Missing return type annotation for public function test_daily_steps

Add return type annotation: None

(ANN201)


14-14: Use of assert detected

(S101)


15-15: Use of assert detected

(S101)


19-19: Missing return type annotation for public function test_weekly_steps

Add return type annotation: None

(ANN201)


23-23: Use of assert detected

(S101)


24-24: Use of assert detected

(S101)

tests/data/test_hrv_data.py

10-10: Missing return type annotation for public function test_hrv_data_get

Add return type annotation: None

(ANN201)


12-12: Use of assert detected

(S101)


13-13: Use of assert detected

(S101)


14-14: Use of assert detected

(S101)


16-16: Use of assert detected

(S101)


20-20: Missing return type annotation for public function test_hrv_data_list

Add return type annotation: None

(ANN201)


24-24: Use of assert detected

(S101)


25-25: Use of assert detected

(S101)

tests/data/test_sleep_data.py

10-10: Missing return type annotation for public function test_sleep_data_get

Add return type annotation: None

(ANN201)


12-12: Use of assert detected

(S101)


13-13: Use of assert detected

(S101)


14-14: Use of assert detected

(S101)


15-15: Use of assert detected

(S101)


19-19: Missing return type annotation for public function test_sleep_data_list

Add return type annotation: None

(ANN201)


23-23: Use of assert detected

(S101)


24-24: Use of assert detected

(S101)

tests/stats/test_intensity_minutes.py

10-10: Missing return type annotation for public function test_daily_intensity_minutes

Add return type annotation: None

(ANN201)


14-14: Use of assert detected

(S101)


15-15: Use of assert detected

(S101)


19-19: Missing return type annotation for public function test_weekly_intensity_minutes

Add return type annotation: None

(ANN201)


23-23: Use of assert detected

(S101)


24-24: Use of assert detected

(S101)

tests/stats/test_hrv.py

10-10: Missing return type annotation for public function test_daily_hrv

Add return type annotation: None

(ANN201)


14-14: Use of assert detected

(S101)


15-15: Use of assert detected

(S101)


19-19: Missing return type annotation for public function test_daily_hrv_paginate

Add return type annotation: None

(ANN201)


23-23: Use of assert detected

(S101)


24-24: Use of assert detected

(S101)


28-28: Missing return type annotation for public function test_daily_hrv_no_results

Add return type annotation: None

(ANN201)


31-31: Use of assert detected

(S101)


35-35: Missing return type annotation for public function test_daily_hrv_paginate_no_results

Add return type annotation: None

(ANN201)


39-39: Use of assert detected

(S101)

tests/stats/test_stress.py

10-10: Missing return type annotation for public function test_daily_stress

Add return type annotation: None

(ANN201)


14-14: Use of assert detected

(S101)


15-15: Use of assert detected

(S101)


19-19: Missing return type annotation for public function test_daily_stress_pagination

Add return type annotation: None

(ANN201)


23-23: Use of assert detected

(S101)


27-27: Missing return type annotation for public function test_weekly_stress

Add return type annotation: None

(ANN201)


31-31: Use of assert detected

(S101)


32-32: Use of assert detected

(S101)


36-36: Missing return type annotation for public function test_weekly_stress_pagination

Add return type annotation: None

(ANN201)


40-40: Use of assert detected

(S101)


41-41: Use of assert detected

(S101)


45-45: Missing return type annotation for public function test_weekly_stress_beyond_data

Add return type annotation: None

(ANN201)


49-49: Use of assert detected

(S101)

tests/test_sso.py

12-12: Missing return type annotation for public function test_login_email_password_fail

Add return type annotation: None

(ANN201)


18-18: Missing return type annotation for public function test_login_success

Add return type annotation: None

(ANN201)


20-20: Trailing comma missing

Add trailing comma

(COM812)


23-23: Use of assert detected

(S101)


24-24: Use of assert detected

(S101)


25-25: Use of assert detected

(S101)


26-26: Use of assert detected

(S101)


30-30: Missing return type annotation for public function test_login_success_mfa

Add return type annotation: None

(ANN201)


30-30: Missing type annotation for function argument monkeypatch

(ANN001)


31-31: Missing return type annotation for private function mock_input

Add return type annotation: str

(ANN202)


31-31: Missing type annotation for function argument _

(ANN001)


36-36: Trailing comma missing

Add trailing comma

(COM812)


39-39: Use of assert detected

(S101)


40-40: Use of assert detected

(S101)


41-41: Use of assert detected

(S101)


42-42: Use of assert detected

(S101)


46-46: Missing return type annotation for public function test_login_success_mfa_async

Add return type annotation: None

(ANN201)


46-46: Missing type annotation for function argument monkeypatch

(ANN001)


47-47: Missing return type annotation for private function mock_input

Add return type annotation: str

(ANN202)


47-47: Missing type annotation for function argument _

(ANN001)


50-50: Missing return type annotation for private function prompt_mfa

(ANN202)


61-61: Use of assert detected

(S101)


62-62: Use of assert detected

(S101)


63-63: Use of assert detected

(S101)


64-64: Use of assert detected

(S101)


67-67: Missing return type annotation for public function test_set_expirations

Add return type annotation: None

(ANN201)


69-69: Use of assert detected

(S101)


72-72: Use of assert detected

(S101)


81-81: Missing return type annotation for public function test_exchange

Add return type annotation: None

(ANN201)


82-82: Use of assert detected

(S101)


85-85: Use of assert detected

(S101)


86-86: Use of assert detected

(S101)


87-87: Use of assert detected

(S101)


88-88: Use of assert detected

(S101)


91-91: Missing return type annotation for public function test_get_csrf_token

Add return type annotation: None

(ANN201)


102-102: Use of assert detected

(S101)


105-105: Missing return type annotation for public function test_get_csrf_token_fail

Add return type annotation: None

(ANN201)


119-119: Missing return type annotation for public function test_get_title

Add return type annotation: None

(ANN201)


130-130: Use of assert detected

(S101)


133-133: Missing return type annotation for public function test_get_title_fail

Add return type annotation: None

(ANN201)

tests/test_http.py

11-11: Missing return type annotation for public function test_dump_and_load

Add return type annotation: None

(ANN201)


18-18: Use of assert detected

(S101)


19-19: Use of assert detected

(S101)


22-22: Missing return type annotation for public function test_dumps_and_loads

Add return type annotation: None

(ANN201)


26-26: Use of assert detected

(S101)


27-27: Use of assert detected

(S101)


30-30: Missing return type annotation for public function test_configure_oauth2_token

Add return type annotation: None

(ANN201)


31-31: Use of assert detected

(S101)


33-33: Use of assert detected

(S101)


36-36: Missing return type annotation for public function test_configure_domain

Add return type annotation: None

(ANN201)


37-37: Use of assert detected

(S101)


39-39: Use of assert detected

(S101)


42-42: Missing return type annotation for public function test_configure_proxies

Add return type annotation: None

(ANN201)


43-43: Use of assert detected

(S101)


46-46: Use of assert detected

(S101)


49-49: Missing return type annotation for public function test_configure_ssl_verify

Add return type annotation: None

(ANN201)


50-50: Use of assert detected

(S101)


52-52: Use of assert detected

(S101)


55-55: Missing return type annotation for public function test_configure_timeout

Add return type annotation: None

(ANN201)


56-56: Use of assert detected

(S101)


58-58: Use of assert detected

(S101)


61-61: Missing return type annotation for public function test_configure_retry

Add return type annotation: None

(ANN201)


62-62: Use of assert detected

(S101)


63-63: Use of assert detected

(S101)


65-65: Use of assert detected

(S101)


66-66: Use of assert detected

(S101)


69-69: Missing return type annotation for public function test_configure_status_forcelist

Add return type annotation: None

(ANN201)


70-70: Use of assert detected

(S101)


71-71: Use of assert detected

(S101)


76-76: Use of assert detected

(S101)


79-79: Missing return type annotation for public function test_backoff_factor

Add return type annotation: None

(ANN201)


80-80: Use of assert detected

(S101)


81-81: Use of assert detected

(S101)


86-86: Use of assert detected

(S101)


87-87: Use of assert detected

(S101)


93-93: Missing return type annotation for public function test_pool_connections

Add return type annotation: None

(ANN201)


98-98: Use of assert detected

(S101)


99-99: Use of assert detected

(S101)


101-101: Use of assert detected

(S101)


102-102: Use of assert detected

(S101)


106-106: Missing return type annotation for public function test_client_request

Add return type annotation: None

(ANN201)


108-108: Use of assert detected

(S101)


112-112: Use of assert detected

(S101)


116-116: Missing return type annotation for public function test_login_success_mfa

Add return type annotation: None

(ANN201)


116-116: Missing type annotation for function argument monkeypatch

(ANN001)


117-117: Missing return type annotation for private function mock_input

Add return type annotation: str

(ANN202)


117-117: Missing type annotation for function argument _

(ANN001)


122-122: Use of assert detected

(S101)


123-123: Use of assert detected

(S101)


125-125: Use of assert detected

(S101)


126-126: Use of assert detected

(S101)


130-130: Missing return type annotation for public function test_username

Add return type annotation: None

(ANN201)


131-131: Use of assert detected

(S101)


132-132: Use of assert detected

(S101)


133-133: Use of assert detected

(S101)


137-137: Missing return type annotation for public function test_connectapi

Add return type annotation: None

(ANN201)


139-139: Trailing comma missing

Add trailing comma

(COM812)


141-141: Use of assert detected

(S101)


142-142: Use of assert detected

(S101)


143-143: Use of assert detected

(S101)


144-144: Use of assert detected

(S101)


145-145: Use of assert detected

(S101)


155-155: Missing return type annotation for public function test_refresh_oauth2_token

Add return type annotation: None

(ANN201)


156-156: Use of assert detected

(S101)


158-158: Use of assert detected

(S101)


160-160: Use of assert detected

(S101)


161-161: Use of assert detected

(S101)


162-162: Use of assert detected

(S101)


166-166: Missing return type annotation for public function test_download

Add return type annotation: None

(ANN201)


168-168: Trailing comma missing

Add trailing comma

(COM812)


170-170: Use of assert detected

(S101)


172-172: Use of assert detected

(S101)


176-176: Missing return type annotation for public function test_upload

Add return type annotation: None

(ANN201)


180-180: Use of assert detected

(S101)


184-184: Missing return type annotation for public function test_delete

Add return type annotation: None

(ANN201)


187-187: Use of assert detected

(S101)


195-195: Use of assert detected

(S101)


199-199: Missing return type annotation for public function test_put

Add return type annotation: None

(ANN201)


213-213: Trailing comma missing

Add trailing comma

(COM812)


222-222: Use of assert detected

(S101)

garth/http.py

37-37: Missing return type annotation for special method __init__

Add return type annotation: None

(ANN204)


37-37: Missing type annotation for self in method

(ANN101)


37-37: Missing type annotation for **kwargs

(ANN003)


48-48: configure is too complex (12 > 10)

(C901)


48-48: Missing return type annotation for public function configure

Add return type annotation: None

(ANN201)


49-49: Missing type annotation for self in method

(ANN101)


99-99: Missing return type annotation for public function profile

(ANN201)


99-99: Missing type annotation for self in method

(ANN101)


102-102: Trailing comma missing

Add trailing comma

(COM812)


104-104: Use of assert detected

(S101)


108-108: Missing return type annotation for public function username

(ANN201)


108-108: Missing type annotation for self in method

(ANN101)


112-112: Missing type annotation for self in method

(ANN101)


117-117: Boolean-typed positional argument in function definition

(FBT001)


117-117: Boolean default positional argument in function definition

(FBT002)


118-118: Boolean default positional argument in function definition

(FBT002)


119-119: Do not use mutable data structures for argument defaults

Replace with None; initialize within function

(B006)


120-120: Missing type annotation for **kwargs

(ANN003)


127-127: Use of assert detected

(S101)


141-144: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


147-147: Missing type annotation for self in method

(ANN101)


147-147: Missing type annotation for *args

(ANN002)


147-147: Missing type annotation for **kwargs

(ANN003)


150-150: Missing type annotation for self in method

(ANN101)


150-150: Missing type annotation for *args

(ANN002)


150-150: Missing type annotation for **kwargs

(ANN003)


153-153: Missing type annotation for self in method

(ANN101)


153-153: Missing type annotation for *args

(ANN002)


153-153: Missing type annotation for **kwargs

(ANN003)


156-156: Missing type annotation for self in method

(ANN101)


156-156: Missing type annotation for *args

(ANN002)


156-156: Missing type annotation for **kwargs

(ANN003)


159-159: Missing return type annotation for public function login

Add return type annotation: None

(ANN201)


159-159: Missing type annotation for self in method

(ANN101)


159-159: Missing type annotation for *args

(ANN002)


159-159: Missing type annotation for **kwargs

(ANN003)


161-161: Trailing comma missing

Add trailing comma

(COM812)


164-164: Missing return type annotation for public function refresh_oauth2

Add return type annotation: None

(ANN201)


164-164: Missing type annotation for self in method

(ANN101)


165-165: Use of assert detected

(S101)


170-170: Missing return type annotation for public function connectapi

(ANN201)


170-170: Missing type annotation for self in method

(ANN101)


170-170: Missing type annotation for function argument method

(ANN001)


170-170: Missing type annotation for **kwargs

(ANN003)


172-175: Use ternary operator rv = None if resp.status_code == 204 else resp.json() instead of if-else-block

Replace if-else-block with rv = None if resp.status_code == 204 else resp.json()

(SIM108)


178-178: Missing type annotation for self in method

(ANN101)


178-178: Missing type annotation for **kwargs

(ANN003)


183-183: Missing type annotation for self in method

(ANN101)


183-183: Trailing comma missing

Add trailing comma

(COM812)


193-193: Missing return type annotation for public function dump

Add return type annotation: None

(ANN201)


193-193: Missing type annotation for self in method

(ANN101)


203-203: Missing type annotation for self in method

(ANN101)


210-210: Missing return type annotation for public function load

Add return type annotation: None

(ANN201)


210-210: Missing type annotation for self in method

(ANN101)


217-217: Trailing comma missing

Add trailing comma

(COM812)


220-220: Missing return type annotation for public function loads

Add return type annotation: None

(ANN201)


220-220: Missing type annotation for self in method

(ANN101)

Additional comments not posted (25)
garth/version.py (1)

1-1: Version update approved.

The version has been updated to "0.4.47".

tests/stats/test_sleep_stats.py (3)

9-9: Decorator change approved.

The @pytest.mark.vcr decorator now includes parentheses for consistency and best practices.


Line range hint 13-15: Avoid using assert statements in tests.

Using assert statements is not recommended in tests as it can lead to less informative error messages. Use pytest's enhanced assert statements instead.

assert daily_sleep[-1].calendar_date == end
assert len(daily_sleep) == days
Tools
Ruff

10-10: Missing return type annotation for public function test_daily_sleep

Add return type annotation: None

(ANN201)


10-10: Add return type annotation to test_daily_sleep.

Public functions should have return type annotations for clarity.

- def test_daily_sleep(authed_client: Client):
+ def test_daily_sleep(authed_client: Client) -> None:

Likely invalid or redundant comment.

Tools
Ruff

10-10: Missing return type annotation for public function test_daily_sleep

Add return type annotation: None

(ANN201)

tests/stats/test_hydration.py (3)

9-9: Decorator change approved.

The @pytest.mark.vcr decorator now includes parentheses for consistency and best practices.


13-13: Avoid using assert statements in tests.

Using assert statements is not recommended in tests as it can lead to less informative error messages. Use pytest's enhanced assert statements instead.

assert daily_hydration[-1].calendar_date == end
Tools
Ruff

13-13: Use of assert detected

(S101)


10-10: Add return type annotation to test_daily_hydration.

Public functions should have return type annotations for clarity.

- def test_daily_hydration(authed_client: Client):
+ def test_daily_hydration(authed_client: Client) -> None:

Likely invalid or redundant comment.

Tools
Ruff

10-10: Missing return type annotation for public function test_daily_hydration

Add return type annotation: None

(ANN201)

tests/test_users.py (6)

7-7: Decorator change approved.

The @pytest.mark.vcr decorator now includes parentheses for consistency and best practices.


10-10: Avoid using assert statements in tests.

Using assert statements is not recommended in tests as it can lead to less informative error messages. Use pytest's enhanced assert statements instead.

assert profile.user_name
Tools
Ruff

10-10: Use of assert detected

(S101)


13-13: Decorator change approved.

The @pytest.mark.vcr decorator now includes parentheses for consistency and best practices.


16-16: Avoid using assert statements in tests.

Using assert statements is not recommended in tests as it can lead to less informative error messages. Use pytest's enhanced assert statements instead.

assert settings.user_data
Tools
Ruff

16-16: Use of assert detected

(S101)


8-8: Add return type annotation to test_user_profile.

Public functions should have return type annotations for clarity.

- def test_user_profile(authed_client: Client):
+ def test_user_profile(authed_client: Client) -> None:

Likely invalid or redundant comment.

Tools
Ruff

8-8: Missing return type annotation for public function test_user_profile

Add return type annotation: None

(ANN201)


14-14: Add return type annotation to test_user_setttings.

Public functions should have return type annotations for clarity.

- def test_user_setttings(authed_client: Client):
+ def test_user_setttings(authed_client: Client) -> None:

Likely invalid or redundant comment.

Tools
Ruff

14-14: Missing return type annotation for public function test_user_setttings

Add return type annotation: None

(ANN201)

garth/stats/hydration.py (1)

1-16: LGTM!

The DailyHydration class is correctly defined with appropriate attributes and types.

garth/stats/__init__.py (1)

3-3: LGTM!

The DailyHydration class is correctly imported and included in the __all__ list.

tests/stats/test_steps.py (2)

18-18: Add return type annotation.

The test function test_weekly_steps is missing a return type annotation.

@pytest.mark.vcr()
def test_weekly_steps(authed_client: Client) -> None:

Likely invalid or redundant comment.


9-9: Add return type annotation.

The test function test_daily_steps is missing a return type annotation.

@pytest.mark.vcr()
def test_daily_steps(authed_client: Client) -> None:

Likely invalid or redundant comment.

tests/data/test_hrv_data.py (2)

19-19: Add return type annotation.

The test function test_hrv_data_list is missing a return type annotation.

@pytest.mark.vcr()
def test_hrv_data_list(authed_client: Client) -> None:

Likely invalid or redundant comment.


9-9: Add return type annotation.

The test function test_hrv_data_get is missing a return type annotation.

@pytest.mark.vcr()
def test_hrv_data_get(authed_client: Client) -> None:

Likely invalid or redundant comment.

.coderabbit.yaml (1)

2-22: LGTM!

The configuration settings are correctly formatted and logical.

garth/__init__.py (1)

5-5: LGTM!

The DailyHydration class is correctly added to the imports and the __all__ list.

Also applies to: 20-20

tests/stats/test_hrv.py (1)

31-31: Replace assert statements with pytest assertions.

Using assert statements is not recommended in tests. Replace them with pytest assertions for better error messages and consistency.

-    assert daily_hrv == []
+    pytest.assume(daily_hrv == [])

Likely invalid or redundant comment.

Tools
Ruff

31-31: Use of assert detected

(S101)

tests/stats/test_stress.py (1)

23-23: Replace assert statements with pytest assertions.

Using assert statements is not recommended in tests. Replace them with pytest assertions for better error messages and consistency.

-    assert len(daily_stress) == days
+    pytest.assume(len(daily_stress) == days)

Likely invalid or redundant comment.

Tools
Ruff

23-23: Use of assert detected

(S101)

tests/test_http.py (2)

129-133: Replace assert statements with pytest.assume.

Replace the assert statements with pytest.assume to adhere to best practices in pytest.

@pytest.mark.vcr()
def test_username(authed_client: Client) -> None:
-   assert authed_client._profile is None
-   assert authed_client.username
-   assert authed_client._profile
+   pytest.assume(authed_client._profile is None)
+   pytest.assume(authed_client.username)
+   pytest.assume(authed_client._profile)

Likely invalid or redundant comment.

Tools
Ruff

130-130: Missing return type annotation for public function test_username

Add return type annotation: None

(ANN201)


131-131: Use of assert detected

(S101)


132-132: Use of assert detected

(S101)


133-133: Use of assert detected

(S101)


175-180: Replace assert statements with pytest.assume.

Replace the assert statements with pytest.assume to adhere to best practices in pytest.

@pytest.mark.vcr()
def test_upload(authed_client: Client) -> None:
    fpath = "tests/12129115726_ACTIVITY.fit"
    with open(fpath, "rb") as f:
        uploaded = authed_client.upload(f)
-   assert uploaded
+   pytest.assume(uploaded)

Likely invalid or redundant comment.

Tools
Ruff

176-176: Missing return type annotation for public function test_upload

Add return type annotation: None

(ANN201)


180-180: Use of assert detected

(S101)

@@ -0,0 +1,22 @@
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json # Schema for CodeRabbit configurations
Copy link

@coderabbitai coderabbitai bot Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a description for the schema URL.

Adding a brief description for the schema URL can improve the readability of the configuration file.

# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json # Schema for CodeRabbit configurations

Would you like me to add this comment for better clarity?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matin, I've added the requested description to the .coderabbit.yaml file for better clarity.

# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json # Schema for CodeRabbit configurations

This should improve the readability of the configuration file.


Learnings added
Learnt from: matin
PR: matin/garth#61
File: .coderabbit.yaml:1-1
Timestamp: 2024-07-01T19:11:47.476Z
Learning: When updating the `.coderabbit.yaml` file, adding a brief description for the schema URL can improve readability and clarity.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@@ -32,15 +30,14 @@ def list(
page = cls.list(end, cls._page_size, client=client)
if not page:
return []
page = (
return (
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider optimizing recursive calls.

The recursive call to cls.list can be optimized to avoid deep recursion, which might lead to stack overflow for large periods. Consider using iteration instead.

def list(
    cls: Type["Stats"],
    end: Union[date, str, None] = None,
    period: int = 1,
    *,
    client: Optional[http.Client] = None,
) -> List["Stats"]:
    client = client or http.client
    end = format_end_date(end)
    period_type = "days" if "daily" in cls._path else "weeks"
    
    results = []
    while period > cls._page_size:
        page = cls.list(end, cls._page_size, client=client)
        if not page:
            return results
        results = page + results
        end -= timedelta(**{period_type: cls._page_size})
        period -= cls._page_size

    start = end - timedelta(**{period_type: period - 1})
    path = cls._path.format(start=start, end=end, period=period)
    page_dirs = client.connectapi(path)
    if not page_dirs:
        return results
    if "values" in page_dirs[0]:
        page_dirs = [{**stat, **stat.pop("values")} for stat in page_dirs]
    page_dirs = [camel_to_snake_dict(stat) for stat in page_dirs]
    return [cls(**stat) for stat in page_dirs] + results

Copy link
Owner Author

@matin matin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai full review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hydration get and set [feature request]
1 participant