"""Ecosystem integration helpers for behave-kit, behave-tables and behave-data.These functions lazily import the corresponding libraries and raise``MissingDependencyError`` with the appropriate extra name if the libraryis not installed."""from__future__importannotationsfromtypingimportAnyfromsteplib.core.exceptionsimportMissingDependencyError,StepContractError
[docs]defassert_soft(condition:bool,message:str="")->None:"""Perform a soft assertion using ``behave-kit``. Args: condition: The condition to assert. message: Optional message to display on failure. Raises: MissingDependencyError: If ``behave-kit`` is not installed. """try:frombehave_kitimportassert_softas_assert_softexceptImportErrorasexc:raiseMissingDependencyError("kit","behave-kit")fromexcifmessage:_assert_soft(condition,message)else:_assert_soft(condition)
[docs]defwrap_table(table:Any)->Any:"""Wrap a behave table using ``behave-tables`` for easy conversion. Args: table: The ``context.table`` object from behave. Returns: A wrapped table object with methods like ``as_dicts()``. Raises: MissingDependencyError: If ``behave-tables`` is not installed. """try:frombehave_tablesimportwrapas_wrapexceptImportErrorasexc:raiseMissingDependencyError("tables","behave-tables")fromexcreturn_wrap(table)
[docs]defload_test_data(source:str,**kwargs:Any)->Any:"""Load test data from a file using ``behave-data``. Args: source: Path or URL to the data file (CSV, JSON, YAML, Excel). **kwargs: Additional arguments passed to ``behave-data``. Returns: The loaded data. Raises: MissingDependencyError: If ``behave-data`` is not installed. StepContractError: If ``behave-data`` is installed but has no ``load`` function. """try:importbehave_dataexceptImportErrorasexc:raiseMissingDependencyError("data","behave-data")fromexcload_fn=getattr(behave_data,"load",None)ifload_fnisNone:raiseStepContractError("behave-data is installed but does not expose a 'load' function.")returnload_fn(source,**kwargs)
[docs]defcheck_behave_model_available()->bool:"""Check if ``behave-model`` is installed. Returns: ``True`` if ``behave-model`` is importable, ``False`` otherwise. """importimportlib.utilreturnimportlib.util.find_spec("behave_model")isnotNone
[docs]defcheck_behave_doctor_available()->bool:"""Check if ``behave-doctor`` is installed. Returns: ``True`` if ``behave-doctor`` is importable, ``False`` otherwise. """importimportlib.utilreturnimportlib.util.find_spec("behave_doctor")isnotNone