This file is indexed.

/usr/share/pyshared/insanity/arguments.py is in python-insanity 0.0+git20110920.4750a8e8-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
# GStreamer QA system
#
#       arguments.py
#
# Copyright (c) 2007, Edward Hervey <bilboed@bilboed.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

"""
Arguments classes for tests
"""

from insanity.log import debug, info
from insanity.generator import Generator

class Arguments(object):
    """
    Iterable argument lists.

    Takes a list of named arguments and can be iterated to return
    dictionnaries of all the combinations.

    Those arguments can either be :
    * static arguments (ex: int, list, string, etc...), or
    * dynamic arguments (currently only generators).

    If a dynamic arguments produces multiple return values, you need
    to name that argument as the coma-separated concatenation of the
    individual arguments. Ex : "arg1,arg2,arg3"
    """

    def __init__(self, **kwargs):
        self.args = kwargs
        # split out static args from generators
        # generators : (generator, curidx, length)
        self.generators = {}
        self.statics = {}
        for key, value in self.args.iteritems():
            info("key:%s, type:%r" % (key, value))
            if isinstance(value, Generator):
                try:
                    # Checking that the generator is not empty, which can
                    # happen easily if you mistype the filename passed to the
                    # filesystemgenerator for example.
                    iter(value).next()
                except StopIteration:
                    raise ValueError("generator %r for argument %r produced no items" % \
                                     (value, key,))
                self.generators[key] = [value, 0, 0]
            else:
                self.statics[key] = value
        self.genlist = self.generators.keys()
        self._initialized = False
        self.combinations = 1
        self.globalidx = 0

    ## Iterable interface
    def __iter__(self):
        # return a copy
        return Arguments(**self.args)

    def next(self):
        if not self._initialized:
            self._initialize()
        if not self.globalidx < self.combinations:
            raise StopIteration
        # return the next dict of arguments
        # contains a copy of all static arguments
        # plus the next combination of generators
        res = self.statics.copy()
        if self.generators:
            info("we have generators")
            # extend with current generator values
            for key in self.genlist:
                info("key")
                gen, idx = self.generators[key][:2]
                # split generator name
                keys = key.split(",")
                if len(keys) > 1:
                    for i in range(len(keys)):
                        res[keys[i]] = gen[idx][i]
                else:
                    res[keys[0]] = gen[idx]
            # update values
            self._updateGeneratorsPosition()
        # update global idx
        self.globalidx += 1
        return res

    def _updateGeneratorsPosition(self):
        for key in self.genlist:
            # update the position of this generator
            apos = (self.generators[key][1] + 1) % self.generators[key][2]
            self.generators[key][1] = apos
            # if we didn't go over, break, else continue to update next one
            if self.generators[key][1]:
                break

    def _initialize(self):
        # figure out the length of all generators
        debug("initializing")
        cpy = {}
        for key, value in self.generators.iteritems():
            gen, idx, nb = value
            nb = len(gen)
            if nb:
                self.combinations *= nb
            cpy[key] = [gen, idx, nb]
        debug("self.combinations: %d" % self.combinations)
        self.generators = cpy
        self._initialized = True

    def __len__(self):
        if not self._initialized:
            self._initialize()
        return self.combinations

    def current(self):
        """ Returns the current position """
        return self.globalidx

    ## EXTRA METHODS
    ## NOT IMPLEMENTED YET

    def isValidWithTest(self, testclass):
        """
        Checks if all arguments are valid with given test
        """
        raise NotImplementedError