def test_ErrorConfigYAMLFormat(tmpdir): '''Test the class ErrorConfigYAMLFormat (error when a configuration file is improperly formatted)''' # This file is not created, just a tmp path tmpfile = os.path.join(tmpdir.strpath, "tmpfile") # Test instantiation test_error = NCBImetaErrors.ErrorConfigYAMLFormat(tmpfile) # Test str representation (error message) error_output = str(test_error) error_expect = ("\n\nThe configuration file could not be loaded, please confirm that this is a proper YAML file: " + "\n" + tmpfile) print("TESTING") assert error_output == error_expect
config_path = args['configPath'] flat_mode = args['flatMode'] #------------------------------------------------------------------------------# # Error Catching # #------------------------------------------------------------------------------# # 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"]