Best Python code snippet using localstack_python
musicbox.py
Source: musicbox.py
1from folderHandler import FolderHandler2from rfidReader import RFIDReader3from mp3Player import MP3Player4from speakerHandler import SpeakerHandler5from buttonHandler import ButtonHandler6from importer import Importer7from settings import Settings8from ledHandler import LedHandler9from shutdownScheduler import ShutdownScheduler10import signal11import sys12# some base definitions13base_path = "/home/pi/musicbox/"14music_path = base_path + "music"15shutdown_time = 30 # shutdown after 30 minutes16# instanciate all classes17settings = Settings(base_path)18speaker_handler = SpeakerHandler()19mp3_player = MP3Player(music_path, settings, speaker_handler)20button_handler = ButtonHandler(mp3_player)21folder_handler = FolderHandler(music_path)22importer = Importer(music_path)23rfid_reader = RFIDReader()24led_handler = LedHandler()25shutdown_scheduler = ShutdownScheduler(mp3_player, shutdown_time, speaker_handler)26# define the exit handler to switch off speaker and antenna27def exit_handler(signum=None, frame=None):28 shutdown_scheduler.shutdown()29 speaker_handler.speaker_off()30 rfid_reader.antenna_off()31 led_handler.shutdown()32 sys.exit(0)33for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]:34 signal.signal(sig, exit_handler)35# start main loop that waits for tags36tag = ""37while True:38 tag = rfid_reader.wait_for_tag_change(tag)39 if tag == "":40 print(tag + " removed.")41 mp3_player.pause()42 else:43 print(str(tag) + " detected.")44 folder = folder_handler.get_folder_by_tag(tag)45 if folder != "":46 mp3_player.play(folder)47 else:48 print("Tag is new...")49 if importer.new_music_available():50 print("New music for import found.")51 folder = str(tag)52 importer.import_new_music(folder)53 mp3_player.play(folder)54 else:...
test_server.py
Source: test_server.py
1# -*- coding: utf-8 -*-2# vim: set ft=python ts=4 sw=4 expandtab:3from unittest.mock import patch4import pytest5from fastapi.testclient import TestClient6from vplan.engine.server import API, API_VERSION, shutdown_event, startup_event7CLIENT = TestClient(API)8class TestLifecycle:9 pytestmark = pytest.mark.asyncio10 @patch("vplan.engine.server.start_scheduler")11 @patch("vplan.engine.server.setup_database")12 @patch("vplan.engine.server.setup_directories")13 async def test_startup_event(self, setup_directories, setup_database, start_scheduler):14 await startup_event()15 setup_directories.assert_called_once()16 setup_database.assert_called_once()17 start_scheduler.assert_called_once()18 @patch("vplan.engine.server.shutdown_scheduler")19 async def test_shutdown_event(self, shutdown_scheduler):20 await shutdown_event()21 shutdown_scheduler.assert_called_once()22class TestRoutes:23 def test_health(self):24 response = CLIENT.get(url="/health")25 assert response.status_code == 20026 assert response.json() == {"status": "OK"}27 @patch("vplan.engine.server.metadata_version")28 def test_version(self, metadata_version):29 metadata_version.return_value = "xxx"30 response = CLIENT.get(url="/version")31 assert response.status_code == 200...
__init__.py
Source: __init__.py
1import atexit2from flask import Flask3from rest_app.shared import db, scheduler4from rest_app.views.shared import blueprint as views_blueprint5from rest_app.services import refresh_offers6def create_app(start_background_job=True, shutdown_scheduler=True, **kwargs) -> Flask:7 app = Flask(__name__)8 app.config.from_pyfile('config.py')9 app.config.update(**kwargs)10 db.init_app(app)11 app.register_blueprint(views_blueprint)12 if start_background_job:13 scheduler.init_app(app)14 with app.app_context():15 db.create_all()16 refresh_offers.schedule_refresh()17 if start_background_job:18 scheduler.start()19 if shutdown_scheduler:20 atexit.register(scheduler.shutdown)...
Check out the latest blogs from LambdaTest on this topic:
The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.
QA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.
Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
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!!