コード例 #1
0
 def result(self, result):
     if not self.monochrome:
         lines = self.step_lines + 1
         if self.show_multiline:
             if result.table:
                 lines += self.table_lines
             if result.text:
                 lines += self.text_lines
         self.stream.write(up(lines))
         arguments = []
         location = None
         if self._match:
             arguments = self._match.arguments
             location = self._match.location
         self.print_step(result.status, arguments, location, True)
     if result.error_message:
         msg = result.error_message.strip()
         if isinstance(msg, str):
             try:
                 msg = msg.decode('ascii')
             except UnicodeDecodeError:
                 try:
                     msg = msg.decode('utf-8')
                 except UnicodeDecodeError:
                     try:
                         msg = msg.decode('latin1')
                     except UnicodeDecodeError:
                         msg = msg.decode('utf-8', errors='replace')
         indented = indent(msg, u'      ')
         self.stream.write(indented.encode('utf-8', errors='replace'))
         self.stream.write('\n\n')
     self.stream.flush()
コード例 #2
0
 def result(self, result):
     if not self.monochrome:
         lines = self.step_lines + 1
         if self.show_multiline:
             if result.table:
                 lines += self.table_lines
             if result.text:
                 lines += self.text_lines
         self.stream.write(up(lines))
         arguments = []
         location = None
         if self._match:
             arguments = self._match.arguments
             location = self._match.location
         self.print_step(result.status, arguments, location, True)
     if result.error_message:
         msg = result.error_message.strip()
         if isinstance(msg, str):
             try:
                 msg = msg.decode('ascii')
             except UnicodeDecodeError:
                 try:
                     msg = msg.decode('utf-8')
                 except UnicodeDecodeError:
                     try:
                         msg = msg.decode('latin1')
                     except UnicodeDecodeError:
                         msg = msg.decode('utf-8', errors='replace')
         indented = indent(msg, u'      ')
         self.stream.write(indented)
         self.stream.write('\n\n')
     self.stream.flush()
コード例 #3
0
ファイル: test_ansi_escapes.py プロジェクト: zrbhavsar/behave
class StripEscapesTest(unittest.TestCase):
    ALL_COLORS = list(ansi_escapes.colors.keys())
    CURSOR_UPS = [ansi_escapes.up(count) for count in range(10)]
    TEXTS = [
        u"lorem ipsum",
        u"Alice\nBob\nCharly\nDennis",
    ]

    @classmethod
    def colorize(cls, text, color):
        color_escape = ""
        if color:
            color_escape = ansi_escapes.colors[color]
        return color_escape + text + ansi_escapes.escapes["reset"]

    @classmethod
    def colorize_text(cls, text, colors=None):
        if not colors:
            colors = []
        colors_size = len(colors)
        color_index = 0
        colored_chars = []
        for char in text:
            color = colors[color_index]
            colored_chars.append(cls.colorize(char, color))
            color_index += 1
            if color_index >= colors_size:
                color_index = 0
        return "".join(colored_chars)

    def test_should_return_same_text_without_escapes(self):
        for text in self.TEXTS:
            tools.eq_(text, ansi_escapes.strip_escapes(text))

    def test_should_return_empty_string_for_any_ansi_escape(self):
        # XXX-JE-CHECK-PY23: If list() is really needed.
        for text in list(ansi_escapes.colors.values()):
            tools.eq_("", ansi_escapes.strip_escapes(text))
        for text in list(ansi_escapes.escapes.values()):
            tools.eq_("", ansi_escapes.strip_escapes(text))

    def test_should_strip_color_escapes_from_text(self):
        for text in self.TEXTS:
            colored_text = self.colorize_text(text, self.ALL_COLORS)
            tools.eq_(text, ansi_escapes.strip_escapes(colored_text))
            self.assertNotEqual(text, colored_text)

            for color in self.ALL_COLORS:
                colored_text = self.colorize(text, color)
                tools.eq_(text, ansi_escapes.strip_escapes(colored_text))
                self.assertNotEqual(text, colored_text)

    def test_should_strip_cursor_up_escapes_from_text(self):
        for text in self.TEXTS:
            for cursor_up in self.CURSOR_UPS:
                colored_text = cursor_up + text + ansi_escapes.escapes["reset"]
                tools.eq_(text, ansi_escapes.strip_escapes(colored_text))
                self.assertNotEqual(text, colored_text)
コード例 #4
0
 def result(self, result):
     if not self.monochrome:
         lines = self.step_lines + 1
         if self.show_multiline:
             if result.table:
                 lines += len(result.table.rows) + 1
             if result.text:
                 lines += len(result.text.splitlines()) + 2
         self.stream.write(up(lines))
     arguments = []
     location = None
     if self._match:
         arguments = self._match.arguments
         location = self._match.location
     self.print_step(result.status, arguments, location, True)
     if result.error_message:
         self.stream.write(indent(result.error_message.strip(), u'      '))
         self.stream.write('\n\n')
     self.stream.flush()
コード例 #5
0
ファイル: pretty.py プロジェクト: akinnane/behave
 def result(self, result):
     if not self.monochrome:
         lines = self.step_lines + 1
         if self.show_multiline:
             if result.table:
                 lines += len(result.table.rows) + 1
             if result.text:
                 lines += len(result.text.splitlines()) + 2
         self.stream.write(up(lines))
         arguments = []
         location = None
         if self._match:
             arguments = self._match.arguments
             location = self._match.location
         self.print_step(result.status, arguments, location, True)
     if result.error_message:
         self.stream.write(indent(result.error_message.strip(), u'      '))
         self.stream.write('\n\n')
     self.stream.flush()
コード例 #6
0
from __future__ import absolute_import
import pytest
from behave.formatter import ansi_escapes
from six.moves import range


# --------------------------------------------------------------------------
# TEST SUPPORT and TEST DATA
# --------------------------------------------------------------------------
TEXTS = [
    u"lorem ipsum",
    u"Alice and Bob",
    u"Alice\nBob",
]
ALL_COLORS = list(ansi_escapes.colors.keys())
CURSOR_UPS = [ansi_escapes.up(count) for count in range(10)]


def colorize(text, color):
    color_escape = ""
    if color:
        color_escape = ansi_escapes.colors[color]
    return color_escape + text + ansi_escapes.escapes["reset"]


def colorize_text(text, colors=None):
    if not colors:
        colors = []
    colors_size = len(colors)
    color_index = 0
    colored_chars = []