Best Python code snippet using lisa_python
unittest_statsd.py
Source: unittest_statsd.py
...54class StatsdTC(TestCase):55 def setUp(self):56 super(StatsdTC, self).setUp()57 DATA[:] = []58 def check_received(self, value):59 for i in range(10):60 if value in DATA:61 break62 time.sleep(0.01)63 else:64 self.assertIn(value, DATA)65 def check_received_ms(self, value):66 value = re.compile(value.replace('?', r'\d'))67 for i in range(10):68 if [x for x in DATA if value.match(x)]:69 break70 time.sleep(0.01)71 else:72 self.assertTrue([x for x in DATA if value.match(x)], DATA)73 def test_statsd_c(self):74 statsd.statsd_c('context')75 self.check_received('test.context:1|c')76 statsd.statsd_c('context', 10)77 self.check_received('test.context:10|c')78 def test_statsd_g(self):79 statsd.statsd_g('context', 42)80 self.check_received('test.context:42|g')81 statsd.statsd_g('context', 'Igorrr')82 self.check_received('test.context:Igorrr|g')83 def test_statsd_t(self):84 statsd.statsd_t('context', 1)85 self.check_received('test.context:1.0000|ms')86 statsd.statsd_t('context', 10)87 self.check_received('test.context:10.0000|ms')88 statsd.statsd_t('context', 0.12344)89 self.check_received('test.context:0.1234|ms')90 statsd.statsd_t('context', 0.12345)91 self.check_received('test.context:0.1235|ms')92 def test_decorator(self):93 @statsd.statsd_timeit94 def measure_me_please():95 "some nice function"96 return 4297 self.assertEqual(measure_me_please.__doc__,98 "some nice function")99 measure_me_please()100 self.check_received_ms('test.measure_me_please:0.0???|ms')101 self.check_received('test.measure_me_please:1|c')102 def test_context_manager(self):103 with statsd.statsd_timethis('cm'):104 time.sleep(0.1)105 self.check_received_ms('test.cm:100.????|ms')106 self.check_received('test.cm:1|c')107if __name__ == '__main__':108 from unittest import main...
machinecontrol.py
Source: machinecontrol.py
...32def n_drops(orderlist, ingredient_n): #returns the number of drops to pump33 mass = float(orderlist["amounts"][ingredient_n][0])34 mass_per_drop = float(orderlist["amounts"][ingredient_n][1])35 return round(mass / mass_per_drop)36def check_received(): #updates the queue37 n = len(os.listdir(queue_dir))38 if n > 0:39 lcd.text("queue: " + str(n), 4)40 return n41def dispense():42 filename = os.listdir(queue_dir)[0] #find the current filename43 with open(queue_dir + filename, "r") as f: #open it44 order = order_handler(json.load(f)) #load and fix the order info45 name = order["name"]46 lcd.text(clear_line, 1) #update screen47 lcd.text("press to dispense:", 1)48 lcd.text(clear_line, 2)49 lcd.text(name, 2)50 while not button.is_pressed: #wait for button press51 check_received()52 lcd.text(clear_line, 1) #update screen53 lcd.text("dispensing:", 1)54 pump_time_list = []55 for n in range(len(pumps)): #iterate through order ingredients56 i = n_drops(order, n)57 pumps[n].blink(pump_pulse_time, pump_pause, i) #set pumps to run for predescribed time58 pump_time_list.append(i)59 os.replace(queue_dir + filename, done_dir + filename) #moves file to done directory60 end_time = time.monotonic() + max(pump_time_list) + 0.561 while time.monotonic() < end_time: #wait until the pumps are done62 pass63 lcd.clear()64 lcd.text("last: " + name, 3) #display the name as last dispensed65 wait_flag = True66try:67 while True:68 if check_received():69 dispense()70 elif wait_flag:71 lcd.text(clear_line, 1)72 lcd.text("waiting for orders.", 1)73 wait_flag = False74finally:75 for n in range(len(pumps)): #shut off all pumps76 pumps[n].off()77 lcd.text(clear_line * 2, 1)78 lcd.text("something's wrong,", 1) #display error message79 lcd.text("restart the device.", 2)...
Check out the latest blogs from LambdaTest on this topic:
Automating testing is a crucial step in the development pipeline of a software product. In an agile development environment, where there is continuous development, deployment, and maintenance of software products, automation testing ensures that the end software products delivered are error-free.
Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.
The QA testing career includes following an often long, winding road filled with fun, chaos, challenges, and complexity. Financially, the spectrum is broad and influenced by location, company type, company size, and the QA tester’s experience level. QA testing is a profitable, enjoyable, and thriving career choice.
It’s strange to hear someone declare, “This can’t be tested.” In reply, I contend that everything can be tested. However, one must be pleased with the outcome of testing, which might include failure, financial loss, or personal injury. Could anything be tested when a claim is made with this understanding?
When it comes to UI components, there are two versatile methods that we can use to build it for your website: either we can use prebuilt components from a well-known library or framework, or we can develop our UI components from scratch.
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!!