def test_build_sorters_from_config_bad_config(): # 1. class_name is bad sorters_config = [{"orderby": "desc", "class_name": "IDontExist", "name": "price",}] with pytest.raises(ge_exceptions.PluginClassNotFoundError): build_sorters_from_config(sorters_config) # 2. orderby : not a real order sorters_config = [ {"orderby": "not_a_real_order", "class_name": "NumericSorter", "name": "price",} ] with pytest.raises(ge_exceptions.SorterError): build_sorters_from_config(sorters_config)
def __init__( self, name: str, datasource_name: str, execution_engine: Optional[ExecutionEngine] = None, default_regex: Optional[dict] = None, sorters: Optional[list] = None, ): """ Base class for DataConnectors that connect to filesystem-like data. This class supports the configuration of default_regex and sorters for filtering and sorting data_references. Args: name (str): name of FilePathDataConnector datasource_name (str): Name of datasource that this DataConnector is connected to execution_engine (ExecutionEngine): Execution Engine object to actually read the data default_regex (dict): Optional dict the filter and organize the data_references. sorters (list): Optional list if you want to sort the data_references """ logger.debug(f'Constructing FilePathDataConnector "{name}".') super().__init__( name=name, datasource_name=datasource_name, execution_engine=execution_engine, ) if default_regex is None: default_regex = {} self._default_regex = default_regex self._sorters = build_sorters_from_config(config_list=sorters) self._validate_sorters_configuration()
def test_build_sorters_from_config_good_config(): sorters_config = [ {"orderby": "desc", "class_name": "NumericSorter", "name": "price",} ] sorters = build_sorters_from_config(sorters_config) assert sorters.__repr__() == str( "{'price': {'name': 'price', 'reverse': True, 'type': 'NumericSorter'}}" ) assert sorters["price"].__repr__() == str( {"name": "price", "reverse": True, "type": "NumericSorter"} ) # no sorters by name of i_dont_exist with pytest.raises(KeyError): sorters["i_dont_exist"]
def __init__( self, name: str, datasource_name: str, execution_engine: Optional[ExecutionEngine] = None, default_regex: Optional[dict] = None, sorters: Optional[list] = None, ): logger.debug(f'Constructing FilePathDataConnector "{name}".') super().__init__( name=name, datasource_name=datasource_name, execution_engine=execution_engine, ) if default_regex is None: default_regex = {} self._default_regex = default_regex self._sorters = build_sorters_from_config(config_list=sorters) self._validate_sorters_configuration()