From 64d7eb07dfeb40c83c72d28efcc77dccdd865f20 Mon Sep 17 00:00:00 2001 From: Jannis Mittenzwei Date: Sun, 22 Feb 2026 16:07:26 +0100 Subject: [PATCH] refacto validate_emit --- exasol_udf_mock_python/column.py | 5 ++++- exasol_udf_mock_python/mock_context.py | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/exasol_udf_mock_python/column.py b/exasol_udf_mock_python/column.py index 4198a5e..251377b 100644 --- a/exasol_udf_mock_python/column.py +++ b/exasol_udf_mock_python/column.py @@ -8,4 +8,7 @@ def __init__(self, name, type, sql_type, precision=None, scale=None, length=None self.length = length def __repr__(self): - return str(self.__class__) + ": " + str(self.__dict__) \ No newline at end of file + return str(self.__class__) + ": " + str(self.__dict__) + + def __str__(self): + return f"{self.name}:{self.type.__name__}" diff --git a/exasol_udf_mock_python/mock_context.py b/exasol_udf_mock_python/mock_context.py index 29c0ff2..c7d1be9 100644 --- a/exasol_udf_mock_python/mock_context.py +++ b/exasol_udf_mock_python/mock_context.py @@ -35,11 +35,20 @@ def validate_emit(row: Tuple, columns: List[Column]): :param row: Data row :param columns: Column definition. """ - if len(row) != len(columns): - raise ValueError(f"row {row} has not the same number of values as columns are defined") + if (expected_len := len(columns)) != (actual_len := len(row)): + raise ValueError( + f"Row length missmatch: got {actual_len} values but {expected_len} columns are defined.\n" + f" Expected columns: {[str(c) for c in columns]}. Actual values: {row}\n" + ) + errors = [] for i, column in enumerate(columns): if row[i] is not None and not isinstance(row[i], column.type): - raise TypeError(f"Value {row[i]} ({type(row[i])}) at position {i} is not a {column.type}") + errors.append( + f"Type missmatch at column '{column.name}' (index {i})\n" + f" Expected type: {column.type.__name__}. Actual type {type(row[i]).__name__} with Value: {row[i]}.\n" + ) + if errors: + raise TypeError("\n".join(errors)) class MockContext(UDFContext):