Best Python code snippet using avocado_python
common.py
Source:common.py
...34 _stderr = file('/tmp/stderr', 'w+')35 sys.stderr = os.fdopen(os.dup(2), 'w')36 os.close(2)37 os.dup(_stderr.fileno())38def enable_stderr():39 global _stderr40 41 os.close(2)42 os.dup(sys.stderr.fileno())43 _stderr.seek(0, 0)44 data = _stderr.read()45 _stderr.close()46 os.remove('/tmp/stderr')47 return data48def run_silent(function, *args, **kwargs):49 disable_stderr()50 try:51 function(*args, **kwargs)52 except Exception, exc:53 enable_stderr()54 raise exc55 56 output = enable_stderr()57 return output58class TestCase(unittest.TestCase):59 _types = [gst.Object, gst.MiniObject]60 def gccollect(self):61 # run the garbage collector62 ret = 063 gst.debug('garbage collecting')64 while True:65 c = gc.collect()66 ret += c67 if c == 0: break68 gst.debug('done garbage collecting, %d objects' % ret)69 return ret70 def gctrack(self):...
log.py
Source:log.py
1import sys2import gevent3from lithoxyl import Logger4from lithoxyl.sensible import SensibleField, SensibleSink, SensibleFormatter5from lithoxyl.emitters import StreamEmitter6def get_current_gthreadid(record):7 return id(gevent.getcurrent())8class SupportLogger(Logger):9 pass10url_log = SupportLogger('url')11worker_log = SupportLogger('worker')12support_log = SupportLogger('support')13extra_fields = [SensibleField('current_gthread_id' , 'd',14 get_current_gthreadid, quote=False)]15# TODO: create/attach this in context16stderr_fmt = SensibleFormatter('{iso_end_local_notz} {module_path}'17 ' ({current_gthread_id}) - {message}',18 extra_fields=extra_fields)19stderr_emt = StreamEmitter('stderr')20stderr_sink = SensibleSink(formatter=stderr_fmt,21 emitter=stderr_emt,22 on='end')23url_log.add_sink(stderr_sink)24worker_log.add_sink(stderr_sink)25support_log.add_sink(stderr_sink)26#url_log.critical('serve_http_request').success('{method} {url}', method='GET', url='/')27class LoggingContext(object):28 logger_type = SupportLogger29 def __init__(self, level=None, enable_stderr=True):30 self.level = level31 self.enable_stderr = enable_stderr32 self.loggers = {}33 self.module_loggers = {}34 self.default_logger = support_log35 def get_module_logger(self):36 module_name = sys._getframe(1).f_globals.get('__name__', '<module>')37 try:38 ret = self.module_loggers[module_name]39 except KeyError:40 ret = self.logger_type(name=module_name, module=module_name)41 self.module_loggers[module_name] = ret42 if self.enable_stderr:43 ret.add_sink(stderr_sink)44 return ret45 def get_logger(self, name):46 try:47 ret = self.loggers[name]48 except KeyError:49 ret = self.loggers[name] = self.logger_type(name)50 return ret51 def debug(self, *a, **kw):52 if len(a) == 2:53 log_name, record_name = a54 return self.get_logger(log_name).debug(record_name, **kw)55 return self.default_logger.debug(*a, **kw)56 def info(self, *a, **kw):57 if len(a) == 2:58 log_name, record_name = a59 return self.get_logger(log_name).info(record_name, **kw)60 return self.default_logger.info(*a, **kw)61 def critical(self, *a, **kw):62 if len(a) == 2:63 log_name, record_name = a64 return self.get_logger(log_name).critical(record_name, **kw)...
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!!