How to use verbosity method in tox

Best Python code snippet using tox_python

logtools.py

Source:logtools.py Github

copy

Full Screen

1import enum2import abc3import warnings4@enum.unique5class LogVerbosity(enum.Enum):6 """7 Represents log verbosity levels. To be used in the log function.8 """9 # No messages will be logged10 SILENT = 011 # Only errors will be logged12 ERRORS = 113 # Only warnings and errors will be logged14 WARNINGS = 215 # Only messages, warning, and errors wil be logged16 MESSAGES = 317 # Everything will be logged18 EVERYTHING = 419 def __lt__(self, other):20 return self.value < other.value21 def __gt__(self, other):22 return self.value > other.value23 def __le__(self, other):24 return self.value <= other.value25 def __ge__(self, other):26 return self.value >= other.value27 def __eq__(self, other):28 return self.value == other.value29 def __hash__(self):30 return hash(self.value)31class TempVerbosityLevel:32 """33 Context manager that manages a temporary LogVerbosity level for a Logger34 """35 def __init__(self, logger, verbosity):36 self.current_verbosity = verbosity37 self.old_verbosity = logger.verbosity38 self.logger = logger39 def __enter__(self):40 self.logger.verbosity = self.current_verbosity41 def __exit__(self, exc_type, exc_val, exc_tb):42 self.logger.verbosity = self.old_verbosity43class Logger:44 """45 Abstract base class for objects that log messages46 """47 def __init__(self):48 self.verbosity = LogVerbosity.WARNINGS49 def verbosity_temp(self, contextual_verbosity):50 """51 :param contextual_verbosity: The temporary verbosity level to change this Logger's verbosity to52 :return: A context manager that sets the verbosity to contextual_verbosity when entered and restores the53 current verbosity when exited54 """55 return TempVerbosityLevel(self, contextual_verbosity)56 # noinspection PyCallingNonCallable57 def log(self, message, message_importance=LogVerbosity.MESSAGES):58 """59 Logs a message with a given importance only if this Logger's current verbosity60 is greater than the message's importance.61 If an exception type that is a subclass of Warning is given as the message_importance, the message wil be62 logged as if WARNINGS were given **AND** via warnings.warn with the given Warning type as the warning63 category.64 If an exception type that is not a subclass of Warning is given as the message_importance, the message will be65 logged as if ERRORS were given **AND** an exception of the given type will be constructed and raised.66 If an exception object is given as the message_importance, the exception's message will be logged as if67 ERRORS were given and will have the exception's message appended to it **AND** the exception will be raised68 :param message: The message to log69 :param message_importance: A LogVerbosity level (please don't use SILENT because it doesn't make sense)70 """71 try:72 if self.verbosity >= message_importance:73 self(message, message_importance)74 return75 except AttributeError:76 pass77 try:78 # noinspection PyTypeChecker79 if self.verbosity >= LogVerbosity.WARNINGS and issubclass(message_importance, Warning):80 self(message, message_importance)81 warnings.warn(message, message_importance)82 return83 except TypeError:84 pass85 if self.verbosity >= LogVerbosity.ERRORS and isinstance(message_importance, BaseException):86 self(message + f'\n\n{type(message_importance).__name__}: {str(message_importance)}', message_importance)87 raise message_importance88 try:89 if self.verbosity >= LogVerbosity.ERRORS and issubclass(message_importance, BaseException):90 self(message, message_importance)91 # noinspection PyCallingNonCallable92 raise message_importance(message)93 except TypeError:94 pass95 @abc.abstractmethod96 def __call__(self, message, importance):97 """98 Actually logs a message99 :param message: The message to log100 :param importance: The message importance as passed to log (so it may be an Exception or Warning type)101 """102 pass103class DefaultLogger(Logger):104 """105 A Logger that logs MESSAGES via the print function, WARNINGS via warning.warn, and errors by raising them106 as an Exception if they were not passed as an exception to be raised107 """108 def __call__(self, message, importance):109 if isinstance(importance, LogVerbosity):110 if importance == LogVerbosity.ERRORS:111 raise Exception(message)112 elif importance == LogVerbosity.WARNINGS:113 warnings.warn(message)114 else:115 print(f'Simerse: {message}')...

Full Screen

Full Screen

ag_logging.py

Source:ag_logging.py Github

copy

Full Screen

