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_add_processes_with_data_version_none( mock_data_handler, mock_cache_handler, caplog): mock_data_handler.get_version = Mock(return_value=None) SourceManager.add('test', mock_data_handler, mock_cache_handler) assert mock_cache_handler.update_cache.called assert 'data version is None, updating cache' in caplog.text
def test_add_sets_sources(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, True) assert SourceManager._sources == {alias: source} assert SourceManager.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_add_fingerprint_mismatch(mock_data_handler, mock_cache_handler, caplog): mock_cache_handler.get_fingerprint = Mock(return_value='cache_fingerprint') mock_data_handler.get_version = Mock(return_value='dh_version') SourceManager.add('test', mock_data_handler, mock_cache_handler) log_msg = 'fingerprint mismatch: cache "cache_fingerprint", data "dh_version_0.0.0.dev8", updating cache' assert log_msg in caplog.text()
def remove(cls, alias): """ Remove source by alias. Required arguments: alias -- alias of source to remove """ try: source = cls._sources[alias] except KeyError: raise UnknownSourceError(alias) else: EosSourceManager.remove(alias) source.edb.close() del cls._sources[alias]
def test_list_sources_correctly(mock_data_handler, mock_cache_handler): SourceManager.add('source one', mock_data_handler, mock_cache_handler) SourceManager.add('source two', mock_data_handler, mock_cache_handler) SourceManager.add('source three', mock_data_handler, mock_cache_handler) sources = SourceManager.list() assert sorted(sources) == sorted(['source one', 'source two', 'source three'])
def test_removing_known_source(mock_data_handler, mock_cache_handler): SourceManager.add('test', mock_data_handler, mock_cache_handler) SourceManager.remove('test') assert 'test' not in SourceManager._sources
def test_add_does_not_set_default(mock_data_handler, mock_cache_handler): SourceManager.add('test', mock_data_handler, mock_cache_handler) assert SourceManager.default is None
def test_add_existing_source_error(mock_data_handler, mock_cache_handler): SourceManager.add('test', mock_data_handler, mock_cache_handler, True) with pytest.raises(ExistingSourceError): SourceManager.add('test', mock_data_handler, mock_cache_handler, True)
def test_get_unkown_source(mock_data_handler, mock_cache_handler): with pytest.raises(UnknownSourceError): SourceManager.get('test')
def test_removing_unknown_source(mock_data_handler, mock_cache_handler): with pytest.raises(UnknownSourceError): SourceManager.remove('test')