Files
trailofbits-buttercup/common/tests/test_map.py
T
Dan Guido 42691e50b4 style: apply ruff auto-fixes and formatting across entire codebase (#309)
* style: apply ruff auto-fixes and formatting across entire codebase

Applied safe auto-fixes from ruff v0.12.9 with --select ALL to improve code quality:
- Reorder imports (stdlib → third-party → local)
- Use modern type hints (collections.abc.Generator instead of typing.Generator)
- Add trailing commas for better diffs
- Format multi-line function parameters for readability
- Add strict=False to zip() calls for explicit behavior
- Simplify redundant elif to if after return statements
- Consistent code formatting with ruff format

These are all mechanical, non-controversial changes that improve code consistency
without altering functionality. Changes affect 180 files across all modules:
common, fuzzer, orchestrator, patcher, program-model, and seed-gen.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* re-applt ruff after merge

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Michael D Brown <michael.brown@trailofbits.com>
2025-08-22 10:30:12 -04:00

71 lines
2.1 KiB
Python

import pytest
from redis import Redis
from buttercup.common.datastructures.msg_pb2 import WeightedHarness
from buttercup.common.maps import RedisMap
@pytest.fixture
def redis_client():
return Redis(host="localhost", port=6379, db=0)
def test_redis_map_set_and_get(redis_client):
# Create a RedisMap instance
redis_map = RedisMap(redis_client, "test_hash", WeightedHarness)
# Create a WeightedHarness
harness = WeightedHarness()
harness.package_name = "test_package"
harness.harness_name = "test_harness"
harness.task_id = "test_task_id"
harness.weight = 1.0
# Set the target with a key
test_key = "test_key"
redis_map.set(test_key, harness)
# Retrieve the target
retrieved_target = redis_map.get(test_key)
# Verify the retrieved target matches the original
assert retrieved_target.package_name == harness.package_name
assert retrieved_target.harness_name == harness.harness_name
assert retrieved_target.task_id == harness.task_id
assert retrieved_target.weight == harness.weight
# Clean up
redis_client.delete("test_hash")
def test_redis_map_iteration(redis_client):
# Create a RedisMap instance
redis_map = RedisMap(redis_client, "test_hash_iter", WeightedHarness)
# Create a WeightedHarness
harness = WeightedHarness()
harness.package_name = "test_package"
harness.harness_name = "test_harness"
harness.task_id = "test_task_id"
harness.weight = 1.0
# Set the target with a key
test_key = "test_key"
redis_map.set(test_key, harness)
# Iterate over the map and collect results
harnesses = list(redis_map)
# Verify we got exactly one harness
assert len(harnesses) == 1
# Verify the iterated target matches the original
retrieved_harness = harnesses[0]
assert retrieved_harness.package_name == harness.package_name
assert retrieved_harness.harness_name == harness.harness_name
assert retrieved_harness.task_id == harness.task_id
assert retrieved_harness.weight == harness.weight
# Clean up
redis_client.delete("test_hash_iter")