Exemplo n.º 1
0
def add_printable_dict_comparison(result, row):
    """Stdout representation of fix/dict match rows."""
    indent, key, status, left, right = row
    if left or right:
        if not left:
            left = "None"
        if not right:
            right = "None"
    else:
        left = ""
        right = ""

    if status == "Passed":
        coloured = Color.colored(status, "green")
        operator = " == "
    elif status == "Failed":
        coloured = Color.colored(status, "red")
        operator = " != "
    else:
        coloured = "Ignore"
        operator = "    "

    result.append("{}  {}{}    {}{}{}".format(
        "({})".format(coloured) if coloured else " " * len("(Passed)"),
        " " * 4 * indent,
        "Key({}),".format(key) if key else "",
        "{} <{}>".format(left[1], left[0])
        if isinstance(left, tuple) else left,
        operator if left and right else " ",
        "{} <{}>".format(right[1], right[0])
        if isinstance(right, tuple) else right,
    ))
Exemplo n.º 2
0
def add_printable_dict_comparison(result, row):
    """Stdout representation of fix/dict match rows."""
    indent, key, status, left, right = row
    if left or right:
        if not left:
            left = 'None'
        if not right:
            right = 'None'
    else:
        left = ''
        right = ''

    if status == 'Passed':
        coloured = Color.colored(status, 'green')
        operator = ' == '
    elif status == 'Failed':
        coloured = Color.colored(status, 'red')
        operator = ' != '
    else:
        coloured = 'Ignore'
        operator = '    '

    result.append('{}  {}{}    {}{}{}'.format(
        '({})'.format(coloured) if coloured else ' ' * len('(Passed)'),
        ' ' * 4 * indent,
        'Key({}),'.format(key) if key else '', '{} <{}>'.format(
            left[1], left[0]) if isinstance(left, tuple) else left,
        operator if left and right else ' ', '{} <{}>'.format(
            right[1], right[0]) if isinstance(right, tuple) else right))
Exemplo n.º 3
0
    def get_assertion_details(self, entry):
        """
        Return highlighted patterns within the
        string, if there is a match.
        """

        string = entry.string
        pattern = "Pattern: `{}`{}".format(entry.pattern, os.linesep)

        if entry.match_indexes:
            curr_idx = 0
            parts = []

            for begin, end in entry.match_indexes:
                if begin > curr_idx:
                    parts.append(string[curr_idx:begin])
                parts.append(
                    Color.colored(string[begin:end], self.highlight_color))
                curr_idx = end

            if curr_idx < len(string):
                parts.append(string[curr_idx:])
            return "{}{}".format(pattern, "".join(parts))
        else:
            return "{}{}".format(pattern, string)
Exemplo n.º 4
0
    def get_assertion_details(self, entry):
        """Return fix and dict match_all result representations"""

        result = []
        for match in entry.matches:
            comparison = match["comparison"]
            description = match["description"]
            passed = match["passed"]
            if passed is True:
                coloured = Color.colored("Passed", "green")
            else:
                coloured = Color.colored("Failed", "red")
            result.append("({}) {}".format(coloured, description))
            for row in comparison:
                add_printable_dict_comparison(result, row)
            if result:
                result.append("")
        return str(os.linesep.join(result))
Exemplo n.º 5
0
    def get_assertion_details(self, entry):
        """Return fix and dict match_all result representations"""

        result = []
        for match in entry.matches:
            comparison = match['comparison']
            description = match['description']
            passed = match['passed']
            if passed is True:
                coloured = Color.colored('Passed', 'green')
            else:
                coloured = Color.colored('Failed', 'red')
            result.append('({}) {}'.format(coloured, description))
            for row in comparison:
                add_printable_dict_comparison(result, row)
            if result:
                result.append('')
        return str(os.linesep.join(result))
Exemplo n.º 6
0
 def get_assertion_details(self, entry):
     """Render `condition` attribute as well, if it exists"""
     msg = super(RegexFindIterRenderer, self).get_assertion_details(entry)
     if entry.condition_match is not None:
         msg += '{}Condition: {}'.format(
             os.linesep,
             Color.colored(
                 entry.condition,
                 color='green' if entry.condition_match else 'red'))
     return msg