How to use _backend_handler method in localstack

Best Python code snippet using localstack_python

settings.py

Source:settings.py Github

copy

Full Screen

1#2# Copyright (c) 2017, Stephanie Wehner and Axel Dahlberg3# All rights reserved.4#5# Redistribution and use in source and binary forms, with or without6# modification, are permitted provided that the following conditions are met:7# 1. Redistributions of source code must retain the above copyright8# notice, this list of conditions and the following disclaimer.9# 2. Redistributions in binary form must reproduce the above copyright10# notice, this list of conditions and the following disclaimer in the11# documentation and/or other materials provided with the distribution.12# 3. All advertising materials mentioning features or use of this software13# must display the following acknowledgement:14# This product includes software developed by Stephanie Wehner, QuTech.15# 4. Neither the name of the QuTech organization nor the16# names of its contributors may be used to endorse or promote products17# derived from this software without specific prior written permission.18#19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ''AS IS'' AND ANY20# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED21# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE22# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY23# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES24# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES25# LOSS OF USE, DATA, OR PROFITS OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND26# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS28# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.29#########################30# SETTINGS FOR SIMULAQRON31#########################32import logging33from configparser import ConfigParser34import os35from SimulaQron.cqc.backend.cqcLogMessageHandler import CQCLogMessageHandler36from SimulaQron.cqc.backend.cqcMessageHandler import SimulaqronCQCHandler37class Settings:38 _settings_file = os.environ["NETSIM"] + "/config/settings.ini"39 _config = ConfigParser()40 # default settings for if file is not ready yet41 CONF_MAXQUBITS = 2042 CONF_MAXREGS = 100043 CONF_WAIT_TIME = 0.544 CONF_LOGGING_LEVEL_BACKEND = logging.DEBUG45 CONF_LOGGING_LEVEL_FRONTEND = logging.DEBUG46 CONF_BACKEND_HANDLER = SimulaqronCQCHandler47 @classmethod48 def init_settings(cls):49 _log_levels = {50 "info": logging.INFO,51 "debug": logging.DEBUG,52 "warning": logging.WARNING,53 "error": logging.ERROR,54 "critical": logging.CRITICAL55 }56 _config = cls._config57 _config.read(cls._settings_file)58 config_changed = False59 if "BACKEND" not in _config:60 _config['BACKEND'] = {}61 backend = _config['BACKEND']62 if "MaxQubits" in backend:63 cls.CONF_MAXQUBITS = int(backend['MaxQubits'])64 else:65 _config['BACKEND']['MaxQubits'] = str(cls.CONF_MAXQUBITS)66 config_changed = True67 if "MaxRegisters" in backend:68 cls.CONF_MAXREGS = int(backend['MaxRegisters'])69 else:70 _config['BACKEND']['MaxRegisters'] = str(cls.CONF_MAXREGS)71 config_changed = True72 if "WaitTime" in backend:73 cls.CONF_WAIT_TIME = float(backend['WaitTime'])74 else:75 backend['WaitTime'] = str(cls.CONF_WAIT_TIME)76 config_changed = True77 if "LogLevel" in backend:78 _log_level = backend['LogLevel'].lower()79 if _log_level in _log_levels:80 cls.CONF_LOGGING_LEVEL_BACKEND = _log_levels[_log_level]81 else:82 backend['LogLevel'] = list(_log_levels.keys())[83 list(_log_levels.values()).index(cls.CONF_LOGGING_LEVEL_BACKEND)]84 else:85 backend['LogLevel'] = list(_log_levels.keys())[86 list(_log_levels.values()).index(cls.CONF_LOGGING_LEVEL_BACKEND)]87 config_changed = True88 if "BackendHandler" in backend:89 _backend_handler = backend['BackendHandler']90 else:91 backend['BackendHandler'] = "simulaqron"92 _backend_handler = backend['BackendHandler']93 config_changed = True94 if _backend_handler.lower() == 'log':95 cls.CONF_BACKEND_HANDLER = CQCLogMessageHandler96 else: # default simulqron (elif backend_handler.lower() == "simulqron")97 cls.CONF_BACKEND_HANDLER = SimulaqronCQCHandler98 if "FRONTEND" not in _config:99 _config['FRONTEND'] = {}100 frontend = _config['FRONTEND']101 if "LogLevel" in frontend:102 _log_level = frontend['LogLevel'].lower()103 if _log_level in _log_levels:104 cls.CONF_LOGGING_LEVEL_FRONTEND = _log_levels[_log_level]105 else:106 frontend['LogLevel'] = list(_log_levels.keys())[107 list(_log_levels.values()).index(cls.CONF_LOGGING_LEVEL_FRONTEND)]108 else:109 frontend['LogLevel'] = list(_log_levels.keys())[110 list(_log_levels.values()).index(cls.CONF_LOGGING_LEVEL_FRONTEND)]111 config_changed = True112 if config_changed:113 cls.save_settings()114 @classmethod115 def save_settings(cls):116 with open(cls._settings_file, 'w') as file:117 cls._config.write(file)118 @classmethod119 def set_setting(cls, section, key, value):120 cls._config[section][key] = value121 cls.save_settings()...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful