2022-11-01 13:26:51 +01:00
|
|
|
# Copyright 2021 Collate
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
Helper module for test suite functions
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2023-01-11 16:51:36 +01:00
|
|
|
from typing import Callable, Optional
|
|
|
|
|
|
2022-11-01 13:26:51 +01:00
|
|
|
from metadata.generated.schema.tests.testCase import TestCaseParameterValue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_test_case_param_value(
|
2023-01-11 16:51:36 +01:00
|
|
|
test_case_param_vals: list[TestCaseParameterValue],
|
|
|
|
|
name: str,
|
|
|
|
|
type_,
|
|
|
|
|
default=None,
|
|
|
|
|
pre_processor: Optional[Callable] = None,
|
2022-11-01 13:26:51 +01:00
|
|
|
):
|
|
|
|
|
"""Give a column and a type return the value with the appropriate type casting for the
|
|
|
|
|
test case definition.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
test_case: the test case
|
|
|
|
|
type_ (Union[float, int, str]): type for the value
|
|
|
|
|
name (str): column name
|
|
|
|
|
default (_type_, optional): Default value to return if column is not found
|
2023-01-11 16:51:36 +01:00
|
|
|
pre_processor: pre processor function/type to use against the value before casting to type_
|
2022-11-01 13:26:51 +01:00
|
|
|
"""
|
2023-01-11 16:51:36 +01:00
|
|
|
value = next(
|
|
|
|
|
(param.value for param in test_case_param_vals if param.name == name), None
|
2022-11-01 13:26:51 +01:00
|
|
|
)
|
2023-01-11 16:51:36 +01:00
|
|
|
|
|
|
|
|
if not value:
|
|
|
|
|
return default
|
|
|
|
|
|
|
|
|
|
if not pre_processor:
|
|
|
|
|
return type_(value)
|
|
|
|
|
|
|
|
|
|
pre_processed_value = pre_processor(value)
|
|
|
|
|
return type_(pre_processed_value)
|