def test_incorrect_db_check(self): incorrect_files = [ "res/test_property_files/db_prop_empty.properties", "res/test_property_files/db_prop_missing.properties", ] for f in incorrect_files: p = r.parse_properties_from_file(f) assert not c.check_required_db_properties(p) assert c.check_experiment_properties(p)
def test_incorrect_experiment_check(self): incorrect_files = [ "res/test_property_files/keyfield_value_empty.properties", "res/test_property_files/keyfield_value_missing.properties", "res/test_property_files/keyfields_empty.properties", "res/test_property_files/keyfields_missing.properties", "res/test_property_files/resultfields_empty.properties", "res/test_property_files/resultfields_missing.properties", ] for f in incorrect_files: p = r.parse_properties_from_file(f) assert not c.check_experiment_properties(p) assert c.check_required_db_properties(p)
def run(self): db_handler = None try: if not required_properties_checker.check_experiment_properties( self.properties): return db_handler = create_database_handler_from_config(self.properties) if db_handler is None: print("Could not create DB handler!") return db_handler.open_connection() if db_handler.is_connected(): db_handler.check_table_and_create_if_missing() else: print("Is not connected to DB!") return experiments_amount = 1 for keyfield in self.properties["keyfields"]: experiments_amount = experiments_amount * len( self.properties[keyfield]) while db_handler.is_connected() and (db_handler.count_entries() < experiments_amount): experiment_entry = selec.create_random_keyfield_configuration( self.properties) experiment_id = db_handler.reserve_entry(experiment_entry) if experiment_id is not None: try: resultfields = self.evaluation_function( experiment_entry) db_handler.save_results(experiment_id, resultfields) except Exception: db_handler.save_error( experiment_id, traceback.format_exc(chain=False, limit=3), ) time.sleep(random.uniform(1.0, 5.0)) except Exception: print(f"Experiment error: {traceback.format_exc()}") finally: if db_handler is not None: db_handler.close_connection()
def test_non_dict_input(self): assert not c.check_experiment_properties(123) assert not c.check_required_db_properties(123)
def test_correct_property_checking(self): p = r.parse_properties_from_file( "res/test_property_files/correct.properties" ) assert c.check_required_db_properties(p) assert c.check_experiment_properties(p)