Best Python code snippet using slash
main.py
Source:main.py  
...62            yield63            pstats.Stats(pr).strip_dirs().sort_stats(SortKey.CUMULATIVE).print_stats(20)64@dynamic_commands("pkm run")65def pkm_run(cmd: Command, next_args: ArgumentsBuffer) -> List[CommandDef]:66    next_ = next_args.peek_or_none()67    context = Context.of(cmd)68    @command("", positional("cmd-and-args", n_values="*"))69    def os_exec(cmd: Command):70        if not (caa := cmd.cmd_and_args):71            raise UnsupportedOperationException("command is required to be executed")72        def on_environment(env: Environment):73            with env.activate():74                restore_cursor()75                sys.exit(execvpe(caa[0], caa[1:], os.environ))76        def on_project(project_: Project):77            on_environment(project_.attached_environment)78        context.run(**locals())79    if next_ is None or not next_.startswith("@"):80        return command_definitions_from([os_exec])81    if not (project := context.lookup_project()):82        raise UnsupportedOperationException("tasks can only be executed in project context")83    @command("", positional("task"), positional("args", n_values="*", default=[]))84    def task_exec(cmd: Command):85        TasksExecutor.execute(project, cmd.task, cmd.args)86    return command_definitions_from([task_exec])87@dynamic_commands('pkm new')88def pkm_new(_: Command, next_args: ArgumentsBuffer) -> List[CommandDef]:89    tr = TemplateRunner()90    if template_name := next_args.peek_or_none():91        try:92            return [with_gc_context(tr.load_template(template_name)).as_command(template_name)]93        except:94            ...95    names = tr.templates_in_namespace()96    if template_name and (filtered := [it for it in names if it.startswith(template_name)]):97        names = filtered98    return [with_gc_context(tr.load_template(it)).as_command(it) for it in names]99@command(100    'pkm install',101    option("-o, --optional", default=None, help="optional group to use (only for projects)"),102    flag("-f, --force", help="forcefully remove and reinstall the given pacakges"),103    flag("-a, --app", help="install package in containerized application mode"),104    flag("-u, --update", help="update the given packages if already installed"),...iteration.py
Source:iteration.py  
...17                raise StopIteration()18            return returned19        return next(self._iterator)20    __next__ = next21    def peek_or_none(self):22        if self.has_next():23            return self.peek()24        return None25    def peek(self):26        if self._peeked is _NOTHING:27            self._peeked = next(self._iterator, _END)28        if self._peeked is _END:29            raise StopIteration()30        return self._peeked31    def has_next(self):32        try:33            self.peek()34        except StopIteration:35            return False...test_iteration.py
Source:test_iteration.py  
...39            if i == len(objects) - 1:40                assert not it.has_next()41                with pytest.raises(StopIteration):42                    it.peek()43                assert it.peek_or_none() is None44            else:45                assert it.has_next()46                assert it.peek() is objects[(i + 1)]47                assert it.peek_or_none() is objects[(i + 1)]48def test_cartesian_dict():49    params = {50        'a': [1, 2, 3],51        'b': [4, 5],52        'c': [6, 7],53    }54    assert set(frozenset(x.items()) for x in iter_cartesian_dicts(params)) == \55        set(frozenset([('a', a_value), ('b', b_value), ('c', c_value)])56            for a_value, b_value, c_value in itertools.product(params['a'], params['b'], params['c']))57@pytest.fixture(params=[True, False])58def use_iterator(request):59    return request.param60@pytest.fixture61def objects(use_iterator):...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!!
