Best Python code snippet using yandex-tank
schedule.py
Source:schedule.py  
...20        interval = 1000.0 / self.rps21        return (22            int(i * interval)23            for i in range(0, int(self.rps * self.duration / 1000)))24    def rps_at(self, t):25        '''Return rps for second t'''26        if t <= self.duration:27            return self.rps28        else:29            return 030    def get_duration(self):31        '''Return step duration'''32        return self.duration33    def __len__(self):34        '''Return total ammo count'''35        return self.duration / 1000 * self.rps36    def get_rps_list(self):37        return [(int(self.rps), self.duration / 1000)]38    def __repr__(self):39        return 'const(%s, %s)' % (self.rps, self.duration / 1000)40class Line(object):41    '''Load plan with linear load'''42    def __init__(self, minrps, maxrps, duration):43        self.minrps = float(minrps)44        self.maxrps = float(maxrps)45        self.duration = duration / 1000.046        self.b = self.minrps47        self.k = (self.maxrps - self.minrps) / self.duration48    def ts(self, n):49            _, root2 = solve_quadratic(self.k / 2.0, self.b, -n)50            return int(root2 * 1000)51    def __iter__(self):52        return (self.ts(n) for n in range(0, self.__len__()))53    def rps_at(self, t):54        '''Return rps for second t'''55        if t <= self.duration:56            return self.minrps + float(57                self.maxrps - self.minrps) * t / self.duration58        else:59            return 060    def get_duration(self):61        '''Return step duration'''62        return int(self.duration * 1000)63    def __len__(self):64        '''Return total ammo count'''65        return int(self.k / 2.0 * (self.duration ** 2) + self.b * self.duration)66    def get_float_rps_list(self):67        '''68        get list of constant load parts (we have no constant load at all,69        but tank will think so), with parts durations (float)70        '''71        int_rps = range(int(self.minrps), int(self.maxrps) + 1)72        step_duration = float(self.duration) / len(int_rps)73        return [(rps, int(step_duration)) for rps in int_rps]74    def get_rps_list(self):75        '''76        get list of each second's rps77        '''78        seconds = range(0, int(self.duration))79        rps_groups = groupby([int(self.rps_at(t))80                              for t in seconds], lambda x: x)81        rps_list = [(rps, len(list(rpl))) for rps, rpl in rps_groups]82        return rps_list83class Composite(object):84    '''Load plan with multiple steps'''85    def __init__(self, steps):86        self.steps = steps87    def __iter__(self):88        base = 089        for step in self.steps:90            for ts in step:91                yield ts + base92            base += step.get_duration()93    def get_duration(self):...load_plan.py
Source:load_plan.py  
...13        if self.rps == 0:14            return iter([])15        interval = 1000000 / self.rps16        return (i * interval for i in xrange(0, self.rps * self.duration))17    def rps_at(self, t):18        '''Return rps for second t'''19        if t <= self.duration:20            return self.rps21        else:22            return 023    def get_duration(self):24        '''Return step duration'''25        return self.duration26    def __len__(self):27        '''Return total ammo count'''28        return self.duration * self.rps29class Line(object):30    '''Load plan with linear load'''31    def __init__(self, minrps, maxrps, duration):32        self.minrps = minrps33        self.maxrps = maxrps34        self.duration = duration35        self.k = float(self.maxrps - self.minrps) / self.duration36        self.b = 1 + 2 * self.minrps / self.k37    def __iter__(self):38        k = self.k39        b = self.b40        #FIXME: does not work for negative k (minrps > maxrps)41        if k < 0:42            raise NotImplementedError("We have no support for descending linear load yet")43        '''44        Solve equation:45        n(t) = k/2 * t^2 + (k/2 + r0) * t46        where r(t) = k(t + 1/2) + r0 -- rps47        r0 is initial rps.48        '''49        def timestamp(n):50            return int((math.sqrt(b ** 2 + 8 * n / k) - b) * 500000)  # (sqrt(b^2 + 8 * n / k) - b) / 2 -- time in seconds51        ''' Find ammo count given the time '''52        def number(t):53            return int(k * (t ** 2) / 2 + (k / 2 + self.minrps) * self.duration)54        return (timestamp(n) for n in xrange(0, self.__len__()))55    def rps_at(self, t):56        '''Return rps for second t'''57        if t <= self.duration:58            return self.minrps + float(self.maxrps - self.minrps) * t / self.duration59        else:60            return 061    def get_duration(self):62        '''Return step duration'''63        return self.duration64    def __len__(self):65        '''Return total ammo count'''66        return int(self.k * (self.duration ** 2) / 2 + (self.k / 2 + self.minrps) * self.duration)67class Composite(object):68    '''Load plan with multiple steps'''69    def __init__(self, steps):...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
