From 9a9b2bd9c766add194ed114ac2e89815a8de0d13 Mon Sep 17 00:00:00 2001 From: emil Date: Mon, 13 Jul 2026 03:01:42 +0200 Subject: [PATCH] test: cover crypto.py line 37 (retry on leading dash) Mock secrets.token_urlsafe to force the '-' prefix branch. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- tests/unit/test_utils_crypto.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/unit/test_utils_crypto.py b/tests/unit/test_utils_crypto.py index 24fd9f7..b698f16 100644 --- a/tests/unit/test_utils_crypto.py +++ b/tests/unit/test_utils_crypto.py @@ -3,6 +3,7 @@ from __future__ import annotations import re +from unittest.mock import patch from devx.utils.crypto import ( _DIGITS, @@ -35,6 +36,13 @@ class TestGenerateSecret: assert "+" not in secret assert "/" not in secret + def test_retries_on_leading_dash(self) -> None: + """When token_urlsafe returns a value starting with '-', it retries.""" + # First call returns a dash-prefixed value, second returns a clean one + with patch("devx.utils.crypto.secrets.token_urlsafe", side_effect=["-bad-value", "good-value"]): + secret = generate_secret() + assert secret == "good-value" + class TestGeneratePassword: def test_default_length(self) -> None: -- 2.54.0