How to use delete_tmp_dir method in autotest

Best Python code snippet using autotest_python

message_compiler.py

Source:message_compiler.py Github

copy

Full Screen

1# Copyright 2015 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4# Runs the Microsoft Message Compiler (mc.exe).5#6# Usage: message_compiler.py <environment_file> [<args to mc.exe>*]7import difflib8import distutils.dir_util9import filecmp10import os11import re12import shutil13import subprocess14import sys15import tempfile16def main():17 env_file, rest = sys.argv[1], sys.argv[2:]18 # Parse some argument flags.19 header_dir = None20 resource_dir = None21 input_file = None22 for i, arg in enumerate(rest):23 if arg == '-h' and len(rest) > i + 1:24 assert header_dir == None25 header_dir = rest[i + 1]26 elif arg == '-r' and len(rest) > i + 1:27 assert resource_dir == None28 resource_dir = rest[i + 1]29 elif arg.endswith('.mc') or arg.endswith('.man'):30 assert input_file == None31 input_file = arg32 # Copy checked-in outputs to final location.33 THIS_DIR = os.path.abspath(os.path.dirname(__file__))34 assert header_dir == resource_dir35 source = os.path.join(THIS_DIR, "..", "..",36 "third_party", "win_build_output",37 re.sub(r'^(?:[^/]+/)?gen/', 'mc/', header_dir))38 distutils.dir_util.copy_tree(source, header_dir, preserve_times=False)39 # On non-Windows, that's all we can do.40 if sys.platform != 'win32':41 return42 # On Windows, run mc.exe on the input and check that its outputs are43 # identical to the checked-in outputs.44 # Read the environment block from the file. This is stored in the format used45 # by CreateProcess. Drop last 2 NULs, one for list terminator, one for46 # trailing vs. separator.47 env_pairs = open(env_file).read()[:-2].split('\0')48 env_dict = dict([item.split('=', 1) for item in env_pairs])49 extension = os.path.splitext(input_file)[1]50 if extension in ['.man', '.mc']:51 # For .man files, mc's output changed significantly from Version 10.0.1506352 # to Version 10.0.16299. We should always have the output of the current53 # default SDK checked in and compare to that. Early out if a different SDK54 # is active. This also happens with .mc files.55 # TODO(thakis): Check in new baselines and compare to 16299 instead once56 # we use the 2017 Fall Creator's Update by default.57 mc_help = subprocess.check_output(['mc.exe', '/?'], env=env_dict,58 stderr=subprocess.STDOUT, shell=True)59 version = re.search(r'Message Compiler\s+Version (\S+)', mc_help).group(1)60 if version != '10.0.15063':61 return62 # mc writes to stderr, so this explicitly redirects to stdout and eats it.63 try:64 tmp_dir = tempfile.mkdtemp()65 delete_tmp_dir = True66 if header_dir:67 rest[rest.index('-h') + 1] = tmp_dir68 header_dir = tmp_dir69 if resource_dir:70 rest[rest.index('-r') + 1] = tmp_dir71 resource_dir = tmp_dir72 # This needs shell=True to search the path in env_dict for the mc73 # executable.74 subprocess.check_output(['mc.exe'] + rest,75 env=env_dict,76 stderr=subprocess.STDOUT,77 shell=True)78 # We require all source code (in particular, the header generated here) to79 # be UTF-8. jinja can output the intermediate .mc file in UTF-8 or UTF-16LE.80 # However, mc.exe only supports Unicode via the -u flag, and it assumes when81 # that is specified that the input is UTF-16LE (and errors out on UTF-882 # files, assuming they're ANSI). Even with -u specified and UTF16-LE input,83 # it generates an ANSI header, and includes broken versions of the message84 # text in the comment before the value. To work around this, for any invalid85 # // comment lines, we simply drop the line in the header after building it.86 # Also, mc.exe apparently doesn't always write #define lines in87 # deterministic order, so manually sort each block of #defines.88 if header_dir:89 header_file = os.path.join(90 header_dir, os.path.splitext(os.path.basename(input_file))[0] + '.h')91 header_contents = []92 with open(header_file, 'rb') as f:93 define_block = [] # The current contiguous block of #defines.94 for line in f.readlines():95 if line.startswith('//') and '?' in line:96 continue97 if line.startswith('#define '):98 define_block.append(line)99 continue100 # On the first non-#define line, emit the sorted preceding #define101 # block.102 header_contents += sorted(define_block, key=lambda s: s.split()[-1])103 define_block = []104 header_contents.append(line)105 # If the .h file ends with a #define block, flush the final block.106 header_contents += sorted(define_block, key=lambda s: s.split()[-1])107 with open(header_file, 'wb') as f:108 f.write(''.join(header_contents))109 # mc.exe invocation and post-processing are complete, now compare the output110 # in tmp_dir to the checked-in outputs.111 diff = filecmp.dircmp(tmp_dir, source)112 if diff.diff_files or set(diff.left_list) != set(diff.right_list):113 print 'mc.exe output different from files in %s, see %s' % (source,114 tmp_dir)115 diff.report()116 for f in diff.diff_files:117 if f.endswith('.bin'): continue118 fromfile = os.path.join(source, f)119 tofile = os.path.join(tmp_dir, f)120 print ''.join(difflib.unified_diff(open(fromfile, 'U').readlines(),121 open(tofile, 'U').readlines(),122 fromfile, tofile))123 delete_tmp_dir = False124 sys.exit(1)125 except subprocess.CalledProcessError as e:126 print e.output127 sys.exit(e.returncode)128 finally:129 if os.path.exists(tmp_dir) and delete_tmp_dir:130 shutil.rmtree(tmp_dir)131if __name__ == '__main__':...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

