def test_ErrorConfigParameter(): '''Test the class ErrorConfigParameter (error when a configuration file parameter is incorrect)''' # This file is not created, just a tmp path test_parameter = "TestParameter" # Test instantiation test_error = NCBImetaErrors.ErrorConfigParameter(test_parameter) # Test str representation (error message) error_output = str(test_error) error_expect = ("\n\nA parameter name and/or value in the configuration file is set incorrectly:" + "\n" + test_parameter) assert error_output == error_expect
# Check if configuration file exists if not os.path.exists(config_path): raise NCBImetaErrors.ErrorConfigFileNotExists(config_path) # Load the YAML configuration file with open(config_path) as config_file: config_data = yaml.load(config_file, Loader=yaml.FullLoader) if config_data is None: raise NCBImetaErrors.ErrorConfigYAMLFormat(config_file) # Retrieve configuration file values and error catching #--- Output Directory ---# try: CONFIG_OUTPUT_DIR = config_data["OUTPUT_DIR"] except KeyError: raise NCBImetaErrors.ErrorConfigParameter("OUTPUT_DIR") #--- User Email ---# try: CONFIG_EMAIL = config_data["EMAIL"] except KeyError: raise NCBImetaErrors.ErrorConfigParameter("EMAIL") #--- User API Key ---# try: CONFIG_API_KEY = config_data["API_KEY"] except KeyError: raise NCBImetaErrors.ErrorConfigParameter("API_KEY") #--- Force pausing in between record fetching ---# try: CONFIG_FORCE_PAUSE_SECONDS = config_data["FORCE_PAUSE_SECONDS"] except KeyError: raise NCBImetaErrors.ErrorConfigParameter("FORCE_PAUSE_SECONDS")