Best Python code snippet using pyatom_python
test_number_helper.py
Source:test_number_helper.py
1import unittest2import math3from src.helper import number_helper as nh4class TestsNumberHelper(unittest.TestCase):5 def test_without_dot(self):6 is_number, number = nh.number_helper.is_number('100')7 self.assertTrue(is_number)8 self.assertEqual(number, 100)9 def test_one_dot_and_one_comma_decimal(self):10 is_number, number = nh.number_helper.is_number('1.234,50')11 self.assertTrue(is_number)12 self.assertEqual(number, 1234.50)13 def test_more_than_one_comma(self):14 is_number, number = nh.number_helper.is_number('1,234,50')15 self.assertFalse(is_number)16 self.assertTrue(math.isnan(number))17 def test_one_dot_two_decimals(self):18 is_number, number = nh.number_helper.is_number('1234.12')19 self.assertTrue(is_number)20 self.assertEqual(number, 1234.12)21 def test_one_dot_one_decimal(self):22 is_number, number = nh.number_helper.is_number('1234.0')23 self.assertTrue(is_number)24 self.assertEqual(number, 1234.0)25 def test_word_nan(self):26 is_number, number = nh.number_helper.is_number('abacate')27 self.assertFalse(is_number)28 self.assertTrue(math.isnan(number))29 def test_more_one_dot(self):30 is_number, number = nh.number_helper.is_number('1.234.567')31 self.assertTrue(is_number)32 self.assertEqual(number, 1234567.0)33 def test_more_one_dot_and_decimal(self):34 is_number, number = nh.number_helper.is_number('1.234.567.89')35 self.assertTrue(is_number)36 self.assertEqual(number, 1234567.89)37 def test_more_one_dot_and_decimal_nan(self):38 is_number, number = nh.number_helper.is_number('1.234.567.890000')39 self.assertFalse(is_number)40 self.assertTrue(math.isnan(number))41 def test_dot_and_comma_one_decimal(self):42 is_number, number = nh.number_helper.is_number('2.587,6')43 self.assertTrue(is_number)44 self.assertEqual(number, 2587.6)45 def test_dot_and_comma_without_decimal(self):46 is_number, number = nh.number_helper.is_number('2.587,')47 self.assertFalse(is_number)48 self.assertTrue(math.isnan(number))49if __name__ == '__main__':...
showTemp.py
Source:showTemp.py
1import machine2import time, utime3import bmp1804import dht5import onewire, ds18x206import Wemos7import number_helper8import MyDateTime9# V1.4.110# BMP18011def showTempBMP(tm):12 i2c = machine.I2C(sda = machine.Pin(Wemos.D2),scl = machine.Pin(Wemos.D1))13 bmp = bmp180.BMP180(i2c)14 tempBMP = bmp.temperature15 tm.write_int(0x0100000000000000)16 number_helper.show2FiguresNumberX3(tm,tempBMP)17 return tempBMP18# DHT19def showTempDHT(tm):20 dht11 = dht.DHT11(machine.Pin(Wemos.D4))21 dht11.measure()22 tempDHT = dht11.temperature()23 tm.write_int(0x1000000000000000)24 number_helper.show2FiguresNumberX3(tm, tempDHT)25 return tempDHT26# DS18x2027def showTempDS(tm):28 ds = ds18x20.DS18X20(onewire.OneWire(machine.Pin(Wemos.D2)))29 roms = ds.scan()30 if len(roms) > 0 :31 ds.convert_temp()32 tempDS = ds.read_temp(roms[0])33 tm.write_int(0x8000000000000000)34 number_helper.show2FiguresNumberX3(tm, tempDS)35 return tempDS36# init LedMatrix37def initLedMatrix():38 tm = number_helper.createTM1640()39 tm.brightness(0)40 return tm41 42# get sensors data 43def getSensorsData(tm):44 tempDS = showTempDS(tm)45 tempDHT = showTempDHT(tm)46 tempBMP = showTempBMP(tm)47 msg = MyDateTime.getLocalTimeHumanFormat() + ', '+str(tempBMP)+ ', '+str(tempDHT)+ ', '+str(tempDS)48 return msg49# main50def mainBeta():51 tm = initLedMatrix()52 print(MyDateTime.setRTC())53 print("# DateTime,BMP,DHT,DS")54 while True:55 msg = getSensorsData(tm)56 print(msg)...
number_helper.py
Source:number_helper.py
1import math2import re3class number_helper:4 @staticmethod5 def is_number(string):6 commas_number = string.count(',')7 if commas_number > 1:8 return (False, math.nan)9 else:10 return number_helper.__is_number_with_at_least_one_dot(string)11 @staticmethod12 def __is_number_with_at_least_one_dot(string):13 string = string.replace(',', '.')14 if string.count('.') <= 1:15 try:16 number = float(string)17 return (True, number)18 except ValueError:19 return (False, math.nan)20 else:21 return number_helper.__is_number_with_more_dots(string)22 @staticmethod23 def __is_number_with_more_dots(string):24 try:25 if re.fullmatch(r'.*\.\d{3}', string) is not None:26 number = float(string.replace('.', ''))27 return (True, number)28 else:29 raise ValueError30 except ValueError:31 return number_helper.__is_number_with_more_dots_and_decimal(string)32 @staticmethod33 def __is_number_with_more_dots_and_decimal(string):34 try:35 if re.fullmatch(r'.*\.\d{1,2}', string) is not None:36 dots_number = string.count('.')37 number = float(string.replace('.', '', dots_number - 1))38 return (True, number)39 else:40 raise ValueError41 except ValueError:...
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!!