Best Python code snippet using autotest_python
mozfile.py
Source: mozfile.py
...10import tarfile11import zipfile12__all__ = ['extract_tarball', 'extract_zip', 'extract', 'rmtree']13### utilities for extracting archives14def extract_tarball(src, dest):15 """extract a .tar file"""16 bundle = tarfile.open(src)17 namelist = bundle.getnames()18 for name in namelist:19 bundle.extract(name, path=dest)20 bundle.close()21 return namelist22def extract_zip(src, dest):23 """extract a zip file"""24 bundle = zipfile.ZipFile(src)25 namelist = bundle.namelist()26 for name in namelist:27 filename = os.path.realpath(os.path.join(dest, name))28 if name.endswith('/'):29 os.makedirs(filename)30 else:31 path = os.path.dirname(filename)32 if not os.path.isdir(path):33 os.makedirs(path)34 _dest = open(filename, 'wb')35 _dest.write(bundle.read(name))36 _dest.close()37 bundle.close()38 return namelist39def extract(src, dest=None):40 """41 Takes in a tar or zip file and extracts it to dest42 If dest is not specified, extracts to os.path.dirname(src)43 Returns the list of top level files that were extracted44 """45 assert os.path.exists(src), "'%s' does not exist" % src46 assert not os.path.isfile(dest), "dest cannot be a file"47 if dest is None:48 dest = os.path.dirname(src)49 elif not os.path.isdir(dest):50 os.makedirs(dest)51 if zipfile.is_zipfile(src):52 namelist = extract_zip(src, dest)53 elif tarfile.is_tarfile(src):54 namelist = extract_tarball(src, dest)55 else:56 raise Exception("mozfile.extract: no archive format found for '%s'" %57 src)58 # namelist returns paths with forward slashes even in windows59 top_level_files = [os.path.join(dest, name) for name in namelist60 if len(name.rstrip('/').split('/')) == 1]61 # namelist doesn't include folders, append these to the list62 for name in namelist:63 root = os.path.join(dest, name[:name.find('/')])64 if root not in top_level_files:65 top_level_files.append(root)66 return top_level_files67def rmtree(dir):68 """This is a replacement for shutil.rmtree that works better under...
tarballfetcher.py
Source: tarballfetcher.py
...12 sys.stdout.write('Downloading %s... ' % url)13 sys.stdout.flush()14 urlretrieve(url, filename)15 sys.stdout.write('DONE\n')16def extract_tarball(tarball_filename):17 tarball = tarfile.open(tarball_filename, 'r:gz')18 sys.stdout.write('Extracting %s... ' % tarball_filename)19 sys.stdout.flush()20 tarball.extractall('.')21 sys.stdout.write('DONE\n')22def sha256_file(filename):23 return hashlib.sha256(open(filename, 'rb').read()).hexdigest()24def download_and_extract_tarball(tarball_url,25 tarball_filename=None,26 expected_sha256=None):27 if tarball_filename is None:28 tarball_filename = os.path.basename(urlparse(tarball_url).path)29 if not os.path.exists(tarball_filename):30 download_file(tarball_url, tarball_filename)31 if expected_sha256 is not None:32 sys.stdout.write('Checking that SHA256 of %s is %s... ' %33 (tarball_filename, expected_sha256))34 actual_sha256 = sha256_file(tarball_filename)35 sys.stdout.write('SHA256 is %s. ' % actual_sha256)36 if actual_sha256 == expected_sha256:37 sys.stdout.write('OK\n')38 else:39 sys.stdout.write('Incorrect SHA256!\n')40 sys.exit(1)...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
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!!