def test_remove_spaces_in_brackets(self): """ Test the Utils remove_spaces_in_brackets """ sentence = "This is the {{ bracket }}" expected_result = "This is the {{bracket}}" self.assertEqual(Utils.remove_spaces_in_brackets(sentence=sentence), expected_result, "Fail to remove spaces in one bracket") sentence = "This is the {{ bracket }} {{ second }}" expected_result = "This is the {{bracket}} {{second}}" self.assertEqual(Utils.remove_spaces_in_brackets(sentence=sentence), expected_result, "Fail to remove spaces in two brackets") # test with json sentence = "{\"params\": {\"apikey\": \"ISNOTMYPASSWORD\", " \ "\"query\": \"met le chauffage a {{ valeur }} degres\"}}" expected_result = "{\"params\": {\"apikey\": \"ISNOTMYPASSWORD\", " \ "\"query\": \"met le chauffage a {{valeur}} degres\"}}" self.assertEqual(Utils.remove_spaces_in_brackets(sentence=sentence), expected_result, "Fail to remove spaces in two brackets")
def _neuron_parameters_are_available_in_loaded_parameters( string_parameters, loaded_parameters): """ Check that all parameters in brackets are available in the loaded_parameters dict E.g: string_parameters = "this is a {{ parameter1 }}" Will return true if the loaded_parameters looks like the following loaded_parameters { "parameter1": "a value"} :param string_parameters: The string that contains one or more parameters in brace brackets :param loaded_parameters: Dict of parameter :return: True if all parameters in brackets have an existing key in loaded_parameters dict """ list_parameters_with_brackets = Utils.find_all_matching_brackets( string_parameters) # remove brackets to keep only the parameter name for parameter_with_brackets in list_parameters_with_brackets: parameter = Utils.remove_spaces_in_brackets( parameter_with_brackets) parameter = parameter.replace("{{", "").replace("}}", "") if loaded_parameters is None or parameter not in loaded_parameters: Utils.print_danger( "The parameter %s is not available in the order" % str(parameter)) return False return True