def test_find_all_matching_brackets(self): """ Test the Utils find all matching brackets """ sentence = "This is the {{bracket}}" expected_result = ["{{bracket}}"] self.assertEqual(Utils.find_all_matching_brackets(sentence=sentence), expected_result, "Fail to match one bracket") sentence = "This is the {{bracket}} {{second}}" expected_result = ["{{bracket}}", "{{second}}"] self.assertEqual(Utils.find_all_matching_brackets(sentence=sentence), expected_result, "Fail to match two brackets")
def test_find_all_matching_brackets(self): """ Test the Utils find all matching brackets """ sentence = "This is the {{bracket}}" expected_result = ["{{bracket}}"] self.assertEqual(Utils.find_all_matching_brackets(sentence=sentence), expected_result, "Fail to match one bracket") sentence = "This is the {{bracket}} {{second}}" expected_result = ["{{bracket}}", "{{second}}"] self.assertEqual(Utils.find_all_matching_brackets(sentence=sentence), expected_result, "Fail to match 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
def _get_split_order_without_bracket(order): """ Get an order with bracket inside like: "hello my name is {{ name }}. return a list of string without bracket like ["hello", "my", "name", "is"] :param order: sentence to split :return: list of string without bracket """ matches = Utils.find_all_matching_brackets(order) for match in matches: order = order.replace(match, "") # then split split_order = order.split() return split_order
def _get_split_order_without_bracket(order): """ Get an order with bracket inside like: "hello my name is {{ name }}. return a list of string without bracket like ["hello", "my", "name", "is"] :param order: sentence to split :return: list of string without bracket """ matches = Utils.find_all_matching_brackets(order) for match in matches: order = order.replace(match, "") # then split split_order = order.split() return split_order
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