|
7 | 7 | """ |
8 | 8 | # pylint: disable=no-name-in-module |
9 | 9 | from concurrent.futures import ThreadPoolExecutor |
10 | | -from functools import partial |
| 10 | +from functools import partial, reduce |
11 | 11 | from itertools import chain |
| 12 | +import operator |
12 | 13 | from pathlib import Path |
13 | | -from typing import Callable, Dict, Optional |
| 14 | +from typing import Any, Callable, Dict, List, Optional, Tuple |
14 | 15 | from uuid import uuid4 |
15 | 16 | from behave import given, then, when # type: ignore |
16 | 17 | from behave.model import Row, Table |
@@ -163,6 +164,30 @@ def get_record_rejects_from_service(context: Context, service: str, expected_num |
163 | 164 | message_df = load_errors_from_service(processing_path, service) |
164 | 165 | num_rejections = message_df.filter(pl.col("FailureType").eq("record")).shape[0] |
165 | 166 | assert num_rejections == expected_num_errors, f"Got {num_rejections} actual rejections" |
| 167 | + |
| 168 | + |
| 169 | +@then("there are errors with the following details and associated error_count from the {service} phase") |
| 170 | +def check_error_record_details_from_service(context: Context, service:str): |
| 171 | + processing_path = ctxt.get_processing_location(context) |
| 172 | + table: Optional[Table] = context.table |
| 173 | + if table is None: |
| 174 | + raise ValueError("No table supplied in step") |
| 175 | + error_details: List[Tuple[pl.Expr, int]] = [] |
| 176 | + row: Row |
| 177 | + for row in table: |
| 178 | + record = row.as_dict() |
| 179 | + error_count = int(record.pop("error_count")) |
| 180 | + filter_expr = reduce(operator.and_, |
| 181 | + [pl.col(k).eq(v) for k, v in record.items()]) |
| 182 | + error_details.append((filter_expr, error_count)) |
| 183 | + |
| 184 | + message_df = load_errors_from_service(processing_path, service) |
| 185 | + for err_details in error_details: |
| 186 | + filter_expr, error_count = err_details |
| 187 | + assert message_df.filter(filter_expr).shape[0] == error_count |
| 188 | + |
| 189 | + |
| 190 | + |
166 | 191 |
|
167 | 192 |
|
168 | 193 | @given("A {implementation} pipeline is configured") |
|
0 commit comments