Example #1
0
    def print_profile(self, threshold):
        '''Prints the 10 slowest topics that took longer than `threshold`
        to test.
        '''
        '''Prints the 10 slowest topics that took longer than
        `threshold` to test.

        '''

        MAX_PATH_SIZE = 40
        topics = self.result.get_worst_topics(number=10, threshold=threshold)

        if topics:
            print(self.header('Slowest Topics'))

            table_header = yellow('  {0}'.format(dim('#')))
            table_header += yellow(
                '  Elapsed     Context File Path                         ')
            table_header += yellow('  Context Name')
            print(table_header)

            for index, topic in enumerate(topics):
                name = self.under_split(topic['context'])
                name = self.camel_split(name)

                topic['path'] = os.path.realpath(topic['path'])
                topic['path'] = '{0!s}'.format(topic['path'])
                topic['path'] = os.path.relpath(topic['path'],
                                                os.path.abspath(os.curdir))

                data = {
                    'number':
                    '{number:#2}'.format(number=index + 1),
                    'time':
                    '{time:.05f}s'.format(time=topic['elapsed']),
                    'path':
                    '{path:<{width}}'.format(
                        path=topic['path'][-MAX_PATH_SIZE:],
                        width=MAX_PATH_SIZE),
                    'name':
                    '{name}'.format(name=name),
                }

                for k, v in data.items():
                    if k == 'number':
                        colorized = blue
                    if k == 'time':
                        colorized = green
                    if k == 'path':
                        colorized = lambda x: dim(white(x))
                    if k == 'name':
                        colorized = green

                    data[k] = colorized(v)

                print(' {number}  {time}{0}{path}{0}{name}'.format(
                    4 * ' ', **data))

            print()
Example #2
0
    def print_profile(self, threshold):
        '''Prints the 10 slowest topics that took longer than `threshold`
        to test.
        '''

        '''Prints the 10 slowest topics that took longer than
        `threshold` to test.

        '''

        MAX_PATH_SIZE = 40
        topics = self.result.get_worst_topics(number=10, threshold=threshold)

        if topics:
            print(self.header('Slowest Topics'))

            table_header = yellow('  {0}'.format(dim('#')))
            table_header += yellow('  Elapsed     Context File Path                         ')
            table_header += yellow('  Context Name')
            print(table_header)

            for index, topic in enumerate(topics):
                name = self.under_split(topic['context'])
                name = self.camel_split(name)

                topic['path'] = os.path.realpath(topic['path'])
                topic['path'] = '{0!s}'.format(topic['path'])
                topic['path'] = os.path.relpath(topic['path'], os.path.abspath(os.curdir))

                data = {
                    'number': '{number:#2}'.format(number=index + 1),
                    'time': '{time:.05f}s'.format(time=topic['elapsed']),
                    'path': '{path:<{width}}'.format(
                        path=topic['path'][-MAX_PATH_SIZE:],
                        width=MAX_PATH_SIZE),
                    'name': '{name}'.format(name=name),
                }

                for k, v in data.items():
                    if k == 'number':
                        colorized = blue
                    if k == 'time':
                        colorized = green
                    if k == 'path':
                        colorized = lambda x: dim(white(x))
                    if k == 'name':
                        colorized = green

                    data[k] = colorized(v)

                print(
                    ' {number}  {time}{0}{path}{0}{name}'.format(
                        4 * ' ',
                        **data)
                    )

            print()
Example #3
0
    def format_class_coverage(self, cover_character, klass, space1, progress, coverage, space2, lines, cover_threshold):
        '''Accepts coverage data for a class and returns a formatted string (intended for
        humans).
        '''
        #   FIXME:
        #       Doesn't this *actually* print coverage for a module, and not a class?

        # preprocess raw data...
        klass = klass.lstrip('.')
        klass = blue(klass)

        MET_THRESHOLD = coverage >= cover_threshold

        coverage = '{prefix}{coverage:.1%}'.format(
            prefix=' ' if (coverage > 0.000) else '',
            coverage=coverage
        )

        if MET_THRESHOLD:
            coverage = bold(coverage)

        coverage = white(coverage)

        # ...then format
        return ' {0} {klass}{space1}\t{progress}{coverage}{space2} {lines}'.format(
            # TODO:
            #   * remove manual spacing, use .format() alignment
            cover_character,
            klass=klass,
            space1=space1,
            progress=dim('•' * progress),
            coverage=coverage,
            space2=space2,
            lines=lines
        )
Example #4
0
    def format_class_coverage(self, cover_character, klass, space1, progress,
                              coverage, space2, lines, cover_threshold):
        '''Accepts coverage data for a class and returns a formatted string (intended for
        humans).
        '''
        #   FIXME:
        #       Doesn't this *actually* print coverage for a module, and not a class?

        # preprocess raw data...
        klass = klass.lstrip('.')
        klass = blue(klass)

        MET_THRESHOLD = coverage >= cover_threshold

        coverage = '{prefix}{coverage:.1%}'.format(prefix=' ' if
                                                   (coverage > 0.000) else '',
                                                   coverage=coverage)

        if MET_THRESHOLD:
            coverage = bold(coverage)

        coverage = white(coverage)

        # ...then format
        return ' {0} {klass}{space1}\t{progress}{coverage}{space2} {lines}'.format(
            # TODO:
            #   * remove manual spacing, use .format() alignment
            cover_character,
            klass=klass,
            space1=space1,
            progress=dim('•' * progress),
            coverage=coverage,
            space2=space2,
            lines=lines)