Best Python code snippet using localstack_python
test_settings.py
Source: test_settings.py
...36 os.environ['SETTING__PYMAID__FLOAT'] = 'float::5.13543512414351235'37 os.environ['SETTING__PYMAID__BOOL'] = 'bool::False'38 os.environ['SETTING__PYMAID__DICT'] = 'dict::{"age": 18}'39 os.environ['SETTING__PYMAID__LIST'] = 'list::[1, 2, 3]'40 settings.load_from_environment(prefix='SETTING__')41 assert settings.get('NOT_EXIST', ns='pymaid') == 'noway'42 assert settings.get('NOT_EXIST', default='what') == b'noway'43 assert settings.get('MAX_TASKS', ns='pymaid') == 12844 assert abs(settings.get('FLOAT', ns='pymaid') - 5.13543512414351235) < 1e-6 # noqa45 assert settings.get('BOOL', ns='pymaid') is False46 assert settings.get('DICT', ns='pymaid') == {'age': 18}47 assert settings.get('LIST', ns='pymaid') == [1, 2, 3]48def test_load_env_bad_cases():49 # wrong prefix50 settings.namespaces.clear()51 os.environ['SETTING__PYMAID__LIST'] = 'list::[1, 2, 3]'52 with pytest.raises(ValueError):53 settings.load_from_environment(prefix='SETTING_')54 assert settings.get('LIST', ns='pymaid') is None55 assert not settings.namespaces56 os.environ.clear()57 with pytest.raises(ValueError):58 settings.load_from_environment(prefix='SETTING___')59 assert settings.get('LIST', ns='pymaid') is None60 assert not settings.namespaces61 # wrong namespace62 os.environ['SETTING___PYMAID__LIST'] = 'list::[1, 2, 3]'63 settings.load_from_environment(prefix='SETTING__')64 assert settings.get('LIST', ns='pymaid') is None65 assert not settings.namespaces66 # wrong key67 os.environ['SETTING__PYMAID___LIST'] = 'list::[1, 2, 3]'68 settings.load_from_environment(prefix='SETTING__')69 assert settings.get('LIST', ns='pymaid') is None70 assert not settings.namespaces71 # wrong value format72 os.environ['SETTING__PYMAID__LIST'] = '[1, 2, 3]'73 with pytest.raises(ValueError):74 settings.load_from_environment(prefix='SETTING__')75 assert settings.get('LIST', ns='pymaid') is None76 assert not settings.namespaces77 os.environ['SETTING__PYMAID__LIST'] = 'list:[1, 2, 3]'78 with pytest.raises(ValueError):79 settings.load_from_environment(prefix='SETTING__')80 assert settings.get('LIST', ns='pymaid') is None81 assert not settings.namespaces82 # wrong value type83 os.environ['SETTING__PYMAID__LIST'] = 'what_type::[1, 2, 3]'84 with pytest.raises(ValueError):85 settings.load_from_environment(prefix='SETTING__')86 assert settings.get('LIST', ns='pymaid') is None87 assert not settings.namespaces88 # wrong type::value89 os.environ['SETTING__PYMAID__LIST'] = 'int::[1, 2, 3]'90 with pytest.raises(ValueError):91 settings.load_from_environment(prefix='SETTING__')92 assert settings.get('LIST', ns='pymaid') is None93 assert not settings.namespaces94def test_dot_get():95 assert settings.pymaid.DEBUG == defaults.DEBUG96 # not exists namespace97 with pytest.raises(AttributeError):98 settings.what99 # not exists key100 with pytest.raises(AttributeError):101 settings.pymaid.what102def test_dot_set():103 assert settings.pymaid.MAX_TASKS == defaults.MAX_TASKS104 settings.pymaid.MAX_TASKS += 1105 assert settings.pymaid.MAX_TASKS == defaults.MAX_TASKS + 1...
application_config.py
Source: application_config.py
...18 try:19 config.update(yaml.load(stream, Loader=yaml.Loader))20 except yaml.YAMLError as e:21 raise Exception("Error parsing config file", e)22def load_from_environment():23 for property in properties:24 if property in os.environ:25 config[property] = os.environ[property]26def load_configs():27 load_defaults()28 load_config_file()29 load_from_environment()30def __get_next_config(path: list, tree_config: dict):31 if path is None or len(path) == 0:32 return None33 current_config_key = path[0]34 if current_config_key not in tree_config:35 return None36 current_config_value = tree_config[current_config_key]37 next_path = path.copy()38 next_path.remove(current_config_key)39 if len(next_path) == 0:40 return current_config_value41 return __get_next_config(next_path, current_config_value)42def get_config(path: list) -> dict:43 return __get_next_config(path, config)...
application.py
Source: application.py
...3from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine4from falert.backend.common.configuration import Configuration, load_from_environment5class BaseApplication:6 def __init__(self):7 self.__configuration = load_from_environment()8 self.__engine = create_async_engine(9 self.__configuration.database_url,10 echo=self.__configuration.database_echo,11 )12 self.__logger = getLogger(None)13 basicConfig()14 self.__logger.setLevel(DEBUG)15 @property16 def _configuration(self) -> Configuration:17 return self.__configuration18 @property19 def _engine(self) -> AsyncEngine:20 return self.__engine21 @property...
Check out the latest blogs from LambdaTest on this topic:
Software Risk Management (SRM) combines a set of tools, processes, and methods for managing risks in the software development lifecycle. In SRM, we want to make informed decisions about what can go wrong at various levels within a company (e.g., business, project, and software related).
Unit and functional testing are the prime ways of verifying the JavaScript code quality. However, a host of tools are available that can also check code before or during its execution in order to test its quality and adherence to coding standards. With each tool having its unique features and advantages contributing to its testing capabilities, you can use the tool that best suits your need for performing JavaScript testing.
Are members of agile teams different from members of other teams? Both yes and no. Yes, because some of the behaviors we observe in agile teams are more distinct than in non-agile teams. And no, because we are talking about individuals!
Hey LambdaTesters! We’ve got something special for you this week. ????
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?
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!!