From d16c80d4991d8f0473720eac5b26dc6e805318d9 Mon Sep 17 00:00:00 2001 From: Nicolas Simonds Date: Tue, 27 Feb 2024 17:09:50 -0800 Subject: [PATCH 1/4] chore: add modern Python runtimes to the test matrix --- .github/workflows/tests.yml | 2 +- setup.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8b468d7..34b0753 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "pypy3.10"] services: redis: diff --git a/setup.py b/setup.py index 321aa29..4b4afff 100644 --- a/setup.py +++ b/setup.py @@ -37,6 +37,8 @@ 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', ], keywords='task queue jobs redis', From 95b860cce4bb29768fe99844e34cb7c0c3ecf9e8 Mon Sep 17 00:00:00 2001 From: Nicolas Simonds Date: Tue, 27 Feb 2024 16:18:22 -0800 Subject: [PATCH 2/4] fix: update utils.exponential_backoff to broker in ints only Python 3.12 finally made good on their promise to start throwing errors when trying to use `random` with non-ints, so make a good-faith effort to do that in all versions. Remove a now-useless test for passing floats that should now be impossible to hit. Partial fix for Issue #29 --- spinach/utils.py | 4 ++-- tests/test_utils.py | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/spinach/utils.py b/spinach/utils.py index 625cbd2..2056469 100644 --- a/spinach/utils.py +++ b/spinach/utils.py @@ -74,8 +74,8 @@ def exponential_backoff(attempt: int, cap: int=1200) -> timedelta: :arg cap: maximum delay, defaults to 20 minutes """ base = 3 - temp = min(base * 2 ** attempt, cap) - return timedelta(seconds=temp / 2 + random.randint(0, temp / 2)) + temp = min(base * 2 ** attempt, cap) // 2 + return timedelta(seconds=temp + random.randint(0, temp)) @contextlib.contextmanager diff --git a/tests/test_utils.py b/tests/test_utils.py index 0c0920b..f403305 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -65,9 +65,6 @@ def func(): def test_exponential_backoff(): - with pytest.raises(ValueError): - utils.exponential_backoff(0) - assert ( timedelta(seconds=3) <= utils.exponential_backoff(1) <= timedelta(seconds=6) From 186b95c761846db47ece1807b5beb42cce89938d Mon Sep 17 00:00:00 2001 From: Nicolas Simonds Date: Tue, 27 Feb 2024 17:24:38 -0800 Subject: [PATCH 3/4] fix: use actual Mock objects for test setup Newer Python runtimes do more stringent method signature checking, so use an actual Mock for dummy tasks rather than a "random" callable Partial fix for Issue #29 --- tests/test_engine.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_engine.py b/tests/test_engine.py index e5d6b47..952d6e2 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -49,7 +49,7 @@ def test_schedule_at(patch_now): now = get_now() tasks = Tasks() - tasks.add(print, 'bar_task') + tasks.add(Mock(), 'bar_task') broker = Mock() @@ -91,8 +91,8 @@ def test_schedule_batch(patch_now): now = get_now() tasks = Tasks() - tasks.add(print, 'foo_task') - tasks.add(print, 'bar_task') + tasks.add(Mock(), 'foo_task') + tasks.add(Mock(), 'bar_task') broker = Mock() From f864a1d37af425029fc213a417e1301f0538d0b8 Mon Sep 17 00:00:00 2001 From: Nicolas Simonds Date: Tue, 27 Feb 2024 17:32:24 -0800 Subject: [PATCH 4/4] fix: fix busted test method It's `assert_called_once()`, not `called_once()`. Also, never use that; always call `assert_called_once_with()` --- tests/test_brokers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_brokers.py b/tests/test_brokers.py index 6046f3a..5d70f69 100644 --- a/tests/test_brokers.py +++ b/tests/test_brokers.py @@ -67,7 +67,7 @@ def test_wait_for_events_no_future_job(broker): mock_sh.wait.return_value = True broker.wait_for_event() - mock_sh.clear.called_once() + mock_sh.clear.assert_called_once_with() @pytest.mark.parametrize('delta,timeout', [