Пример #1
0
    def assertCommandMatchesExactlyOneFormatString(self, format_strings,
                                                   command):
        """
        Assert that the provided command matches exactly one format string from the provided list.
        """
        matched_format_strings = []

        for format_string in format_strings:
            try:
                extract_parameters(format_str=format_string,
                                   param_stream=command)
            except ParseException:
                continue

            matched_format_strings.append(format_string)

        if len(matched_format_strings) == 0:
            msg = (
                'Command "%s" didn\'t match any of the provided format strings'
                % (command))
            raise AssertionError(msg)
        elif len(matched_format_strings) > 1:
            msg = ('Command "%s" matched multiple format strings: %s' %
                   (command, ', '.join(matched_format_strings)))
            raise AssertionError(msg)
Пример #2
0
def match_command_to_alias(command, aliases, match_multiple=False):
    """
    Match the text against an action and return the action reference.
    """
    results = []

    for alias in aliases:
        formats = list_format_strings_from_aliases([alias], match_multiple)
        for format_ in formats:
            try:
                extract_parameters(format_str=format_['representation'],
                                   param_stream=command)
            except ParseException:
                continue

            results.append(format_)
    return results
Пример #3
0
def match_command_to_alias(command, aliases, match_multiple=False):
    """
    Match the text against an action and return the action reference.
    """
    results = []

    for alias in aliases:
        formats = list_format_strings_from_aliases([alias], match_multiple)
        for format_ in formats:
            try:
                extract_parameters(format_str=format_['representation'],
                                   param_stream=command)
            except ParseException:
                continue

            results.append(format_)
    return results
Пример #4
0
def match_command_to_alias(command, aliases):
    """
    Match the text against an action and return the action reference.
    """
    results = []

    for alias in aliases:
        format_strings = list_format_strings_from_aliases([alias])
        for format_string in format_strings:
            try:
                extract_parameters(format_str=format_string[1],
                                   param_stream=command)
            except ParseException:
                continue

            results.append((alias, format_string[0], format_string[1]))
    return results
Пример #5
0
def match_command_to_alias(command, aliases):
    """
    Match the text against an action and return the action reference.
    """
    results = []

    for alias in aliases:
        format_strings = list_format_strings_from_aliases([alias])
        for format_string in format_strings:
            try:
                extract_parameters(format_str=format_string[1],
                                   param_stream=command)
            except ParseException:
                continue

            results.append((alias, format_string[0], format_string[1]))
    return results
Пример #6
0
    def assertCommandMatchesExactlyOneFormatString(self, format_strings, command):
        """
        Assert that the provided command matches exactly one format string from the provided list.
        """
        matched_format_strings = []

        for format_string in format_strings:
            try:
                extract_parameters(format_str=format_string,
                                   param_stream=command)
            except ParseException:
                continue

            matched_format_strings.append(format_string)

        if len(matched_format_strings) == 0:
            msg = ('Command "%s" didn\'t match any of the provided format strings' % (command))
            raise AssertionError(msg)
        elif len(matched_format_strings) > 1:
            msg = ('Command "%s" matched multiple format strings: %s' %
                   (command, ', '.join(matched_format_strings)))
            raise AssertionError(msg)