style: Fix linter formatting in analytics module

This commit is contained in:
Paul Gauthier (aider) 2024-11-20 17:54:22 -08:00
parent 82187f6a71
commit 95c9863d0a
2 changed files with 9 additions and 9 deletions

View file

@ -83,20 +83,20 @@ class Analytics:
def is_uuid_in_percentage(self, uuid_str, percent):
"""Check if a UUID string falls within the first X percent of the UUID space.
Args:
uuid_str: UUID string to test
percent: Percentage threshold (0-100)
Returns:
bool: True if UUID falls within the first X percent
"""
if not (0 <= percent <= 100):
raise ValueError("Percentage must be between 0 and 100")
if not uuid_str:
return False
# Convert percentage to hex threshold (1% = "03", 10% = "1a", etc)
threshold = format(int(256 * percent / 100), "02x")
return uuid_str < threshold

View file

@ -109,29 +109,29 @@ def test_need_to_ask(temp_data_dir):
def test_is_uuid_in_percentage():
analytics = Analytics()
# Test basic percentage thresholds
assert analytics.is_uuid_in_percentage("00", 1) is True
assert analytics.is_uuid_in_percentage("02", 1) is True
assert analytics.is_uuid_in_percentage("03", 1) is False
assert analytics.is_uuid_in_percentage("ff", 1) is False
assert analytics.is_uuid_in_percentage("00", 10) is True
assert analytics.is_uuid_in_percentage("19", 10) is True
assert analytics.is_uuid_in_percentage("1a", 10) is False
assert analytics.is_uuid_in_percentage("ff", 10) is False
# Test edge cases
assert analytics.is_uuid_in_percentage("00", 0) is False
assert analytics.is_uuid_in_percentage("00", 100) is True
assert analytics.is_uuid_in_percentage("ff", 100) is True
# Test invalid inputs
with pytest.raises(ValueError):
analytics.is_uuid_in_percentage("00", -1)
with pytest.raises(ValueError):
analytics.is_uuid_in_percentage("00", 101)
# Test empty/None UUID
assert analytics.is_uuid_in_percentage("", 50) is False
assert analytics.is_uuid_in_percentage(None, 50) is False