From ebe1d7b19c7aca5134484ccb32d2e61d529e8ddc Mon Sep 17 00:00:00 2001 From: eugenegujing Date: Tue, 11 Aug 2026 13:38:39 -0700 Subject: [PATCH] chore(python): interpolate the offending type in the BATCH_SIZE validation error - Change the message to f"BATCH_SIZE cannot be {type(value)}." in amber/src/main/python/core/models/operator.py - Add three tests in amber/src/test/python/core/models/test_operator.py pinning the exact message for float and str values via the validator and for a concrete BatchOperator subclass with BATCH_SIZE = 10.0 --- amber/src/main/python/core/models/operator.py | 2 +- .../test/python/core/models/test_operator.py | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/amber/src/main/python/core/models/operator.py b/amber/src/main/python/core/models/operator.py index c27dc154b58..67d25b693bc 100644 --- a/amber/src/main/python/core/models/operator.py +++ b/amber/src/main/python/core/models/operator.py @@ -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.") diff --git a/amber/src/test/python/core/models/test_operator.py b/amber/src/test/python/core/models/test_operator.py index d8d387a9ad9..99b3c729e85 100644 --- a/amber/src/test/python/core/models/test_operator.py +++ b/amber/src/test/python/core/models/test_operator.py @@ -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 ." + + 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 ." + + 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 ." + def test_validate_batch_size_rejects_zero(self): with pytest.raises(ValueError, match="positive"): BatchOperator._validate_batch_size(0)