Best Python code snippet using tempest_python
hoststatsTests.py
Source: hoststatsTests.py
...62 shutil.rmtree(self._tmpDir)63 def testBootTimeOk(self):64 with MonkeyPatchScope([(hoststats, '_PROC_STAT_PATH',65 self._good_path)]):66 self.assertEquals(hoststats.get_boot_time(),67 1395249141)68 def testBootTimeEmpty(self):69 with MonkeyPatchScope([(hoststats, '_PROC_STAT_PATH',70 '/dev/null')]):71 with self.assertRaises(ValueError):72 hoststats.get_boot_time()73 def testBootTimeMissing(self):74 with MonkeyPatchScope([(hoststats, '_PROC_STAT_PATH',75 self._missing_path)]):76 with self.assertRaises(ValueError):77 hoststats.get_boot_time()78 def testBootTimeMalformed(self):79 with MonkeyPatchScope([(hoststats, '_PROC_STAT_PATH',80 self._malformed_path)]):81 with self.assertRaises(ValueError):82 hoststats.get_boot_time()83 def testBootTimeNonExistantFile(self):84 with MonkeyPatchScope([(hoststats, '_PROC_STAT_PATH',85 '/i/do/not/exist/1234567890')]):86 with self.assertRaises(IOError):87 hoststats.get_boot_time()88 def testBootTimeExtra(self):89 with MonkeyPatchScope([(hoststats, '_PROC_STAT_PATH',90 self._extra_path)]):91 self.assertEquals(hoststats.get_boot_time(), 1395249141)92class HostStatsThreadTests(TestCaseBase):93 _core_zero_stats = {94 'cpuIdle': '100.00',95 'cpuSys': '0.00',96 'cpuUser': '0.00',97 'nodeIndex': 098 }99 _core_one_stats = {100 'cpuIdle': '100.00',101 'cpuSys': '0.00',102 'cpuUser': '0.00',103 'nodeIndex': 1104 }105 def _fakeNumaTopology(self):...
boot_monitor.py
Source: boot_monitor.py
...15# along with this program; if not, write to the Free Software16# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA17#18from time import sleep19def get_boot_time(con):20 timeepoch = None21 problem, out, _ = con.maybe_launch('net statistics server',timeout = 60)22 if problem: print 'BOOT_MONITOR:', 'problem',problem,'getting boot time' 23 else:24 try:25 print 'BOOT_MONITOR:', 'raw output',out 26 uout = out.replace('\r', '')27 lines = out.split('\n')28 timestring= ' '.join(lines[3].split()[2:])29 # 5/4/2010 5:37 PM30 colons = timestring.count(':')31 format = '%m/%d/%Y %I:%M %p' if colons == 1 else '%m/%d/%Y %I:%M:%S %p'32 timetuple = time.strptime(timestring, format)33 timeepoch = time.mktime(timetuple)34 print 'BOOT_MONITOR:', 'epoch',timeepoch 35 except IndexError: pass36 return (timeepoch)37class BootMonitor:38 def __init__(self, con):39 self.con = con40 self.boots = []41 42 def get_first_boot_time(self):43 while True:44 epoch = get_boot_time(self.con)45 if epoch is not None: break46 47 print 'BOOT_MONITOR:', 'boot time not available yet' 48 sleep(1)49 assert epoch > 050 self.boots.append(epoch)51 52 def get_boot_time(self):53 t = get_boot_time(self.con)54 if t is None: return55 if t not in self.boots: self.boots.append(t)56 return (t)57 def get_number_of_boots(self): return len(self.boots)58 def render_boot_times(self):59 return 'boot times %r' % ([time.asctime(time.localtime(t)) for ...
main.py
Source: main.py
1from record_img import CapThread2from start_app import AppStartThread3import process_img4import get_boot_time5import device_info6import os7import shutil8import global_var9import airtest_app10times = 011while times < 11:12 target_dir = global_var.target_dir13 source_dir = global_var.source_dir14 # æ¯æ¬¡å 餿件夹åéæ°åå»ºæ¤æä»¶å¤¹15 shutil.rmtree(source_dir)16 os.mkdir(source_dir)17 # å建æ°çº¿ç¨-å¯å¨Appå¹¶ä¸å¼å¯å½å±18 thread1 = CapThread(1, "cap")19 thread2 = AppStartThread(2, "appstart")20 # å¼å¯æ°çº¿ç¨21 thread1.start()22 thread2.start()23 thread1.join()24 thread2.join()25 print("éåºä¸»çº¿ç¨")26 process_img.processIMG()27 filelist = os.listdir(target_dir) # è·å该ç®å½ä¸çæææä»¶å28 filelist.sort()29 start_time = get_boot_time.get_start_time(filelist)30 end_time = get_boot_time.get_end_time(filelist, target_dir)31 boot_time = end_time - start_time32 print("å¯å¨æ¶é´ï¼msï¼:" + str(boot_time))33 # è·åææºåå·34 n = os.popen("adb shell getprop ro.product.model")35 devicename = n.readlines()36 # device_info.create_csv()37 device_info.write_csv("7.5.21", devicename[0], boot_time)38 global_var.exitFlag = 139 airtest_app.close()...
Check out the latest blogs from LambdaTest on this topic:
Agile software development stems from a philosophy that being agile means creating and responding to change swiftly. Agile means having the ability to adapt and respond to change without dissolving into chaos. Being Agile involves teamwork built on diverse capabilities, skills, and talents. Team members include both the business and software development sides working together to produce working software that meets or exceeds customer expectations continuously.
When software developers took years to create and introduce new products to the market is long gone. Users (or consumers) today are more eager to use their favorite applications with the latest bells and whistles. However, users today don’t have the patience to work around bugs, errors, and design flaws. People have less self-control, and if your product or application doesn’t make life easier for users, they’ll leave for a better solution.
Hey LambdaTesters! We’ve got something special for you this week. ????
In some sense, testing can be more difficult than coding, as validating the efficiency of the test cases (i.e., the ‘goodness’ of your tests) can be much harder than validating code correctness. In practice, the tests are just executed without any validation beyond the pass/fail verdict. On the contrary, the code is (hopefully) always validated by testing. By designing and executing the test cases the result is that some tests have passed, and some others have failed. Testers do not know much about how many bugs remain in the code, nor about their bug-revealing efficiency.
These days, development teams depend heavily on feedback from automated tests to evaluate the quality of the system they are working on.
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!!