Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Fix some more untyped tests #4373

Merged
merged 2 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ api-tests:
SNUBA_SETTINGS=test pytest -vv tests/*_api.py

backend-typing:
mypy snuba tests scripts --strict --config-file mypy.ini --exclude 'tests/datasets|tests/query|tests/state|tests/snapshots|tests/clickhouse|tests/test_split.py'
mypy snuba tests scripts --strict --config-file mypy.ini --exclude 'tests/datasets|tests/query|tests/snapshots|tests/clickhouse|tests/test_split.py'

install-python-dependencies:
pip uninstall -qqy uwsgi # pip doesn't do well with swapping drop-ins
Expand Down
13 changes: 8 additions & 5 deletions tests/state/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
from snuba.state.cache.abstract import Cache, ExecutionError, ExecutionTimeoutError
from snuba.state.cache.redis.backend import RedisCache
from snuba.utils.codecs import ExceptionAwareCodec
from snuba.utils.serializable_exception import SerializableException
from snuba.utils.serializable_exception import (
SerializableException,
SerializableExceptionDict,
)
from tests.assertions import assert_changes, assert_does_not_change

redis_client = get_redis_client(RedisClientKey.CACHE)
Expand Down Expand Up @@ -44,7 +47,7 @@ def encode(self, value: bytes) -> bytes:

def decode(self, value: bytes) -> bytes:
try:
ret = rapidjson.loads(value)
ret: SerializableExceptionDict = rapidjson.loads(value)
if not isinstance(ret, dict):
return value
if ret.get("__type__", "NOP") == "SerializableException":
Expand All @@ -55,7 +58,7 @@ def decode(self, value: bytes) -> bytes:
return value

def encode_exception(self, value: SerializableException) -> bytes:
return rapidjson.dumps(value.to_dict()).encode("utf-8")
return bytes(rapidjson.dumps(value.to_dict()).encode("utf-8"))


@pytest.fixture
Expand Down Expand Up @@ -260,10 +263,10 @@ def test_notify_queue_ttl() -> None:
num_waiters = 9

class DelayedRedisClient:
def __init__(self, redis_client):
def __init__(self, redis_client: RedisClientType) -> None:
self._client = redis_client

def __getattr__(self, attr: str):
def __getattr__(self, attr: str) -> Any:
# simulate the queue pop taking longer than expected.
# the notification queue TTL is 60 seconds so running into a timeout
# shouldn't happen (unless something has drastically changed in the TTL
Expand Down
2 changes: 1 addition & 1 deletion tests/state/test_record.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from snuba.state import _kafka_producer


def test_get_producer():
def test_get_producer() -> None:
assert _kafka_producer() is not None
Loading