Skip to content

Commit

Permalink
Merge pull request #54 from jklynch/fix-tests
Browse files Browse the repository at this point in the history
De-dent unchecked assertions in pytest.raises blocks
  • Loading branch information
mrakitin authored Feb 22, 2023
2 parents 9b5efd6 + dad612a commit 5b692e3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 47 deletions.
1 change: 0 additions & 1 deletion bluesky_kafka/produce.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def __init__(
raise ValueError(
"do not specify 'bootstrap.servers' in producer_config dictionary, "
"use only the 'bootstrap_servers' parameter"
f"\n{self}"
)
else:
self._producer_config["bootstrap.servers"] = ",".join(bootstrap_servers)
Expand Down
43 changes: 20 additions & 23 deletions bluesky_kafka/tests/test_basic_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"bootstrap_servers, consumer_config_bootstrap_servers",
[
([], ""),
(["1.2.3.4:9092"], "1.2.3.4:9092"),
(["1.2.3.4:9092", "localhost:9092"], "1.2.3.4:9092,localhost:9092"),
(["localhost:9092"], "localhost:9092"),
(["localhost:9091", "localhost:9092"], "localhost:9091,localhost:9092"),
],
)
def test_bootstrap_servers(bootstrap_servers, consumer_config_bootstrap_servers):
Expand Down Expand Up @@ -42,49 +42,46 @@ def test_bootstrap_servers_in_consumer_config():
consumer_config={"bootstrap.servers": ""},
)

assert (
"do not specify 'bootstrap.servers' in consumer_config dictionary, "
"use only the 'bootstrap_servers' parameter" in excinfo.value
)
assert (
"do not specify 'bootstrap.servers' in consumer_config dictionary, "
"use only the 'bootstrap_servers' parameter" in str(excinfo.value)
)


def test_bootstrap_servers_not_list():
with pytest.raises(TypeError) as excinfo:
BasicConsumer(
topics=["abc"],
bootstrap_servers="1.2.3.4:9092",
bootstrap_servers="localhost:9092",
group_id="abc",
consumer_config={},
)
assert (
"parameter `bootstrap_servers` must be a sequence of str, not str"
in excinfo.value
)
assert "parameter `bootstrap_servers` must be a sequence of str, not str" in str(
excinfo.value
)


def test_bad_consumer_config():
with pytest.raises(ValueError) as excinfo:
BasicConsumer(
topics=["abc"],
bootstrap_servers=["1.2.3.4:9092"],
bootstrap_servers=["localhost:9092"],
group_id="abc",
consumer_config={
"bootstrap.servers": "5.6.7.8:9092",
"auto.offset.reset": "latest",
"group.id": "raise an exception!",
},
)
assert (
"do not specify 'group.id' in consumer_config, use only the 'group_id' argument"
in excinfo.value
)
assert (
"do not specify 'group.id' in consumer_config, use only the 'group_id' parameter"
in str(excinfo.value)
)


def test_redact_password_from_str():
basic_consumer = BasicConsumer(
topics=["abc"],
bootstrap_servers=["localhost:9091", "localhost:9092"],
group_id="abc",
group_id="def",
consumer_config={
"sasl.password": "PASSWORD",
},
Expand All @@ -94,8 +91,8 @@ def test_redact_password_from_str():
"<class 'bluesky_kafka.consume.BasicConsumer'>("
"topics=['abc'], "
"consumer_config={"
"'sasl.password': '****', "
"'group.id': 'abc', "
"'bootstrap.servers': 'localhost:9091,localhost:9092'}"
"'sasl.password': '****', "
"'group.id': 'def', "
"'bootstrap.servers': 'localhost:9091,localhost:9092'}"
")"
)
)
21 changes: 10 additions & 11 deletions bluesky_kafka/tests/test_basic_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"bootstrap_servers, producer_config, combined_bootstrap_servers",
[
([], {}, ""),
(["1.2.3.4:9092"], {}, "1.2.3.4:9092"),
(["1.2.3.4:9092", "localhost:9092"], {}, "1.2.3.4:9092,localhost:9092"),
(["localhost:9092"], {}, "localhost:9092"),
(["localhost:9091", "localhost:9092"], {}, "localhost:9091,localhost:9092"),
],
)
def test_bootstrap_servers(
Expand Down Expand Up @@ -45,10 +45,10 @@ def test_bootstrap_servers_in_producer_config():
producer_config={"bootstrap.servers": ""},
)

assert (
"do not specify 'bootstrap.servers' in producer_config dictionary, "
"use only the 'bootstrap_servers' parameter" in excinfo.value
)
assert (
"do not specify 'bootstrap.servers' in producer_config dictionary, "
"use only the 'bootstrap_servers' parameter" in str(excinfo.value)
)


def test_bad_bootstrap_servers():
Expand All @@ -62,10 +62,9 @@ def test_bad_bootstrap_servers():
"bootstrap.servers": "localhost:9092",
},
)
assert (
"parameter `bootstrap_servers` must be a sequence of str, not str"
in excinfo.value
)
assert "parameter `bootstrap_servers` must be a sequence of str, not str" in str(
excinfo.value
)


def test_redact_password_from_str_output():
Expand All @@ -88,4 +87,4 @@ def test_redact_password_from_str_output():
"bootstrap_servers=['localhost:9091', 'localhost:9092'], "
"producer_config={'sasl.password': '****', 'bootstrap.servers': 'localhost:9091,localhost:9092'}"
")"
)
)
20 changes: 9 additions & 11 deletions bluesky_kafka/tests/test_bluesky_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ def test_consumer_config():
test_topic = "test.consumer.config"
bluesky_consumer = BlueskyConsumer(
topics=[test_topic],
bootstrap_servers="1.2.3.4:9092",
bootstrap_servers="localhost:9091",
group_id="abc",
consumer_config={
"bootstrap.servers": "5.6.7.8:9092",
"bootstrap.servers": "localhost:9092",
"auto.offset.reset": "latest",
},
)

assert (
bluesky_consumer._consumer_config["bootstrap.servers"]
== "1.2.3.4:9092,5.6.7.8:9092"
== "localhost:9091,localhost:9092"
)


def test_redact_password_from_str_output():
bluesky_consumer = BlueskyConsumer(
topics=["test.redact.password"],
bootstrap_servers="1.2.3.4:9092",
bootstrap_servers="localhost:9092",
group_id="test-redact-password-group",
consumer_config={
"sasl.password": "PASSWORD",
Expand All @@ -46,15 +46,13 @@ def test_bad_consumer_config():
with pytest.raises(ValueError) as excinfo:
BlueskyConsumer(
topics=[test_topic],
bootstrap_servers="1.2.3.4:9092",
bootstrap_servers="localhost:9092",
group_id="test-bad-consumer_config",
consumer_config={
"bootstrap.servers": "5.6.7.8:9092",
"auto.offset.reset": "latest",
"group.id": "raise an exception!",
},
)
assert (
"do not specify 'group.id' in consumer_config, use only the 'group_id' argument"
in excinfo.value
)
assert (
"do not specify 'group.id' in consumer_config, use only the 'group_id' parameter"
in str(excinfo.value)
)
2 changes: 1 addition & 1 deletion bluesky_kafka/tests/test_queue_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def test_publisher_with_no_broker(RE, hw):
build_kafka_publisher_queue_and_thread(
topic=beamline_name,
# specify a bootstrap server that does not exist
bootstrap_servers="100.100.100.100:9092",
bootstrap_servers="localhost:9999",
producer_config={},
publisher_queue_timeout=1,
)

0 comments on commit 5b692e3

Please sign in to comment.