Skip to content

Commit

Permalink
Merge pull request #249 from kpn/fix/bump-deps
Browse files Browse the repository at this point in the history
fix: bump deps
  • Loading branch information
woile authored Nov 27, 2024
2 parents 8afd127 + 72de291 commit a7055c5
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 140 deletions.
187 changes: 94 additions & 93 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ pytest-benchmark = "^5.1.0"
pytest-cov = "^6"
pytest-httpserver = "^1.1.0"
mypy = "^1.11.2"
ruff = ">=0.6.9,<0.8.0"
ruff = "^0.8"
aiorun = "^2024.5.1"
jedi = "^0.19.1"
mkdocs = "^1.1.2"
uvicorn = "<1.0"
commitizen = "^3.29.1"
commitizen = "^4"
fastapi = "^0.115.0"
mkdocs-material = "^9.5.39"
starlette-prometheus = "^0.10.0"
Expand Down
8 changes: 5 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ async def stream_engine():

@pytest.fixture
def ssl_data():
with open("tests/fixtures/ssl/cabundle.pem") as cabundle, open(
"tests/fixtures/ssl/certificate.pem"
) as cert, open("tests/fixtures/ssl/certificate.key") as key:
with (
open("tests/fixtures/ssl/cabundle.pem") as cabundle,
open("tests/fixtures/ssl/certificate.pem") as cert,
open("tests/fixtures/ssl/certificate.key") as key,
):
return SSLData(cabundle.read(), cert.read(), key.read())


