How to use do_run_cmd method in localstack

Best Python code snippet using localstack_python

preview_namelists.py

Source: preview_namelists.py Github

copy

Full Screen

1"""2API for preview namelist3"""4from CIME.XML.standard_module_setup import *5import glob, shutil, imp6logger = logging.getLogger(__name__)7def create_dirs(case):8 """9 Make necessary directories for case10 """11 # Get data from XML12 exeroot = case.get_value("EXEROOT")13 libroot = case.get_value("LIBROOT")14 incroot = case.get_value("INCROOT")15 rundir = case.get_value("RUNDIR")16 caseroot = case.get_value("CASEROOT")17 docdir = os.path.join(caseroot, "CaseDocs")18 dirs_to_make = []19 models = case.get_values("COMP_CLASSES")20 for model in models:21 dirname = model.lower()22 dirs_to_make.append(os.path.join(exeroot, dirname, "obj"))23 dirs_to_make.extend([exeroot, libroot, incroot, rundir, docdir])24 for dir_to_make in dirs_to_make:25 if (not os.path.isdir(dir_to_make)):26 try:27 logger.debug("Making dir '%s'" % dir_to_make)28 os.makedirs(dir_to_make)29 except OSError as e:30 expect(False, "Could not make directory '%s', error: %s" % (dir_to_make, e))31 # As a convenience write the location of the case directory in the bld and run directories32 for dir_ in (exeroot, rundir):33 with open(os.path.join(dir_,"CASEROOT"),"w+") as fd:34 fd.write(caseroot+"\n")35def create_namelists(case):36 """37 Create component namelists38 """39 case.flush()40 casebuild = case.get_value("CASEBUILD")41 caseroot = case.get_value("CASEROOT")42 rundir = case.get_value("RUNDIR")43 docdir = os.path.join(caseroot, "CaseDocs")44 # Load modules45 case.load_env()46 logger.info("Creating component namelists")47 # Create namelists - must have cpl last in the list below48 # Note - cpl must be last in the loop below so that in generating its namelist,49 # it can use xml vars potentially set by other component's buildnml scripts50 models = case.get_values("COMP_CLASSES")51 models += [models.pop(0)]52 for model in models:53 model_str = model.lower()54 config_file = case.get_value("CONFIG_%s_FILE" % model_str.upper())55 config_dir = os.path.dirname(config_file)56 if model_str == "cpl":57 compname = "drv"58 else:59 compname = case.get_value("COMP_%s" % model_str.upper())60 cmd = os.path.join(config_dir, "buildnml")61 do_run_cmd = False62 try:63 with open(cmd, 'r') as f:64 first_line = f.readline()65 if "python" in first_line: 66 logger.info(" Calling %s buildnml"%compname)67 mod = imp.load_source("buildnml", cmd)68 mod.buildnml(case, caseroot, compname)69 else:70 raise SyntaxError71 except SyntaxError as detail:72 if 'python' in first_line:73 expect(False, detail)74 else:75 do_run_cmd = True76 except AttributeError:77 do_run_cmd = True78 except:79 raise80 if do_run_cmd:81 logger.info(" Running %s buildnml"%compname)82 case.flush()83 run_cmd_no_fail("%s %s" % (cmd, caseroot), verbose=False)84 # refresh case xml object from file85 case.read_xml() 86 logger.info("Finished creating component namelists")87 # Save namelists to docdir88 if (not os.path.isdir(docdir)):89 os.makedirs(docdir)90 try:91 with open(os.path.join(docdir, "README"), "w") as fd:92 fd.write(" CESM Resolved Namelist Files\n For documentation only DO NOT MODIFY\n")93 except (OSError, IOError) as e:94 expect(False, "Failed to write %s/​README: %s" % (docdir, e))95 for cpglob in ["*_in_[0-9]*", "*modelio*", "*_in",96 "*streams*txt*", "*stxt", "*maps.rc", "*cism.config*"]:97 for file_to_copy in glob.glob(os.path.join(rundir, cpglob)):98 logger.debug("Copy file from '%s' to '%s'" % (file_to_copy, docdir))99 shutil.copy2(file_to_copy, docdir)100 # Copy over chemistry mechanism docs if they exist101 if (os.path.isdir(os.path.join(casebuild, "camconf"))):102 for file_to_copy in glob.glob(os.path.join(casebuild, "camconf", "*chem_mech*")):...

Full Screen

Full Screen

test.py

Source: test.py Github

copy

Full Screen

...23 write_diff(expected, new_expected)24 with open(path + '.output', 'w') as f:25 f.write(new_expected)26 return 027def do_run_cmd(args):28 exit_code = 029 for pattern in args.files if 'files' in args else ['test-snippets/​*.tply']:30 for path in glob(pattern):31 filename = os.path.basename(path)32 print(f"Checking {filename} ...")33 with open(path, 'r') as f:34 contents = f.read()35 actual = templaty.evaluate(contents, filename=path)36 try:37 with open(path + '.output', 'r') as f:38 expected = f.read()39 except FileNotFoundError:40 print(f"Warning: {filename} does not have an expected output. Run 'test.py save {path}' to add it.")41 write_diff('', actual)42 continue43 if actual != expected:44 print("Error: output does not correspond with saved state")45 write_diff(actual, expected)46 exit_code = 147 return exit_code48parser = argparse.ArgumentParser()49subparsers = parser.add_subparsers()50save_parser = subparsers.add_parser('save')51save_parser.add_argument('files', nargs='*', default=['test-snippets/​*.tply'])52save_parser.set_defaults(func=do_save_cmd)53run_parser = subparsers.add_parser('run')54run_parser.add_argument('files', nargs='*', default=['test-snippets/​*.tply'])55run_parser.set_defaults(func=do_run_cmd)56args = parser.parse_args()57if 'func' in args:58 args.func(args)59else:...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

13 Best Java Testing Frameworks For 2023

The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.

QA Innovation – Using the senseshaping concept to discover customer needs

QA Innovation - Using the senseshaping concept to discover customer needsQA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.

Best 23 Web Design Trends To Follow In 2023

Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.

Acquiring Employee Support for Change Management Implementation

Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful