Skip to content

Commit 0fcb211

Browse files
committed
end of day commit before i lose my marbles entirely
1 parent 6596567 commit 0fcb211

File tree

7 files changed

+69
-6
lines changed

7 files changed

+69
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ coverage.xml
5050
.hypothesis/
5151
.pytest_cache/
5252
cover/
53+
coverage_html_report/
5354

5455
# Translations
5556
*.mo

pyproject.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,29 @@ dev = [
2525
"pyright",
2626
"ruff",
2727
"pytest",
28+
"pytest-cov"
2829
]
2930

31+
[tool.coverage.run]
32+
branch = true
33+
source = ["src"]
34+
35+
[tool.coverage.report]
36+
fail_under = 100
37+
exclude_lines = [
38+
"pragma: no cover",
39+
"if TYPE_CHECKING:",
40+
"if typing.TYPE_CHECKING:",
41+
"@abstractmethod",
42+
]
43+
omit = ["main.py"]
44+
45+
46+
[tool.coverage.html]
47+
directory = "coverage_html_report"
48+
49+
[tool.pytest.ini_options]
50+
testpaths = "tests"
51+
addopts = "--cov --cov-report=html -vv"
52+
3053
[tool.setuptools_scm]

src/saluki/consume.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ def consume(
3939

4040
if go_forwards:
4141
if offset is None:
42-
logger.error("Can't go forwards without an offset")
43-
return
42+
raise ValueError("Can't go forwards without an offset")
4443
start = offset
4544
else:
4645
if offset is not None:

src/saluki/listen.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ def listen(broker: str, topic: str, partition: int | None = None) -> None:
3232
_deserialise_and_print_messages([msg], partition)
3333
except KeyboardInterrupt:
3434
logger.debug("finished listening")
35-
except Exception:
36-
logger.exception("Got exception while listening:")
3735
finally:
3836
logger.debug(f"closing consumer {c}")
3937
c.close()

tests/test_consume.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
# test that tries go_forwards with no offset
1+
from unittest.mock import patch
2+
3+
import pytest
4+
5+
from saluki.consume import consume
6+
7+
@patch("saluki.consume.Consumer")
8+
def test_go_forwards_with_no_offset_raises(_):
9+
with pytest.raises(ValueError):
10+
consume("broker", "topic", go_forwards=True, offset=None)
211

312
# test that tries going forwards that consumes from offset
413

514
# test that checks start offset
615

7-
# test that catches exception
16+
# test that catches exception

tests/test_listen.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from unittest.mock import MagicMock
2+
3+
from confluent_kafka import TopicPartition
4+
5+
from saluki.listen import listen
6+
from unittest import mock
7+
8+
def test_listen_with_partition_assigns_to_partition():
9+
expected_partition = 123
10+
topic = "sometopic"
11+
with (
12+
mock.patch(
13+
"saluki.listen._deserialise_and_print_messages",
14+
side_effect=KeyboardInterrupt,
15+
),
16+
mock.patch("saluki.listen.Consumer") as c,
17+
):
18+
listen("somebroker", "sometopic", partition=expected_partition)
19+
assert c.return_value.assign.call_args[0][0][0].topic == topic
20+
assert c.return_value.assign.call_args[0][0][0].partition == expected_partition
21+
22+
23+
def test_keyboard_interrupt_causes_consumer_to_close():
24+
with (
25+
mock.patch(
26+
"saluki.listen._deserialise_and_print_messages",
27+
side_effect=KeyboardInterrupt,
28+
),
29+
mock.patch("saluki.listen.Consumer") as c,
30+
):
31+
listen("somebroker", "sometopic")
32+
c.return_value.close.assert_called_once()

tests/test_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
# test _parse_timestamp
1515

16+
1617
def test_uri_with_broker_name_and_topic_successfully_split():
1718
test_broker = "localhost"
1819
test_topic = "some_topic"

0 commit comments

Comments
 (0)