from functools import wraps
from collections.abc import Callable
from ppc_robot_lib import tasks
[docs]
def table_not_empty(table_name: str) -> Callable[['tasks.TaskContextInterface'], bool]:
"""
Creates a callable that checks whether a table of given name **is not empty**.
:param table_name: Name of the table to check.
:return: Callable that receives ``TaskContext`` and returns whether the given table is not empty.
"""
@wraps(table_not_empty)
def cond_func(task_ctx: 'tasks.TaskContextInterface'):
if table_name not in task_ctx.work_set:
return False
table = task_ctx.work_set.get_table(table_name)
return len(table) > 0
return cond_func
[docs]
def table_empty(table_name: str) -> Callable[['tasks.TaskContextInterface'], bool]:
"""
Creates a callable that checks whether a table of given name **is empty**.
:param table_name: Name of the table to check.
:return: Callable that receives ``TaskContext`` and returns whether the given table is empty.
"""
@wraps(table_empty)
def cond_func(task_ctx: 'tasks.TaskContextInterface'):
if table_name not in task_ctx.work_set:
return False
table = task_ctx.work_set.get_table(table_name)
return len(table) == 0
return cond_func
[docs]
def table_min_rows(table_name: str, min_rows) -> Callable[['tasks.TaskContextInterface'], bool]:
"""
Creates a callable that checks whether a table of given name **contains at least ``min_rows`` rows**.
:param table_name: Name of the table to check.
:param min_rows: Minimum number of rows that are required to trigger the condition.
:return: Callable that receives ``TaskContext`` and returns whether the given table contains at least
``min_rows`` rows.
"""
@wraps(table_min_rows)
def cond_func(task_ctx: 'tasks.TaskContextInterface'):
if table_name not in task_ctx.work_set:
return False
table = task_ctx.work_set.get_table(table_name)
return len(table) >= min_rows
return cond_func