def add(cls, alias, db_path, make_default=False): """ Add source to source manager - this includes initializing all facilities hidden behind name 'source'. After source has been added, it is accessible with alias. Required arguments: alias -- alias under which source will be accessible. Also controls several paths under which temporary data is stored for the sources db_path -- path to database with EVE data for this source Optional arguments: make_default -- marks passed source default; it will be used by default for some actions, like fit initialization, unless specified explicitly """ if alias in cls._sources: raise ExistingSourceError(alias) # Database session edb_session = make_evedata_session(db_path) # Eos source data_handler = SQLiteDataHandler(db_path) cache_handler = JsonCacheHandler('staticdata/eos_cache/{}.json.bz2'.format(alias)) EosSourceManager.add(alias, data_handler, cache_handler) eos_source = EosSourceManager.get(alias) # Finally, add record to list of sources source = Source(alias=alias, edb=edb_session, eos=eos_source) cls._sources[alias] = source if make_default is True: cls.default = source
def test_get_real_source(mock_data_handler, mock_cache_handler): alias = 'test' source = Source(alias=alias, cache_handler=mock_cache_handler) SourceManager.add(alias, mock_data_handler, mock_cache_handler) result = SourceManager.get(alias) assert result == source
def test_get_unkown_source(mock_data_handler, mock_cache_handler): with pytest.raises(UnknownSourceError): SourceManager.get('test')