def test_load_stock(write_yaml, shared_datadir): stock_filename = str(shared_datadir / "stock1.h5") filename = write_yaml({"stock": {"files": {"test": stock_filename}}}) config = Configuration.from_file(filename) assert config.stock.items == ["test"]
def test_load_stock(write_yaml, create_dummy_stock1): stock_filename = create_dummy_stock1("hdf5") filename = write_yaml({"stock": {"files": {"test": stock_filename}}}) config = Configuration.from_file(filename) assert config.stock.items == ["test"]
def test_load_default_mongodb(write_yaml, mocker): mocked_client = mocker.patch("aizynthfinder.context.stock.MongoClient") filename = write_yaml({"stock": {"mongodb": {}}}) config = Configuration.from_file(filename) mocked_client.assert_called_with(None) assert config.stock.items == ["mongodb_stock"]
def test_load_scorer_from_module_spec(write_yaml): filename = write_yaml( {"scorer": {"aizynthfinder.context.scoring.PriceSumScorer": None}} ) config = Configuration.from_file(filename) assert "sum of prices" in config.scorers.items
def test_load_filter_policy(write_yaml, shared_datadir, mock_policy_model): templates_filename = str(shared_datadir / "templates.hdf5") filename = write_yaml( {"filter": {"files": {"test": ["dummy", templates_filename]}}} ) config = Configuration.from_file(filename) assert config.filter_policy.items == ["test"]
def test_load_policy(write_yaml, create_dummy_templates, mock_keras_model): templates_filename = create_dummy_templates(3) filename = write_yaml( {"policy": {"files": {"test": ["dummy", templates_filename]}}} ) config = Configuration.from_file(filename) assert config.expansion_policy.items == ["test"]
def test_load_stop_criteria(write_yaml): filename = write_yaml( {"stock": {"stop_criteria": {"price": 100, "counts": {"C": 10}}}} ) config = Configuration.from_file(filename) set_keys = [key for key, item in config.stock.stop_criteria.items() if item] assert set_keys == ["price", "counts"] assert list(config.stock.stop_criteria["counts"].keys()) == ["C"] assert config.stock.stop_criteria["counts"]["C"] == 10
def test_load_external_stock_incorrect_class(write_yaml, shared_datadir): stock_filename = str(shared_datadir / "stock1.h5") filename = write_yaml({ "stock": { "aizynthfinder.context.stock.InnMemoryInchiKeyQuery": { "filename": stock_filename } } }) config = Configuration.from_file(filename) assert config.stock.items == []
def __init__(self, configfile: str = None, configdict: StrDict = None) -> None: self._logger = logger() if configfile: self.config = Configuration.from_file(configfile) elif configdict: self.config = Configuration.from_dict(configdict) else: self.config = Configuration() self.expansion_policy = self.config.expansion_policy self.filter_policy = self.config.filter_policy
def test_load_from_file(write_yaml): filename = write_yaml( { "properties": {"cutoff_number": 300}, "policy": {"properties": {"C": 1.9}}, "finder": {"properties": {"time_limit": 300}}, } ) config = Configuration.from_file(filename) assert config.cutoff_number == 300 assert config.C == 1.9 assert config.time_limit == 300
def test_load_external_stock_incorrect_class(write_yaml, create_dummy_stock1): stock_filename = create_dummy_stock1("hdf5") filename = write_yaml( { "stock": { "aizynthfinder.context.stock.InnMemoryInchiKeyQuery": { "filename": stock_filename } } } ) config = Configuration.from_file(filename) assert config.stock.items == []
def __init__(self, configfile=None, configdict=None): self._logger = logger() if configfile: self.config = Configuration.from_file(configfile) elif configdict: self.config = Configuration.from_dict(configdict) else: self.config = Configuration() self.expansion_policy = self.config.expansion_policy self.filter_policy = self.config.filter_policy self.stock = self.config.stock self.scorers = self.config.scorers self.tree = None self._target_mol = None self.search_stats = {} self.routes = None self.analysis = None
def __init__(self, configfile: str = None, configdict: StrDict = None) -> None: self._logger = logger() if configfile: self.config = Configuration.from_file(configfile) elif configdict: self.config = Configuration.from_dict(configdict) else: self.config = Configuration() self.expansion_policy = self.config.expansion_policy self.filter_policy = self.config.filter_policy self.stock = self.config.stock self.scorers = self.config.scorers self.tree: Optional[SearchTree] = None self._target_mol: Optional[Molecule] = None self.search_stats: StrDict = dict() self.routes = RouteCollection([]) self.analysis: Optional[TreeAnalysis] = None
def test_load_specific_mongodb(write_yaml, mocker): mocked_client = mocker.patch( "aizynthfinder.context.stock.get_mongo_client") filename = write_yaml({ "stock": { "mongodb": { "host": "myhost", "database": "mydatabase", "collection": "mycollection", } } }) config = Configuration.from_file(filename) mocked_client.assert_called_with("myhost") assert config.stock.items == ["mongodb_stock"] config.stock["mongodb_stock"].client.__getitem__.assert_called_with( "mydatabase") config.stock["mongodb_stock"].database.__getitem__.assert_called_with( "mycollection")
def test_load_filter_policy(write_yaml, mock_keras_model): filename = write_yaml({"filter": {"files": {"test": "dummy"}}}) config = Configuration.from_file(filename) assert config.filter_policy.items == ["test"]
def test_load_scorer_from_context_module(write_yaml): filename = write_yaml({"scorer": {"PriceSumScorer": None}}) config = Configuration.from_file(filename) assert "sum of prices" in config.scorers.items
def test_load_empty_file(default_config, write_yaml): filename = write_yaml({}) config = Configuration.from_file(filename) assert config == default_config