...29# In interactive Python, logging echo is enabled by default.30if hasattr(sys, 'ps1') or hasattr(sys, 'ps2'):31 echo_log_to_stdout = True32@tf_export('autograph.set_verbosity')33def set_verbosity(level, alsologtostdout=False):34 """Sets the AutoGraph verbosity level.35 _Debug logging in AutoGraph_36 More verbose logging is useful to enable when filing bug reports or doing37 more in-depth debugging.38 There are two means to control the logging verbosity:39 * The `set_verbosity` function40 * The `AUTOGRAPH_VERBOSITY` environment variable41 `set_verbosity` takes precedence over the environment variable.42 For example:43 ```python44 import os45 import tensorflow as tf46 os.environ['AUTOGRAPH_VERBOSITY'] = 547 # Verbosity is now 548 tf.autograph.set_verbosity(0)49 # Verbosity is now 050 os.environ['AUTOGRAPH_VERBOSITY'] = 151 # No effect, because set_verbosity was already called.52 ```53 Logs entries are output to [absl](https://abseil.io)'s 54 [default output](https://abseil.io/docs/python/guides/logging),55 with `INFO` level.56 Logs can be mirrored to stdout by using the `alsologtostdout` argument.57 Mirroring is enabled by default when Python runs in interactive mode.58 Args:59 level: int, the verbosity level; larger values specify increased verbosity;60 0 means no logging. When reporting bugs, it is recommended to set this61 value to a larger number, like 10.62 alsologtostdout: bool, whether to also output log messages to `sys.stdout`.63 """64 global verbosity_level65 global echo_log_to_stdout66 verbosity_level = level67 echo_log_to_stdout = alsologtostdout68@tf_export('autograph.trace')69def trace(*args):70 """Traces argument information at compilation time.71 `trace` is useful when debugging, and it always executes during the tracing72 phase, that is, when the TF graph is constructed.73 _Example usage_74 ```python75 import tensorflow as tf76 for i in tf.range(10):77 tf.autograph.trace(i)78 # Output: <Tensor ...>79 ```80 Args:81 *args: Arguments to print to `sys.stdout`.82 """83 print(*args)84def get_verbosity():85 global verbosity_level86 if verbosity_level is not None:87 return verbosity_level88 return int(os.getenv(VERBOSITY_VAR_NAME, DEFAULT_VERBOSITY))89def has_verbosity(level):90 return get_verbosity() >= level91def _output_to_stdout(msg, *args, **kwargs):92 print(msg % args)93 if kwargs.get('exc_info', False):94 traceback.print_exc()95def error(level, msg, *args, **kwargs):96 if has_verbosity(level):97 logging.error(msg, *args, **kwargs)98 if echo_log_to_stdout:99 _output_to_stdout('ERROR: ' + msg, *args, **kwargs)100def log(level, msg, *args, **kwargs):101 if has_verbosity(level):102 logging.info(msg, *args, **kwargs)103 if echo_log_to_stdout:104 _output_to_stdout(msg, *args, **kwargs)105def warn(msg, *args, **kwargs):106 logging.warn(msg, *args, **kwargs)107 if echo_log_to_stdout:108 _output_to_stdout('WARNING: ' + msg, *args, **kwargs)...

Full Screen

Full Screen

verbosity.py

Source:verbosity.py Github

copy

Full Screen

1#BEGIN_LEGAL2#3#Copyright (c) 2018 Intel Corporation4#5# Licensed under the Apache License, Version 2.0 (the "License");6# you may not use this file except in compliance with the License.7# You may obtain a copy of the License at8#9# http://www.apache.org/licenses/LICENSE-2.010#11# Unless required by applicable law or agreed to in writing, software12# distributed under the License is distributed on an "AS IS" BASIS,13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14# See the License for the specific language governing permissions and15# limitations under the License.16# 17#END_LEGAL18_verbosity_options = []19def set_verbosity_options(options):20 global _verbosity_options21 _verbosity_options = options22def vflag():23 return 'flag' in _verbosity_options24def vnext():25 return 'next' in _verbosity_options26def vrearrange():27 return 'rearrange' in _verbosity_options28def vmacro():29 return 'macro' in _verbosity_options30def vreadyscan():31 return 'readyscan' in _verbosity_options32def vbitgroup():33 return 'bitgroup' in _verbosity_options34def vextract():35 return 'extract' in _verbosity_options36def vstack():37 return 'stack' in _verbosity_options38def vgraph_res():39 return 'graph_res' in _verbosity_options40def varraygen():41 return 'arraygen' in _verbosity_options42def viform():43 return 'iform' in _verbosity_options44def viclass():45 return 'iclass' in _verbosity_options46def vattr():47 return 'attribute' in _verbosity_options48def vopnd():49 return 'opnd' in _verbosity_options50def vlookup():51 return 'lookup' in _verbosity_options52def vopvis():53 return 'opvis' in _verbosity_options54def vcapture():55 return 'capture' in _verbosity_options56def vcapture1():57 return 'capture1' in _verbosity_options58def vcapture2():59 return 'capture2' in _verbosity_options60def vcapturefunc():61 return 'capture' in _verbosity_options62def vbind():63 return 'bind' in _verbosity_options64def vod():65 return 'od' in _verbosity_options66def vtrace():67 return 'trace' in _verbosity_options68def vparse():69 return 'parse' in _verbosity_options70def vpart():71 return 'partition' in _verbosity_options72def vbuild():73 return 'build' in _verbosity_options74def vmerge():75 return 'merge' in _verbosity_options76def verb1():77 return '1' in _verbosity_options78def verb2():79 return '2' in _verbosity_options80def verb3():81 return '3' in _verbosity_options82def verb4():83 return '4' in _verbosity_options84def verb5():85 return '5' in _verbosity_options86def verb6():87 return '6' in _verbosity_options88def verb7():89 return '7' in _verbosity_options90def vencfunc():91 return 'encfunc' in _verbosity_options92def vencode():93 return 'encode' in _verbosity_options94def vntname():95 return 'ntname' in _verbosity_options96def vtestingcond():97 return 'testingcond' in _verbosity_options98def vclassify():99 return 'classify' in _verbosity_options100def veparse():101 return 'eparse' in _verbosity_options102def veemit():103 return 'eemit' in _verbosity_options104def vignoreod():105 return 'ignoreod' in _verbosity_options106def vtuples():107 return 'tuples' in _verbosity_options108def vdumpinput():109 return 'dumpinput' in _verbosity_options110def vfinalize():111 return 'finalize' in _verbosity_options112def vopseq():113 return 'opseq' in _verbosity_options114def voperand():115 return 'operand' in _verbosity_options116def voperand2():117 return 'operand2' in _verbosity_options118def vinputs():119 return 'inputs' in _verbosity_options120def vread():121 return 'read' in _verbosity_options122def vcapture():123 return 'capture' in _verbosity_options124def vrule():125 return 'rule' in _verbosity_options126def vaction():127 return 'action' in _verbosity_options128def vblot():129 return 'blot' in _verbosity_options130def vild():131 return 'ild' in _verbosity_options132def vfuncgen():...

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 tox 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