Expand Down
31 changes: 18 additions & 13 deletions tests/test_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ async def on_partitions_assigned(

rebalance_listener = MyRebalanceListener()

with mock.patch.multiple(
Consumer, start=mock.DEFAULT, unsubscribe=mock.DEFAULT
), mock.patch("kstreams.clients.aiokafka.AIOKafkaProducer.start"):
with (
mock.patch.multiple(Consumer, start=mock.DEFAULT, unsubscribe=mock.DEFAULT),
mock.patch("kstreams.clients.aiokafka.AIOKafkaProducer.start"),
):

@stream_engine.stream(
topic,
Expand Down Expand Up @@ -103,13 +104,14 @@ async def test_stream_with_default_rebalance_listener():
topic = "local--hello-kpn"
topic_partitions = set(TopicPartition(topic=topic, partition=0))

with mock.patch.multiple(
Consumer, start=mock.DEFAULT, unsubscribe=mock.DEFAULT
), mock.patch("kstreams.clients.aiokafka.AIOKafkaProducer.start"), mock.patch(
"kstreams.PrometheusMonitor.start"
) as monitor_start, mock.patch(
"kstreams.PrometheusMonitor.clean_stream_consumer_metrics"
) as clean_stream_metrics:
with (
mock.patch.multiple(Consumer, start=mock.DEFAULT, unsubscribe=mock.DEFAULT),
mock.patch("kstreams.clients.aiokafka.AIOKafkaProducer.start"),
mock.patch("kstreams.PrometheusMonitor.start") as monitor_start,
mock.patch(
"kstreams.PrometheusMonitor.clean_stream_consumer_metrics"
) as clean_stream_metrics,
):
# use this function so we can mock PrometheusMonitor
stream_engine = create_engine()

Expand Down Expand Up @@ -150,9 +152,12 @@ async def test_stream_manual_commit_rebalance_listener(stream_engine: StreamEngi
topic = "local--hello-kpn"
topic_partitions = set(TopicPartition(topic=topic, partition=0))

with mock.patch.multiple(
Consumer, start=mock.DEFAULT, commit=mock.DEFAULT, unsubscribe=mock.DEFAULT
), mock.patch("kstreams.clients.aiokafka.AIOKafkaProducer.start"):
with (
mock.patch.multiple(
Consumer, start=mock.DEFAULT, commit=mock.DEFAULT, unsubscribe=mock.DEFAULT
),
mock.patch("kstreams.clients.aiokafka.AIOKafkaProducer.start"),
):

@stream_engine.stream(
topic,
Expand Down
52 changes: 32 additions & 20 deletions tests/test_engine_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ async def test_hook_on_startup(stream_engine: StreamEngine, consumer_record_fact
on_startup_sync_mock = mock.Mock()
on_startup_async_mock = mock.AsyncMock()

with mock.patch.multiple(
Consumer,
start=mock.DEFAULT,
stop=mock.DEFAULT,
), mock.patch.multiple(Producer, start=mock.DEFAULT, stop=mock.DEFAULT):
with (
mock.patch.multiple(
Consumer,
start=mock.DEFAULT,
stop=mock.DEFAULT,
),
mock.patch.multiple(Producer, start=mock.DEFAULT, stop=mock.DEFAULT),
):
assert stream_engine._on_startup == []

@stream_engine.stream("local--kstreams")
Expand Down Expand Up @@ -57,11 +60,14 @@ async def test_hook_after_startup(stream_engine: StreamEngine, consumer_record_f
after_startup_async_mock = mock.AsyncMock()
set_healthy_pod = mock.AsyncMock()

with mock.patch.multiple(
Consumer,
start=mock.DEFAULT,
stop=mock.DEFAULT,
), mock.patch.multiple(Producer, start=mock.DEFAULT, stop=mock.DEFAULT):
with (
mock.patch.multiple(
Consumer,
start=mock.DEFAULT,
stop=mock.DEFAULT,
),
mock.patch.multiple(Producer, start=mock.DEFAULT, stop=mock.DEFAULT),
):
assert stream_engine._after_startup == []

@stream_engine.stream("local--kstreams")
Expand Down Expand Up @@ -103,11 +109,14 @@ async def test_hook_on_stop(stream_engine: StreamEngine, consumer_record_factory
close_db_mock = mock.Mock()
backgound_task_mock = mock.AsyncMock()

with mock.patch.multiple(
Consumer,
start=mock.DEFAULT,
stop=mock.DEFAULT,
), mock.patch.multiple(Producer, start=mock.DEFAULT, stop=mock.DEFAULT):
with (
mock.patch.multiple(
Consumer,
start=mock.DEFAULT,
stop=mock.DEFAULT,
),
mock.patch.multiple(Producer, start=mock.DEFAULT, stop=mock.DEFAULT),
):
assert stream_engine._on_stop == []

@stream_engine.stream("local--kstreams")
Expand Down Expand Up @@ -149,11 +158,14 @@ async def stop_backgound_task():
async def test_hook_after_stop(stream_engine: StreamEngine, consumer_record_factory):
delete_files_mock = mock.AsyncMock()

with mock.patch.multiple(
Consumer,
start=mock.DEFAULT,
stop=mock.DEFAULT,
), mock.patch.multiple(Producer, start=mock.DEFAULT, stop=mock.DEFAULT):
with (
mock.patch.multiple(
Consumer,
start=mock.DEFAULT,
stop=mock.DEFAULT,
),
mock.patch.multiple(Producer, start=mock.DEFAULT, stop=mock.DEFAULT),
):
assert stream_engine._after_stop == []

@stream_engine.stream("local--kstreams")
Expand Down
15 changes: 9 additions & 6 deletions tests/test_stream_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,15 @@ async def stream(cr: ConsumerRecord):
await asyncio.sleep(5)
await save_to_db(cr.value)

with mock.patch.multiple(
Consumer,
start=mock.DEFAULT,
stop=mock.DEFAULT,
getone=getone,
), mock.patch.multiple(Producer, start=mock.DEFAULT, stop=mock.DEFAULT):
with (
mock.patch.multiple(
Consumer,
start=mock.DEFAULT,
stop=mock.DEFAULT,
getone=getone,
),
mock.patch.multiple(Producer, start=mock.DEFAULT, stop=mock.DEFAULT),
):
await stream_engine.start()
await asyncio.sleep(0) # Allow stream coroutine to run once

Expand Down
7 changes: 4 additions & 3 deletions tests/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,10 @@ async def test_stream_custom_conf(stream_engine: StreamEngine):
)
async def stream(_): ...

with mock.patch.multiple(
Consumer, start=mock.DEFAULT, stop=mock.DEFAULT
), mock.patch.multiple(Producer, start=mock.DEFAULT, stop=mock.DEFAULT):
with (
mock.patch.multiple(Consumer, start=mock.DEFAULT, stop=mock.DEFAULT),
mock.patch.multiple(Producer, start=mock.DEFAULT, stop=mock.DEFAULT),
):
await stream_engine.start_streams()

# switch the current Task to the one running in background
Expand Down

0 comments on commit a7055c5

Please sign in to comment.