From 950a69493f6906458d70e8a417036a4fa32620d1 Mon Sep 17 00:00:00 2001 From: Patryk Szulczyk Date: Fri, 7 Jul 2023 09:05:48 +0200 Subject: [PATCH] Use timezone-aware reset datetime in GithubRetry.py (#2610) Co-authored-by: Patryk Szulczyk Co-authored-by: Enrico Minack --- github/GithubRetry.py | 4 ++-- tests/GithubRetry.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/github/GithubRetry.py b/github/GithubRetry.py index 7f42c8bf..6ae0eb25 100644 --- a/github/GithubRetry.py +++ b/github/GithubRetry.py @@ -137,8 +137,8 @@ class GithubRetry(Retry): if "X-RateLimit-Reset" in response.headers: value = response.headers.get("X-RateLimit-Reset") if value and value.isdigit(): - reset = self.__datetime.utcfromtimestamp( - int(value) + reset = self.__datetime.fromtimestamp( + int(value), timezone.utc ) delta = reset - self.__datetime.now( timezone.utc diff --git a/tests/GithubRetry.py b/tests/GithubRetry.py index 96fb9488..cf67388c 100644 --- a/tests/GithubRetry.py +++ b/tests/GithubRetry.py @@ -95,7 +95,7 @@ class GithubRetry(unittest.TestCase): mock.call(20, "Request TEST URL failed with 403: None"), mock.call(10, f"Response body indicates retry-able {'primary' if is_primary else 'secondary'} rate limit error: {expected_rate_limit_error}"), ] + ([ - mock.call(10, "Reset occurs in 0:00:12 (1644768012 / 2022-02-13 16:00:12)") + mock.call(10, "Reset occurs in 0:00:12 (1644768012 / 2022-02-13 16:00:12+00:00)") ] if has_reset else []) + ([ mock.call(10, f"Retry backoff of {expected_retry_backoff}s exceeds required rate limit backoff of {expected_backoff}s") ] if expected_retry_backoff and expected_backoff > 0 else []) + ([ @@ -132,8 +132,8 @@ class GithubRetry(unittest.TestCase): else: attr = "github.GithubRetry._GithubRetry__datetime" with mock.patch(attr) as dt: - dt.now = mock.Mock(return_value=datetime.utcfromtimestamp(now)) - dt.utcfromtimestamp = datetime.utcfromtimestamp + dt.now = lambda tz=None: datetime.fromtimestamp(now, tz=tz) + dt.fromtimestamp = datetime.fromtimestamp yield def test_primary_rate_error_with_reset(self):