Best Python code snippet using Airtest
runner.py
Source:runner.py  
...64    def exec_other_script(cls, scriptpath):65        """run other script in test script"""66        warnings.simplefilter("always")67        warnings.warn("please use using() api instead.", PendingDeprecationWarning)68        def _sub_dir_name(scriptname):69            dirname = os.path.splitdrive(os.path.normpath(scriptname))[-1]70            dirname = dirname.strip(os.path.sep).replace(os.path.sep, "_").replace(cls.SCRIPTEXT, "_sub")71            return dirname72        def _copy_script(src, dst):73            if os.path.isdir(dst):74                shutil.rmtree(dst, ignore_errors=True)75            os.mkdir(dst)76            for f in os.listdir(src):77                srcfile = os.path.join(src, f)78                if not (os.path.isfile(srcfile) and f.endswith(cls.TPLEXT)):79                    continue80                dstfile = os.path.join(dst, f)81                shutil.copy(srcfile, dstfile)82        # find script in PROJECT_ROOT83        scriptpath = os.path.join(ST.PROJECT_ROOT, scriptpath)84        # copy submodule's images into sub_dir85        sub_dir = _sub_dir_name(scriptpath)86        sub_dirpath = os.path.join(cls.args.script, sub_dir)87        _copy_script(scriptpath, sub_dirpath)88        # read code89        pyfilename = os.path.basename(scriptpath).replace(cls.SCRIPTEXT, ".py")90        pyfilepath = os.path.join(scriptpath, pyfilename)91        pyfilepath = os.path.abspath(pyfilepath)92        with open(pyfilepath, 'r', encoding='utf8') as f:93            code = f.read()94        # replace tpl filepath with filepath in sub_dir95        code = re.sub("[\'\"](\w+.png)[\'\"]", "\"%s/\g<1>\"" % sub_dir, code)96        exec(compile(code.encode("utf8"), pyfilepath, 'exec'), cls.scope)97def setup_by_args(args):98    # init devices99    if isinstance(args.device, list):...airtest_runner.py
Source:airtest_runner.py  
...60    def exec_other_script(cls, scriptpath):61        """run other script in test script"""62        warnings.simplefilter("always")63        warnings.warn("please use using() api instead.", PendingDeprecationWarning)64        def _sub_dir_name(scriptname):65            dirname = os.path.splitdrive(os.path.normpath(scriptname))[-1]66            dirname = dirname.strip(os.path.sep).replace(os.path.sep, "_").replace(cls.SCRIPTEXT, "_sub")67            return dirname68        def _copy_script(src, dst):69            if os.path.isdir(dst):70                shutil.rmtree(dst, ignore_errors=True)71            os.mkdir(dst)72            for f in os.listdir(src):73                srcfile = os.path.join(src, f)74                if not (os.path.isfile(srcfile) and f.endswith(cls.TPLEXT)):75                    continue76                dstfile = os.path.join(dst, f)77                shutil.copy(srcfile, dstfile)78        # find script in PROJECT_ROOT79        scriptpath = os.path.join(ST.PROJECT_ROOT, scriptpath)80        # copy submodule's images into sub_dir81        sub_dir = _sub_dir_name(scriptpath)82        sub_dirpath = os.path.join(cls.args.script, sub_dir)83        _copy_script(scriptpath, sub_dirpath)84        # read code85        pyfilename = os.path.basename(scriptpath).replace(cls.SCRIPTEXT, ".py")86        pyfilepath = os.path.join(scriptpath, pyfilename)87        pyfilepath = os.path.abspath(pyfilepath)88        with open(pyfilepath, 'r', encoding='utf8') as f:89            code = f.read()90        # replace tpl filepath with filepath in sub_dir91        code = re.sub("[\'\"](\w+.png)[\'\"]", "\"%s/\g<1>\"" % sub_dir, code)92        exec(compile(code.encode("utf8"), pyfilepath, 'exec'), cls.scope)93def setup_by_args(args):94    # init devices95    if isinstance(args.device, list):...initializer.py
Source:initializer.py  
...34        MacMaker.make_mac(self.c['generate']['config'])35    def _make_phantom(self):36        from .phantom import PhantomBinFileMaker37        PhantomBinFileMaker(self.fs, self.c['phantom']).make()38    def _sub_dir_name(self, i):39        return '{name}.{did}'.format(name=self.c_full['split']['name'], did=i)40    @property41    def _nb_sub_dirs(self):42        return self.c_full['split']['nb_split']43    def _make_subdirs(self):44        for i in range(self._nb_sub_dirs):45            self.fs.makedir(self._sub_dir_name(i), recreate=True)46    def _make_map_shell_scripts(self):47        from .shell import ShellScriptMaker48        ssm = ShellScriptMaker(self.fs, self.c_full)49        ssm.make()50    def _copy_sources_to_subdirs(self):51        from dxpy import batch52        from fs.copy import copy_file53        all_sources = batch.FilesFilter(['*']).lst(self.fs)54        for i in range(self._nb_sub_dirs):55            with self.fs.opendir(self._sub_dir_name(i)) as d:56                for f in all_sources:57                    copy_file(self.fs, f, d, f)58    def pre_sub(self):59        if 'source' in self.c:60            self._copy_sources_from_template()61        if 'generate' in self.c:62            self._make_mac()63        if 'phantom' in self.c:64            self._make_phantom()65    def make_sub(self):66        self._make_subdirs()67        self._copy_sources_to_subdirs()...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!!
