예제 #1
0
    def test_windows_fallback(self):  # pylint: disable=no-self-use
        platform = sys.platform
        sys.platform = "windows"

        assert pretty.get_terminal_size() == (80, 24)

        sys.platform = platform
예제 #2
0
    def test_windows_fallback(self):    # pylint: disable=no-self-use
        platform = sys.platform
        sys.platform = 'windows'

        eq_(pretty.get_terminal_size(), (80, 24))

        sys.platform = platform
예제 #3
0
    def test_windows_fallback(self):
        platform = sys.platform
        sys.platform = 'windows'

        eq_(pretty.get_terminal_size(), (80, 24))

        sys.platform = platform
예제 #4
0
    def test_windows_fallback(self):  # pylint: disable=no-self-use
        platform = sys.platform
        sys.platform = 'windows'

        eq_(pretty.get_terminal_size(), (80, 24))

        sys.platform = platform
예제 #5
0
    def test_windows_fallback(self):
        platform = sys.platform
        sys.platform = 'windows'

        eq_(pretty.get_terminal_size(), (80, 24))

        sys.platform = platform
예제 #6
0
    def test_termios_fallback(self):
        try:
            import termios
            return
        except ImportError:
            pass

        eq_(pretty.get_terminal_size(), (80, 24))
예제 #7
0
    def test_termios_fallback(self):
        try:
            import termios
            return
        except ImportError:
            pass

        eq_(pretty.get_terminal_size(), (80, 24))
예제 #8
0
    def test_termios_fallback(self):  # pylint: disable=no-self-use
        try:
            import termios
            return
        except ImportError:
            pass

        eq_(pretty.get_terminal_size(), (80, 24))
예제 #9
0
    def test_termios_fallback(self):    # pylint: disable=no-self-use
        try:
            import termios
            return
        except ImportError:
            pass

        eq_(pretty.get_terminal_size(), (80, 24))
예제 #10
0
    def test_termios_fallback(self):
        try:
            __pychecker__ = "unusednames=termios"
            import termios
            return
        except ImportError:
            pass

        eq_(pretty.get_terminal_size(), (80, 24))
예제 #11
0
    def test_happy_path(self):
        try:
            import termios
        except ImportError:
            return

        self.ioctl.return_value = struct.pack('HHHH', 17, 23, 5, 5)

        eq_(pretty.get_terminal_size(), (23, 17))
        self.ioctl.assert_called_with(0, termios.TIOCGWINSZ, self.zero_struct)
예제 #12
0
    def test_zero_size_fallback(self):
        try:
            import termios
        except ImportError:
            return

        self.ioctl.return_value = self.zero_struct

        eq_(pretty.get_terminal_size(), (80, 24))
        self.ioctl.assert_called_with(0, termios.TIOCGWINSZ, self.zero_struct)
예제 #13
0
    def test_zero_size_fallback(self):
        try:
            import termios
        except ImportError:
            return

        self.ioctl.return_value = self.zero_struct

        eq_(pretty.get_terminal_size(), (80, 24))
        self.ioctl.assert_called_with(0, termios.TIOCGWINSZ, self.zero_struct)
예제 #14
0
    def test_happy_path(self):
        try:
            import termios
        except ImportError:
            return

        self.ioctl.return_value = struct.pack('HHHH', 17, 23, 5, 5)

        eq_(pretty.get_terminal_size(), (23, 17))
        self.ioctl.assert_called_with(0, termios.TIOCGWINSZ, self.zero_struct)
예제 #15
0
    def test_exception_in_ioctl(self):
        try:
            import termios
        except ImportError:
            return

        def raiser(*args, **kwargs):    # pylint: disable=unused-argument
            raise Exception('yeehar!')

        self.ioctl.side_effect = raiser

        eq_(pretty.get_terminal_size(), (80, 24))
        self.ioctl.assert_called_with(0, termios.TIOCGWINSZ, self.zero_struct)
예제 #16
0
    def test_exception_in_ioctl(self):
        try:
            import termios
        except ImportError:
            return

        def raiser(*args, **kwargs):  # pylint: disable=unused-argument
            raise Exception("yeehar!")

        self.ioctl.side_effect = raiser

        assert pretty.get_terminal_size() == (80, 24)
        self.ioctl.assert_called_with(0, termios.TIOCGWINSZ, self.zero_struct)
예제 #17
0
    def test_exception_in_ioctl(self):
        try:
            import termios
        except ImportError:
            return

        def raiser(*args, **kwargs):
            raise Exception('yeehar!')

        self.ioctl.side_effect = raiser

        eq_(pretty.get_terminal_size(), (80, 24))
        self.ioctl.assert_called_with(0, termios.TIOCGWINSZ, self.zero_struct)
예제 #18
0
class TravisFormatter(PlainFormatter):
    """
    Provides a simple plain formatter without coloring/formatting.
    The formatter displays now also:

       * multi-line text (doc-strings)
       * table
       * tags (maybe)
    """
    name = "travis"
    description = "Very basic formatter with maximum compatibility but shortened line lengths for Travis"

    LINE_WIDTH = (130
                  if 'CI' in os.environ else max(get_terminal_size()[0], 130))
    SHOW_TAGS = True

    def write_tags(self, tags, indent=None):
        if tags and self.show_tags:
            indent = indent or ""

            if 'test-cluster-1' in tags:
                tags = set(tags) - set(['test-cluster-1'])

            text = textwrap.fill(' '.join([
                '@' + tag
                for tag in sorted(tags,
                                  key=lambda t: (t.rjust(10, '0').rjust(
                                      30, '~') if t.isdigit() else t))
            ]),
                                 self.LINE_WIDTH,
                                 initial_indent=indent,
                                 subsequent_indent=indent + '  ')
            self.stream.write(text + '\n')

    def result(self, step):
        """
        Process the result of a step (after step execution).

        :param step:   Step object with result to process.
        """
        step = self.steps.pop(0)
        indent = make_indentation(2 * self.indent_size)
        if self.show_aligned_keywords:
            # -- RIGHT-ALIGN KEYWORDS (max. keyword width: 6):
            text = u"%s%6s %s" % (indent, step.keyword, step.name)
        else:
            text = u"%s%s %s" % (indent, step.keyword, step.name)
        text = escapes[step.status.name] + textwrap.shorten(
            text, width=self.LINE_WIDTH - 30) + escapes['reset'] + ' '
        self.stream.write(text)

        status_text = ': '
        status_text += {
            'passed': u'\u2713',
            'failed': u'\u26A0'
        }[step.status.name]

        if self.show_timings:
            status_text += " in %0.3fs" % step.duration

        unicode_errors = 0
        if step.error_message:
            try:
                self.stream.write(u"%s\n%s\n" %
                                  (status_text, step.error_message))
            except UnicodeError as e:
                unicode_errors += 1
                self.stream.write(u"%s\n" % status_text)
                self.stream.write(u"%s while writing error message: %s\n" % \
                                  (e.__class__.__name__, e))
                if self.RAISE_OUTPUT_ERRORS:
                    raise
        else:
            self.stream.write(u"%s\n" % status_text)

        if self.show_multiline:
            if step.text:
                try:
                    self.doc_string(step.text)
                except UnicodeError as e:
                    unicode_errors += 1
                    self.stream.write(u"%s while writing docstring: %s\n" % \
                                      (e.__class__.__name__, e))
                    if self.RAISE_OUTPUT_ERRORS:
                        raise
            if step.table:
                self.table(step.table)