Best Python code snippet using autotest_python
itercools.py
Source:itercools.py  
...346            raise exc(f"{item!r} at position {i}")347        yield item348    if i is None and not allow_empty:349        raise exc("empty sequence")350def check_cmp(cmp, seq, *, allow_empty=False):351    """Wrap a sequence, raising ValueError if the comparison fails.352    >>> list(check_cmp(op.lt, [1, 2]))353    [1, 2]354    >>> list(check_cmp(op.le, [1, 1]))355    [1, 1]356    >>> list(check_cmp(op.lt, [1, 1]))357    Traceback (most recent call last):358      ...359    ValueError: 1 followed by 1 at position 1360    >>> list(check_cmp(op.lt, []))361    Traceback (most recent call last):362      ...363    ValueError: empty sequence364    >>> list(check_cmp(op.lt, [], allow_empty=True))365    []366    """367    it = iter(seq)368    try:369        prev = next(it)370    except StopIteration:371        if allow_empty:372            return373        else:374            raise ValueError("empty sequence")375    yield prev376    for i, item in enumerate(it, start=1):377        if not cmp(prev, item):378            raise ValueError(379                f"{prev!r} followed by {item!r} at position {i}"380            )381        prev = item382        yield item383ensure_monotonic_increasing = partial(check_cmp, op.le)384ensure_strict_monotonic_increasing = partial(check_cmp, op.lt)385ensure_monotonic_decreasing = partial(check_cmp, op.ge)386ensure_strict_monotonic_decreasing = partial(check_cmp, op.gt)387def check_monotonic_increasing(*args, **kwargs):388    return exhaust(check_cmp(*args, **kwargs))389if __name__ == '__main__':390    import doctest...trigger_unittest.py
Source:trigger_unittest.py  
...69            control_type='Client', hosts=['mach1'])70        action(['2.6.21'])71        self.god.check_playback()72    def test_kver_cmp(self):73        def check_cmp(ver1, ver2):74            # function to make sure "cmp" invariants are followed75            cmp_func = trigger.map_action._kver_cmp76            if ver1 != ver2:77                self.assertEquals(cmp_func(ver1, ver2), -1)78                self.assertEquals(cmp_func(ver2, ver1), 1)79            else:80                self.assertEquals(cmp_func(ver1, ver2), 0)81                self.assertEquals(cmp_func(ver2, ver1), 0)82        check_cmp('2.6.20', '2.6.20')83        check_cmp('2.6.20', '2.6.21')84        check_cmp('2.6.20', '2.6.21-rc2')85        check_cmp('2.6.20-rc2-git2', '2.6.20-rc2')86    def test_upload_kernel_config(self):87        tests_map = {88            'mach1': trigger.map_action.machine_info(89                ('test1',), {'2.6.20': 'config1'}),90            'mach3': trigger.map_action.machine_info(91                ('test1',), {'2.6.20': 'config1'})92        }93        action = trigger.map_action(tests_map, 'jobname %s',94                                    upload_kernel_config=True)95        self.assertTrue(isinstance(action._afe, trigger.frontend.AFE))96        action._afe = self.god.create_mock_class(trigger.frontend.AFE, 'AFE')97        control = self._make_control_dict('control contents', is_server=True)98        (action._afe.generate_control_file.expect_call(99            tests=['test1'],...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!!
