This file is indexed.

/usr/lib/python2.7/dist-packages/pyvows/result.py is in python-pyvows 2.1.0-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# -*- coding: utf-8 -*-
'''Contains `VowsResult` class, which collects the results of
each vow.

'''

# pyvows testing engine
# https://github.com/heynemann/pyvows

# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 Bernardo Heynemann heynemann@gmail.com

#-------------------------------------------------------------------------------


class VowsResult(object):
    '''Collects success/failure/total statistics (as well as elapsed
    time) for the outcomes of tests.

    Only one instance of this class is created when PyVows is run.

    '''

    def __init__(self):
        self.contexts = []
        self.elapsed_time = 0.0

    def _count_contexts(self, contexts=None, count_func=lambda context: 1):
        '''Used interally for class properties
        `total_test_count`, `successful_tests`, and `errored_tests`.

        '''
        #   TODO
        #       Reevaluate whether `count_func` should have a default value
        #       (AFAICT the default is never used. It makes more sense
        #       to me if it had no default, or defaulted to `None`.
        context_count = 0

        for context in contexts:
            context_count += count_func(context)
            context_count += self._count_contexts(
                contexts=context['contexts'],
                count_func=count_func
            )

        return context_count

    def _get_topic_times(self, contexts=None):
        '''Returns a dict describing how long testing took for
        each topic in `contexts`.

        '''
        topic_times = []

        if contexts is None:
            contexts = self.contexts

        for context in contexts:
            topic_times.append({
                'context': context['name'],
                'path':    context['filename'],
                'elapsed': context['topic_elapsed']
            })
            ctx_topic_times = self._get_topic_times(context['contexts'])
            topic_times.extend(ctx_topic_times)

        return topic_times

    @property
    def successful(self):
        '''Returns a boolean, indicating whether the current
        `VowsResult` was 100% successful.

        '''
        return self.successful_tests + self.skipped_tests == self.total_test_count

    @property
    def total_test_count(self):
        '''Returns the total number of tests.'''
        return self.successful_tests + self.errored_tests + self.skipped_tests

    @staticmethod
    def test_is_successful(test):
        return not (test['error'] or test['skip'])

    @property
    def successful_tests(self):
        '''Returns the number of tests that passed.'''
        return self._count_contexts(
            contexts=self.contexts,
            count_func=lambda context: (
                len([t for t in context['tests'] if self.test_is_successful(t)])
                + (0 if (context['error'] or context['skip']) else 1)
            )
        )

    @property
    def errored_tests(self):
        '''Returns the number of tests that failed.'''
        return self._count_contexts(
            contexts=self.contexts,
            count_func=lambda context: (
                len([t for t in context['tests'] if t['error']])
                + (1 if context['error'] else 0)
            )
        )

    @property
    def skipped_tests(self):
        '''Returns the number of tests that were skipped'''
        return self._count_contexts(
            contexts=self.contexts,
            count_func=lambda context: (
                len([t for t in context['tests'] if t['skip']])
                + (1 if context['skip'] else 0)
            )
        )

    def eval_context(self, context):
        '''Returns a boolean indicating whether `context` tested
        successfully.

        '''
        succeeded = True

        # Success only if there wasn't an error in setup, topic or teardown
        succeeded = succeeded and (not context.get('error', None))

        # Success only if all subcontexts succeeded
        for context in context['contexts']:
            succeeded = succeeded and self.eval_context(context)

        # Success only if all tests succeeded
        for test in context['tests']:
            succeeded = succeeded and not test['error']

        return succeeded

    def get_worst_topics(self, number=10, threshold=0.1):
        '''Returns the top `number` slowest topics which took longer
        than `threshold` to test.

        '''
        times = [
            time for time in self._get_topic_times()
            if time['elapsed'] > 0 and time['elapsed'] >= threshold
        ]
        times.sort(key=lambda x: x['elapsed'], reverse=True)
        return times[:number]