def test_update_existing_hash(local_config): """Tests updating an exising hash in the database, and how it affects the retrieval APIs.""" manager = StateManager(local_config) manager.set_checkpoint('ABCDEFGH', 'default', 'ALPHA') return_list = manager.get_unfinished_hashes('default') assert return_list == [('ABCDEFGH', 'ALPHA')] return_list = manager.get_previous_hashes('default') assert return_list == [] manager.set_checkpoint('ABCDEFGH', 'default', 'DONE') return_list = manager.get_unfinished_hashes('default') assert return_list == [] return_list = manager.get_previous_hashes('default') assert return_list == ['ABCDEFGH']
def test_set_checkpoint_persistent(local_persistent_config): """Tests that set_checkpoint actually adds stuff to the database file on disk.""" if os.path.exists(PERSISTENCE_FILE): os.remove(PERSISTENCE_FILE) manager = StateManager(local_persistent_config) manager.set_checkpoint('ABCDEFGH', 'default', 'ALPHA') manager.set_checkpoint('EFGHIJKL', 'default', 'BRAVO') manager.set_checkpoint('ABCDEFGH', 'another', 'CHARLIE') manager.force_close() manager2 = StateManager(local_persistent_config) return_list = manager2.get_unfinished_hashes('default') assert len(return_list) == 2 return_list = manager2.get_unfinished_hashes('another') assert len(return_list) == 1
def test_add_unfinished_hashes(local_config): """Tests adding hashes that are unfinished and getting them with get_unfinished_hashes().""" manager = StateManager(local_config) manager.set_checkpoint('ABCDEFGH', 'default', 'ALPHA') manager.set_checkpoint('EFGHIJKL', 'default', 'BRAVO') manager.set_checkpoint('ABCDEFGH', 'another', 'CHARLIE') return_list = manager.get_unfinished_hashes('default') assert len(return_list) == 2 tmp = _unfinished_as_map(return_list) assert tmp['ABCDEFGH'] == 'ALPHA' assert tmp['EFGHIJKL'] == 'BRAVO' return_list = manager.get_unfinished_hashes('another') assert len(return_list) == 1 tmp = _unfinished_as_map(return_list) assert tmp['ABCDEFGH'] == 'CHARLIE'
def test_empty_database_retrieval(local_config): """Tests the two retrieval APIs on an empty database.""" manager = StateManager(local_config) return_list = manager.get_unfinished_hashes('default') assert return_list == [] return_list = manager.get_previous_hashes('default') assert return_list == []
def test_add_mixed_hashes(local_config): """Tests adding both done and not-done hashes to make sure they're separated properly.""" manager = StateManager(local_config) manager.set_checkpoint('ABCDEFGH', 'default', 'ALPHA') manager.set_checkpoint('DEFGHIJK', 'default', 'DONE') return_list = manager.get_unfinished_hashes('default') assert return_list == [('ABCDEFGH', 'ALPHA')] return_list = manager.get_previous_hashes('default') assert return_list == ['DEFGHIJK']
def test_get_unfinished_hashes(local_config): """Test the get_unfinished_hashes() API.""" manager = StateManager(local_config) return_list = manager.get_unfinished_hashes("default") assert len(return_list) == 2 assert getattr(manager._persistor, "_sc", 0) == 0 assert getattr(manager._persistor, "_gph", 0) == 0 assert getattr(manager._persistor, "_guh", 0) == 1 assert getattr(manager._persistor, "_p", 0) == 0 assert getattr(manager._persistor, "_ari", 0) == 0 assert getattr(manager._persistor, "_gcri", 0) == 0 assert getattr(manager._persistor, "_cri", 0) == 0