Best Python code snippet using ATX
lnd_diags_bc.py
Source:lnd_diags_bc.py
...3940 def title(self):41 return self._title4243 def setup_workdir(self, env, t, scomm):44 """This method sets up the unique working directory for a given diagnostic type45 """46 # create the working directory first before calling the base class prerequisites47 endYr = (int(env['clim_first_yr_'+t]) + int(env['clim_num_yrs_'+t])) - 1 48 subdir = '{0}.{1}-{2}/{3}.{4}_{5}'.format(env['caseid_'+t], env['clim_first_yr_'+t], endYr,self._name.lower(), env['clim_first_yr_'+t], endYr)49 workdir = '{0}/climo/{1}/{2}'.format(env['PTMPDIR_'+t], env['caseid_'+t], subdir)5051 if (scomm.is_manager()):52 print('DEBUG lnd_diags_bc.setup_workdir t = {0}'.format(t))53 print('DEBUG lnd_diags_bc.setup_workdir subdir = {0}'.format(subdir))54 print('DEBUG lnd_diags_bc.setup_workdir first workdir = {0}'.format(workdir))5556 try:57 os.makedirs(workdir)58 os.makedirs(workdir+'/atm')59 os.makedirs(workdir+'/rof')60 except OSError as exception:61 if exception.errno != errno.EEXIST:62 err_msg = 'ERROR: {0} problem accessing the working directory {1}'.format(self.__class__.__name__, workdir)63 raise OSError(err_msg)6465 for model in ('lnd', 'atm', 'rtm'):66 if ('rtm' in model):67 m_dir = 'rof'68 else:69 m_dir = model70 # create symbolic links between the old and new workdir and get the real names of the files71 old_workdir = env['PTMPDIR_'+t]+'/climo/'+env['caseid_'+t]+'/'+env['caseid_'+t]+'.'+str(env['clim_first_yr_'+t])+'-'+str(endYr)+'/'+m_dir72 env['case'+t+'_path_climo'] = workdir7374 print('DEBUG lnd_diags_bc.setup_workdir old_workdir = {0}'.format(old_workdir))75 print('DEBUG lnd_diags_bc.setup_workdir case_t_path_climo = {0}'.format(env['case'+t+'_path_climo']))7677 if 'lnd' in model:78 workdir_mod = workdir79 else:80 workdir_mod = workdir + '/' + m_dir81 # Add links to the new wkrdir that use the expected file names (existing climos have dates, the NCL do not like dates)82 print('DEBUG lnd_diags_bc.setup_workdir workdir_mod = {0}'.format(workdir_mod))83 84 climo_files = glob.glob(old_workdir+'/*.nc') 85 for climo_file in climo_files:86 name_split = climo_file.split('.') # Split on '.'87 if ('-' in name_split[-3]):88 fn = str.join('.',name_split[:len(name_split)-3] + name_split[-2:]) #Piece together w/o the date, but still has old path 89 path_split = fn.split('/') # Remove the path90 new_fn = workdir_mod + '/' +path_split[-1] # Take file name and add it to new path91 rc1, err_msg1 = cesmEnvLib.checkFile(new_fn, 'read')92 if not rc1:93 try:94 os.symlink(climo_file,new_fn)95 except:96 print('INFO lnd_diags_bc.setup_workdir symlink {0} to {1} already exists.'.format(new_fn, climo_file))9798 env['DIAG_BASE'] = env['PTMPDIR_1'] 99 env['PTMPDIR_'+t] = '{0}/climo/{1}/{2}'.format(env['PTMPDIR_'+t], env['caseid_'+t], subdir)100101 if (scomm.is_manager()):102 print('DEBUG lnd_diags_bc.setup_workdir DIAG_BASE = {0}'.format(env['DIAG_BASE']))103 print('DEBUG lnd_diags_bc.setup_workdir PTMPDIR_t {0}'.format(env['PTMPDIR_'+t]))104105 return env106107 def check_prerequisites(self, env, scomm):108 """This method does some generic checks for the prerequisites109 that are common to all diagnostics110 """111 print(' Checking generic prerequisites for land diagnostics.')112 # setup the working directory for each diagnostics class113 env = self.setup_workdir(env, '1', scomm)114 if (env['MODEL_VS_MODEL'] == 'True'):115 env = self.setup_workdir(env, '2', scomm)116117 def run_diagnostics(self, env, scomm):118 """ base method for calling diagnostics119 """120 return121122# todo move these classes to another file123class RecoverableError(RuntimeError):124 pass125126class UnknownDiagType(RecoverableError):127 pass
...
common.py
Source:common.py
...10 >>> os.path.exists(selfdir())11 True12 """13 return os.path.dirname(__file__)14def setup_workdir():15 """16 >>> workdir = setup_workdir()17 >>> assert workdir != '.'18 >>> assert workdir != '/'19 >>> os.path.exists(workdir)20 True21 >>> os.rmdir(workdir)22 """23 return tempfile.mkdtemp(dir="/tmp", prefix="python-fleure-tests-")24def cleanup_workdir(workdir):25 """26 FIXME: Danger!27 >>> workdir = setup_workdir()28 >>> os.path.exists(workdir)29 True30 >>> open(os.path.join(workdir, "workdir.stamp"), 'w').write("OK!\n")31 >>> cleanup_workdir(workdir)32 >>> os.path.exists(workdir)33 False34 """35 assert workdir != '/'36 assert workdir != '.'37 os.system("rm -rf " + workdir)38def dicts_equal(lhs, rhs):39 """40 >>> dicts_equal({}, {})41 True...
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!!