...59 return 'java'60def ensure_dir_exist(dir_path):61 if not is_dir_exists(dir_path):62 os.makedirs(dir_path)63def delete_tmp_dir(dir_path):64 if not is_dir_exists(dir_path):65 return66 if settings.TMP_DIR in dir_path:67 print("delete dir: {}".format(dir_path))68 try:69 shutil.rmtree(dir_path, ignore_errors=False)70 print("\n")71 except Exception as e:72 delete_tmp_dir(dir_path)73def dump_smali_data_to_csv(app_data, file_path):74 out_dir = os.path.dirname(file_path)75 if not is_dir_exists(out_dir):76 os.makedirs(out_dir)77 is_first_write = True78 if os.access(file_path, os.W_OK):79 is_first_write = False80 with open(file_path, 'a+', encoding="utf-8-sig", newline="") as f:81 csv_writer = csv.writer(f)82 if is_first_write:83 csv_writer.writerow(['MD5', 'filename', 'packageName', 'verNum', 'classLocation', 'riskF', 'broadcastcnt', 'receivercnt'])84 app_info = app_data["app_info"]85 apk_md5 = app_data["apk_md5"]86 file_name = app_data["file_name"]...

Full Screen

Full Screen

test_bammend.py

Source:test_bammend.py Github

copy

Full Screen

...8 self.tmp_path = tempfile.mkdtemp()9 self.input_bam = input_bam10 self.input_csv = input_csv11 self.output_bam = self.tmp_path + output_bam12 def delete_tmp_dir(self):13 """Remove files generated during test"""14 os.rmdir(self.tmp_path)15 def is_internal_mode(self, supposed_to_be_internal):16 """Tests whether detected internal-mode status is correct"""17 assert bm.is_internal_mode(self.input_bam) == supposed_to_be_internal18 def open_annotation_csv(self):19 """Tests whether basecall rejection CSV input can be opened20 and validated. Includes implicit test of bm.validate_bammend_csv21 """22 bm.open_annotation_csv(self.input_csv)23 def reject_basecalls(self):24 """Tests reject_basecalls routine. Includes implicit test of25 bm.filter_subread as well as bm.apply_subreadset_filters26 """27 if bm.reject_basecalls(self.input_bam, self.input_csv, self.output_bam):28 pass29def test_bammend_internal_mode():30 """Test bammend module with internal-mode data"""31 path = os.path.dirname(os.path.abspath(__file__))32 input_bam = (path + '/data/internal_mode/tiny_set_' +33 'internal.subreads.bam')34 input_csv = (path + '/data/internal_mode/tiny_set_' +35 'testfilter.csv')36 output_bam = 'tiny_set_internal_output.subreads.bam'37 test = _test_bammend_module(path, input_bam, input_csv, output_bam)38 test.is_internal_mode(True)39 test.open_annotation_csv()40 test.reject_basecalls()41 test.delete_tmp_dir()42def test_bammend_customer_mode():43 """Test bammend module with customer-mode data"""44 path = os.path.dirname(os.path.abspath(__file__))45 input_bam = (path + '/data/customer_mode/tiny_set_' +46 'customer.subreads.bam')47 input_csv = (path + '/data/customer_mode/tiny_set_' +48 'testfilter.csv')49 output_bam = 'tiny_set_customer_output.subreads.bam'50 test = _test_bammend_module(path, input_bam, input_csv, output_bam)51 test.is_internal_mode(False)52 test.open_annotation_csv()53 test.reject_basecalls()...

Full Screen

Full Screen

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 autotest 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