Skip to content

Commit

Permalink
fix: update check test
Browse files Browse the repository at this point in the history
Flaky test failing once a year
  • Loading branch information
akshayka committed Jan 2, 2025
1 parent 3bf9807 commit f8a9781
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 8 additions & 5 deletions marimo/_cli/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _check_for_updates_internal(on_update: Callable[[str, str], None]) -> None:
def _update_with_latest_version(state: MarimoCLIState) -> MarimoCLIState:
"""
If we have not saved the latest version,
or its newer than the one we have, update it.
or it's newer than the one we have, update it.
"""
# querying pypi is +250kb and there is not a better API
# this endpoint just returns the version
Expand All @@ -84,15 +84,18 @@ def _update_with_latest_version(state: MarimoCLIState) -> MarimoCLIState:
else:
api_url = "https://marimo.io/api/oss/latest-version"

# Check if it is a different day
# We only update the state once a day
if state.last_checked_at:
last_checked_date = datetime.strptime(
state.last_checked_at, "%Y-%m-%d"
).date()
now = datetime.now()
year = last_checked_date.timetuple().tm_year
today_year = now.timetuple().tm_year
day_of_the_year = last_checked_date.timetuple().tm_yday
today_day_of_the_year = datetime.now().timetuple().tm_yday
if today_day_of_the_year == day_of_the_year:
# Same day of the year, so do nothing
today_day_of_the_year = now.timetuple().tm_yday
if year == today_year and today_day_of_the_year == day_of_the_year:
# Same day, so do nothing
return state

# Fetch the latest version from PyPI
Expand Down
1 change: 0 additions & 1 deletion tests/_cli/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def test_update_with_latest_version(mock_fetch_data_from_url: Any) -> None:
)
mock_fetch_data_from_url.return_value = {"info": {"version": "0.1.2"}}

# Run
updated_state = _update_with_latest_version(state)

# Assert that the latest_version was updated
Expand Down

0 comments on commit f8a9781

Please sign in to comment.