Best Python code snippet using autotest_python
test_hostinfo.py
Source:test_hostinfo.py
...21 def setUp(self):22 super(HostInfoTestCase, self).setUp()23 hostinfo.get_meminfo = self.get_meminfo24 hostinfo.statvfs = self.statvfs25 def get_meminfo(self):26 data = ['MemTotal: 1018784 kB\n',27 'MemFree: 220060 kB\n',28 'Buffers: 21640 kB\n',29 'Cached: 63364 kB\n']30 return data31 def statvfs(self):32 seq = (4096, 4096, 10047582, 7332259, 6820195,33 2564096, 2271310, 2271310, 1024, 255)34 return posix.statvfs_result(sequence=seq)35 def test_get_disk_usage(self):36 disk_usage = hostinfo.get_disk_usage()37 self.assertEqual(disk_usage['total'], 41154895872)38 self.assertEqual(disk_usage['available'], 27935518720)39 self.assertEqual(disk_usage['used'], 11121963008)...
profile.py
Source:profile.py
...12config = yaml.load(open(REDUX_CONF))13trace = Trace(level=config['verbosity'])14# Procedure: get_meminfo15# Purpose: return memory usage of this process (resident set size)16def get_meminfo():17 # get process info from OS18 p = psutil.Process(os.getpid())19 # return resident set size20 return p.memory_full_info().rss21# Procedure: profile22# Purpose: decorator for function that adds memory usage and time stat23def profile(myfunc):24 from functools import wraps25 @wraps(myfunc)26 def wrapper(*arg, **kw):27 mem0 = get_meminfo()28 start = time.time()29 result = myfunc(*arg, **kw)30 seconds = time.time() - start31 mem1 = get_meminfo()32 trace(2, '{}: mem: {:,} bytes; time: {:.4f} sec'.format(myfunc.__name__,33 mem1-mem0, seconds))34 #print('{}: mem: {:,} bytes; time: {:.4f} sec'.format(myfunc.__name__,35 # mem1-mem0, seconds))36 return result...
memory_info
Source:memory_info
1#!/usr/bin/env python32import re3import sys4def get_meminfo():5 meminfo = {}6 for line in open("/proc/meminfo").readlines():7 match = re.match(r"(.*):\s+(.*)", line)8 if match:9 key = match.group(1)10 value = match.group(2)11 meminfo[key] = value12 return meminfo13def main(args):14 meminfo = get_meminfo()15 amount, units = meminfo["MemTotal"].split()16 amount = float(amount)17 next_units = {'kB': 'MiB',18 'MB': 'GiB',19 'MiB': 'GiB'}20 while amount > 1024:21 amount = amount / 102422 units = next_units[units]23 print("%.1f %s" % (amount, units))24 return 025if __name__ == "__main__":...
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!!