Best Python code snippet using localstack_python
smstool_event_handler_tests.py
Source:smstool_event_handler_tests.py
1#!/usr/bin/python2#######################################################################3# SingularMS version 1.0 #4#######################################################################5# This file is a part of SingularMS. #6# #7# SingularMs is free software; you can copy, modify, and distribute #8# it under the terms of the GNU Affero General Public License #9# Version 1.0, 21 May 2007. #10# #11# SingularMS is distributed in the hope that it will be useful, but #12# WITHOUT ANY WARRANTY; without even the implied warranty of #13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. #14# See the GNU Affero General Public License for more details. #15# #16# You should have received a copy of the GNU Affero General Public #17# License with this program; if not, contact Galotecnia #18# at contacto[AT]galotecnia[DOT]org. If you have questions about the #19# GNU Affero General Public License see "Frequently Asked Questions" #20# at http://www.gnu.org/licenses/gpl-faq.html #21#######################################################################22import unittest23import coverage24import glob25from mocker import Mocker26from mocker import Mock27from mocker import expect28from mocker import ARGS29from mocker import KWARGS30from mocker import ANY31import smstool_event_handler32 33class SMSToolEventHandlerTests (unittest.TestCase):34 35 def setUp(self):36 self.mocker = Mocker()37 self.event_handler = smstool_event_handler.SmsToolEventHandler ([])38 39 def tearDown(self):40 self.mocker.restore()41 def test_parse_sms_ok_files (self):42 for file in glob.glob ('./sms_test_files/GSM*'):43 self.event_handler.headers = {}44 self.event_handler.text = ''45 self.event_handler.filename = file46 self.event_handler.parse_sms_file ()47 if self.event_handler.text == '':48 self.fail ("Coud not parse %s correctly" % file)49 def test_wrong_files (self):50 for file in glob.glob ('./sms_test_files/BADGSM*'):51 self.event_handler.filename = file52 self.assertRaises (ValueError, self.event_handler.parse_sms_file)53 def test_input_parser_wrong_param_numbers (self):54 wrong_argv = ['one', 'two', 'three', 'four', 'five' ]55 self.event_handler.argv = wrong_argv56 self.assertRaises (ValueError, self.event_handler.input_parser)57 wrong_argv = ['one', 'two', 'three']58 self.event_handler.argv = wrong_argv59 self.assertRaises (ValueError, self.event_handler.input_parser)60 def test_input_parser_wrong_event (self):61 wrong_argv = ['smstool_event_handler', 'WrongEvent', 'filename', 'id']62 self.event_handler.argv = wrong_argv63 self.assertRaises (ValueError, self.event_handler.input_parser)64 def test_input_parser_ok_event_SENT (self):65 argv = ['smstool_event_handler', 'SENT', 'filename', 'id']66 self.event_handler.argv = argv67 self.event_handler.input_parser()68 self.assertEqual (self.event_handler.event, 'SENT')69 self.assertEqual (self.event_handler.filename, 'filename')70 self.assertEqual (self.event_handler.message_id, 'id')71 def test_input_parser_ok_event_FAILED (self):72 argv = ['smstool_event_handler', 'FAILED', 'filename', 'id']73 self.event_handler.argv = argv74 self.event_handler.input_parser()75 self.assertEqual (self.event_handler.event, 'FAILED')76 self.assertEqual (self.event_handler.filename, 'filename')77 self.assertEqual (self.event_handler.message_id, 'id')78 def test_input_parser_ok_event_RECEIVED (self):79 argv = ['smstool_event_handler', 'RECEIVED', 'filename']80 self.event_handler.argv = argv81 self.event_handler.input_parser()82 self.assertEqual (self.event_handler.event, 'RECEIVED')83 self.assertEqual (self.event_handler.filename, 'filename')84 def test_input_parser_ok_event_REPORT (self):85 argv = ['smstool_event_handler', 'REPORT', 'filename', 'id']86 self.event_handler.argv = argv87 self.event_handler.input_parser()88 self.assertEqual (self.event_handler.event, 'REPORT')89 self.assertEqual (self.event_handler.filename, 'filename')90 self.assertEqual (self.event_handler.message_id, 'id')91 def test_load_config_ok (self):92 self.event_handler.config_file = './smstool_event_handler.conf'93 self.event_handler.load_config()94 self.assertEqual ('pepito', self.event_handler.username)95 self.assertEqual ('password', self.event_handler.password)96 self.assertEqual ('TestAccess', self.event_handler.access)97 self.assertEqual ('http://localhost:8080/', self.event_handler.server_url)98 def test_load_config_ko (self):99 self.event_handler.config_file = './smstool_event_handler_test_wrong.conf'100 self.assertRaises (ValueError, self.event_handler.load_config)101 def test_load_config_not_found (self):102 self.event_handler.config_file = './no_config_file.conf'103 self.assertRaises (ValueError, self.event_handler.load_config)104 def test_dispatch_SENT_event (self):105 dummy_SOAPpy= self.mocker.replace('SOAPpy')106 dummy_SOAPpy.SOAPProxy (ANY)107 self.mocker.count (1)108 self.mocker.result (True)109 self.mocker.replay ()110 argv = ['smstool_event_handler', 'SENT', './sms_test_files/singularmszhwabc.sms', '1JyoAT']111 event_handler = smstool_event_handler.SmsToolEventHandler (argv, './smstool_event_handler.conf')112 event_handler.dispatch ()113 self.mocker.verify()114 def test_dispatch_RECEIVED_event (self):115 dummy_server = self.mocker.mock ()116 dummy_SOAPpy= self.mocker.replace('SOAPpy')117 dummy_SOAPpy.SOAPProxy (ANY)118 self.mocker.count (1)119 self.mocker.result (dummy_server)120 dummy_server.receiveSMS(ARGS, KWARGS)121 self.mocker.count (1)122 self.mocker.result (True)123 self.mocker.replay ()124 argv = ['smstool_event_handler', 'RECEIVED', './sms_test_files/GSM1.M1h8yB']125 event_handler = smstool_event_handler.SmsToolEventHandler (argv, './smstool_event_handler.conf')126 event_handler.dispatch ()127 self.mocker.verify()128 def test_dispatch_FAILED_event (self):129 dummy_SOAPpy= self.mocker.replace('SOAPpy')130 dummy_SOAPpy.SOAPProxy (ANY)131 self.mocker.count (1)132 self.mocker.result (True)133 self.mocker.replay ()134 argv = ['smstool_event_handler', 'FAILED', './sms_test_files/GSM1.M1h8yB', '1JyoAT']135 event_handler = smstool_event_handler.SmsToolEventHandler (argv, './smstool_event_handler.conf')136 event_handler.dispatch ()137 self.mocker.verify()138 def test_dispatch_REPORT_event (self):139 dummy_SOAPpy= self.mocker.replace('SOAPpy')140 dummy_SOAPpy.SOAPProxy (ANY)141 self.mocker.count (1)142 self.mocker.result (True)143 self.mocker.replay ()144 argv = ['smstool_event_handler', 'REPORT', './sms_test_files/GSM1.M1h8yB', '1JyoAT']145 event_handler = smstool_event_handler.SmsToolEventHandler (argv, './smstool_event_handler.conf')146 event_handler.dispatch ()147 self.mocker.verify()148if __name__ == '__main__':149 try:150 coverage.use_cache(False)151 coverage.erase()152 coverage.start()153 reload(smstool_event_handler)154 try:155 unittest.main()156 finally:157 coverage.stop()158 coverage.report(smstool_event_handler)159 except ImportError:...
test_events.py
Source:test_events.py
...70 return parameters71class Test_Events(unittest.TestCase):72 def __init__(self, methodName='runTest'):73 super().__init__(methodName)74 def create_event_handler(self):75 event_handler = TestHandler()76 event_handler.add_event('evt0', 'performer.param_1', 0, 0)77 event_handler.add_event('evt1', 'performer.param_1', 1, 0)78 event_handler.add_event('evt2', 'performer.param_2', (2, 1), 0)79 event_handler.add_event('evt3', 'performer.param_2', (3, 2), 0)80 event_handler.add_event('evt4', 'performer.param_2', (3, 3), 0)81 return event_handler82 def test_adding_events(self):83 event_handler = self.create_event_handler()84 with self.assertRaises(CADETProcess.CADETProcessError):85 event_handler.add_event('wrong_path', 'performer.wrong', 1)86 with self.assertRaises(CADETProcess.CADETProcessError):87 event_handler.add_event(88 'wrong_value', 'performer.param_1', 'wrong'89 )90 with self.assertRaises(CADETProcess.CADETProcessError):91 event_handler.add_event('duplicate', 'performer.param_1', 1)92 event_handler.add_event('duplicate', 'performer.param_1', 1)93 with self.assertRaises(CADETProcess.CADETProcessError):94 event_handler.add_event(95 'not_sec_dependent', 'performer.param_3', 196 )97 def test_event_times(self):98 event_handler = self.create_event_handler()99 self.assertEqual(event_handler.event_times, [0.0])100 event_handler.evt0.time = 1101 self.assertEqual(event_handler.event_times, [0.0, 1.0])102 event_handler.cycle_time = 10103 event_handler.evt0.time = 11104 self.assertEqual(event_handler.event_times, [0.0, 1.0])105 def test_dependenciies(self):106 event_handler = self.create_event_handler()107 event_handler.add_event_dependency('evt1', 'evt0')108 self.assertEqual(event_handler.event_times, [0.0])109 event_handler.evt0.time = 1110 self.assertEqual(event_handler.event_times, [0.0, 1.0])111 event_handler.add_event_dependency('evt2', 'evt1', 2)112 self.assertEqual(event_handler.event_times, [0.0, 1.0, 2.0])113 event_handler.add_event_dependency('evt3', ['evt1', 'evt0'], [2, 1])114 self.assertEqual(event_handler.event_times, [0.0, 1.0, 2.0, 3.0])115 # Dependent event116 with self.assertRaises(CADETProcess.CADETProcessError):117 event_handler.evt1.time = 1118 # Event does not exist119 with self.assertRaises(CADETProcess.CADETProcessError):120 event_handler.add_event_dependency('evt3', 'evt0')...
lv_example_list_1.py
Source:lv_example_list_1.py
...5display_driver.getdisplay_landscape()6#!/opt/bin/lv_micropython -i7import lvgl as lv8import display_driver9def event_handler(e):10 code = e.get_code()11 obj = e.get_target()12 if code == lv.EVENT.CLICKED:13 print("Clicked: list1." + list1.get_btn_text(obj))14# Create a list15list1 = lv.list(lv.scr_act())16list1.set_size(180, 220)17list1.center()18# Add buttons to the list19list1.add_text("File")20btn_new = list1.add_btn(lv.SYMBOL.FILE, "New")21btn_new.add_event_cb(event_handler,lv.EVENT.ALL, None)22btn_open = list1.add_btn(lv.SYMBOL.DIRECTORY, "Open")23btn_open.add_event_cb(event_handler,lv.EVENT.ALL, None)...
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!!