Skip to content
Open
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 amber/src/main/python/core/models/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def _validate_batch_size(value):
if value is None:
raise ValueError("BATCH_SIZE cannot be None.")
if type(value) is not int:
raise ValueError("BATCH_SIZE cannot be {type(value))}.")
raise ValueError(f"BATCH_SIZE cannot be {type(value)}.")
if value <= 0:
raise ValueError("BATCH_SIZE should be positive.")

Expand Down
22 changes: 22 additions & 0 deletions amber/src/test/python/core/models/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,28 @@ def test_validate_batch_size_rejects_non_int(self):
with pytest.raises(ValueError):
BatchOperator._validate_batch_size("10")

def test_validate_batch_size_non_int_message_names_the_float_type(self):
# The message must name the offending type, not a template literal.
with pytest.raises(ValueError) as excinfo:
BatchOperator._validate_batch_size(10.0)
assert str(excinfo.value) == "BATCH_SIZE cannot be <class 'float'>."

def test_validate_batch_size_non_int_message_names_the_str_type(self):
with pytest.raises(ValueError) as excinfo:
BatchOperator._validate_batch_size("10")
assert str(excinfo.value) == "BATCH_SIZE cannot be <class 'str'>."

def test_concrete_batch_operator_with_float_size_reports_type_in_message(self):
class _FloatBatch(BatchOperator):
BATCH_SIZE = 10.0

def process_batch(self, batch, port):
yield batch

with pytest.raises(ValueError) as excinfo:
_FloatBatch()
assert str(excinfo.value) == "BATCH_SIZE cannot be <class 'float'>."

def test_validate_batch_size_rejects_zero(self):
with pytest.raises(ValueError, match="positive"):
BatchOperator._validate_batch_size(0)
Expand Down
Loading