Best Python code snippet using tox_python
config.py
Source: config.py
...3from dtools.enums import LoggingLevel, ConfigAttribute4DTOOLS_DIR = os.path.join(os.path.expanduser("~"), 'dtools')5CONFIG_PATH = os.path.join(DTOOLS_DIR, 'config.json')6REPO_PATH = os.path.dirname(os.path.abspath(__file__))7def _check_logging_levels(logging_levels):8 possible_values = set([e.value for e in LoggingLevel])9 if logging_levels - possible_values:10 raise ValueError(f'Invalid {ConfigAttribute.LOGGING_LEVELS.value} {logging_levels - possible_values}')11def _create_new_config_entry():12 logging_levels = [LoggingLevel.EXCEPTION.value]13 return {14 ConfigAttribute.LOGGING_LEVELS.value: logging_levels,15 ConfigAttribute.LOG_FILE_PATH.value: 'log.txt'16 }17class _Config:18 def __init__(self):19 if not os.path.exists(CONFIG_PATH):20 self._create_new_config_json()21 else:22 with open(CONFIG_PATH, 'r') as f:23 self._config_json = json.load(f)24 if REPO_PATH not in self._config_json:25 self.add_repo_to_config()26 else:27 _check_logging_levels(self.logging_levels)28 def add_repo_to_config(self):29 self._config_json[REPO_PATH] = _create_new_config_entry()30 self.save()31 def _create_new_config_json(self):32 self._config_json = {33 REPO_PATH: _create_new_config_entry()34 }35 self.save()36 def save(self):37 with open(CONFIG_PATH, 'w') as f:38 json.dump(self._config_json, f, indent=4)39 def set_logging_levels(self, logging_levels):40 logging_levels = set(logging_levels)41 _check_logging_levels(logging_levels)42 self._config_json[REPO_PATH][ConfigAttribute.LOGGING_LEVELS.value] = list(logging_levels)43 self.save()44 @property45 def logging_levels(self):46 return set(self._config_json[REPO_PATH][ConfigAttribute.LOGGING_LEVELS.value])47 @property48 def log_file_path(self):49 return self._config_json[REPO_PATH][ConfigAttribute.LOG_FILE_PATH.value]...
lambda_handler.py
Source: lambda_handler.py
1#!/usr/bin/env python32# -*- coding: utf-8 -*-3"""4"""5import json6import logging7import os8import traceback9import line_handler10logger = logging.getLogger(__name__)11def lambda_handler(event, context):12 _lambda_logging_init()13 headers = event["headers"] # or event["multiValueHeaders"]14 # prm1 = event["pathParameters"]["prm1"]15 # prm2 = event["queryStringParameters"]["prm2"]16 body = event["body"]17 logger.info(headers)18 try:19 result = line_handler.callback(headers, body)20 return {"statusCode": 200, "body": json.dumps(result)}21 except Exception as e:22 result = {"result": "failed", "message": traceback.format_exc()}23 logger.info(json.dumps(result), exc_info=e)24 return {"statusCode": 500, "body": json.dumps(result)}25def _lambda_logging_init():26 """27 logging ã®åæåãLOGGING_LEVEL, LOGGING_LEVELS ç°å¢å¤æ°ãè¦ã¦ããã°ã¬ãã«ãè¨å®ããã28 LOGGING_LEVELS - "module1=DEBUG,module2=INFO" ã¨ããå½¢ã®æååãæ³å®ãèªåã®ã¢ã¸ã¥ã¼ã«ã®ã¿ DEBUG ã«ããã¨ããªã©ã«å©ç¨29 """30 logging.getLogger().setLevel(os.getenv('LOGGING_LEVEL', 'INFO')) # lambda ã®å ´åã¯ãã¬ã¼è¨å®æ¸ã¿ã®ãããã¡ããå¿
è¦31 if os.getenv('LOGGING_LEVELS'):32 for mod_lvl in os.getenv('LOGGING_LEVELS').split(','):33 mod, lvl = mod_lvl.split('=')...
pylogger.py
Source: pylogger.py
1import logging2from pytorch_lightning.utilities import rank_zero_only3def get_pylogger(name=__name__) -> logging.Logger:4 """Initializes multi-GPU-friendly python command line logger."""5 logger = logging.getLogger(name)6 # this ensures all logging levels get marked with the rank zero decorator7 # otherwise logs would get multiplied for each GPU process in multi-GPU setup8 logging_levels = ("debug", "info", "warning", "error", "exception", "fatal", "critical")9 for level in logging_levels:10 setattr(logger, level, rank_zero_only(getattr(logger, level)))...
Check out the latest blogs from LambdaTest on this topic:
Hey Testers! We know it’s been tough out there at this time when the pandemic is far from gone and remote working has become the new normal. Regardless of all the hurdles, we are continually working to bring more features on-board for a seamless cross-browser testing experience.
Manual cross browser testing is neither efficient nor scalable as it will take ages to test on all permutations & combinations of browsers, operating systems, and their versions. Like every developer, I have also gone through that ‘I can do it all phase’. But if you are stuck validating your code changes over hundreds of browsers and OS combinations then your release window is going to look even shorter than it already is. This is why automated browser testing can be pivotal for modern-day release cycles as it speeds up the entire process of cross browser compatibility.
With new-age project development methodologies like Agile and DevOps slowly replacing the old-age waterfall model, the demand for testing is increasing in the industry. Testers are now working together with the developers and automation testing is vastly replacing manual testing in many ways. If you are new to the domain of automation testing, the organization that just hired you, will expect you to be fast, think out of the box, and able to detect bugs or deliver solutions which no one thought of. But with just basic knowledge of testing, how can you be that successful test automation engineer who is different from their predecessors? What are the skills to become a successful automation tester in 2019? Let’s find out.
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
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!!