Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'coloredlogs' in functional components in Python. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
def test_colorize_auto_tty(self):
# with colorize=Colorize.AUTO on a stream connected to a TTY,
# return colorizing formatter
stream = _get_tty_stream()
cls = fancylogger._screenLogFormatterFactory(fancylogger.Colorize.AUTO, stream)
self.assertEqual(cls, coloredlogs.ColoredFormatter)
def test_increase_verbosity(self):
"""Make sure increase_verbosity() respects default and custom levels."""
# Start from a known state.
set_level(logging.INFO)
assert get_level() == logging.INFO
# INFO -> VERBOSE.
increase_verbosity()
assert get_level() == logging.VERBOSE
# VERBOSE -> DEBUG.
increase_verbosity()
assert get_level() == logging.DEBUG
# DEBUG -> SPAM.
increase_verbosity()
assert get_level() == logging.SPAM
# SPAM -> NOTSET.
increase_verbosity()
assert get_level() == logging.NOTSET
# NOTSET -> NOTSET.
increase_verbosity()
assert get_level() == logging.NOTSET
1. Sets up verbose logging to the terminal. When a test fails the logging
output can help to perform a post-mortem analysis of the failure in
question (even when its hard to reproduce locally). This is especially
useful when debugging remote test failures, whether they happened on
Travis CI or a user's local system.
2. Creates temporary directories where the pip download cache and the
pip-accel binary cache are located. Isolating the pip-accel binary cache
from the user's system is meant to ensure that the tests are as
independent from the user's system as possible. The function
:func:`tearDownModule` is responsible for cleaning up the temporary
directory after the test suite finishes.
"""
# Initialize verbose logging to the terminal.
coloredlogs.install()
coloredlogs.increase_verbosity()
# Create temporary directories to store the pip download cache and
# pip-accel's binary cache, to make sure these tests run isolated from the
# rest of the system.
os.environ['PIP_DOWNLOAD_CACHE'] = create_temporary_directory()
os.environ['PIP_ACCEL_CACHE'] = create_temporary_directory()
def setUp(self):
coloredlogs.install()
coloredlogs.set_level(logging.DEBUG)
def test_increase_verbosity(self):
"""Make sure increase_verbosity() respects default and custom levels."""
# Start from a known state.
set_level(logging.INFO)
assert get_level() == logging.INFO
# INFO -> VERBOSE.
increase_verbosity()
assert get_level() == logging.VERBOSE
# VERBOSE -> DEBUG.
increase_verbosity()
assert get_level() == logging.DEBUG
# DEBUG -> SPAM.
increase_verbosity()
assert get_level() == logging.SPAM
# SPAM -> NOTSET.
increase_verbosity()
assert get_level() == logging.NOTSET
# NOTSET -> NOTSET.
increase_verbosity()
assert get_level() == logging.NOTSET
def test_decrease_verbosity(self):
"""Make sure decrease_verbosity() respects default and custom levels."""
# Start from a known state.
set_level(logging.INFO)
assert get_level() == logging.INFO
# INFO -> NOTICE.
decrease_verbosity()
assert get_level() == logging.NOTICE
# NOTICE -> WARNING.
decrease_verbosity()
assert get_level() == logging.WARNING
# WARNING -> SUCCESS.
decrease_verbosity()
assert get_level() == logging.SUCCESS
# SUCCESS -> ERROR.
decrease_verbosity()
assert get_level() == logging.ERROR
# ERROR -> CRITICAL.
decrease_verbosity()
assert get_level() == logging.CRITICAL
def setUp(self):
"""Reset logging verbosity before each test."""
coloredlogs.set_level(logging.INFO)
def test_is_verbose(self):
"""Make sure is_verbose() does what it should :-)."""
set_level(logging.INFO)
assert not is_verbose()
set_level(logging.DEBUG)
assert is_verbose()
set_level(logging.VERBOSE)
assert is_verbose()
import time
import logging
import coloredlogs
from monero_glue.messages.DebugMoneroDiagRequest import DebugMoneroDiagRequest
from trezorlib import debuglink, device
from monero_glue.agent import agent_lite
from monero_glue.xmr import crypto, monero, wallet
from monero_glue.xmr import bulletproof as bp
from monero_glue.xmr import bulletproof_cl as bpcl
from monero_glue_test.base_agent_test import BaseAgentTest
from monero_glue.trezor import manager as tmanager
logger = logging.getLogger(__name__)
coloredlogs.CHROOT_FILES = []
coloredlogs.install(level=logging.INFO, use_chroot=False)
class TrezorTest(BaseAgentTest):
def __init__(self, *args, **kwargs):
super(TrezorTest, self).__init__(*args, **kwargs)
self.trezor_proxy = None # type: tmanager.Trezor
self.agent = None # type: agent_lite.Agent
self.creds = None
self.test_only_tsx = False
self.is_debug = True
self.do_timing = int(os.getenv('TREZOR_TEST_TIMING', '1'))
self.do_bp_off = int(os.getenv('TREZOR_TEST_BP_OFF', '0'))
self.time_start = None
self.timing_bins = {}
def test_find_hostname(self):
"""Make sure :func:`~find_hostname()` works correctly."""
assert find_hostname()
# Create a temporary file as a placeholder for e.g. /etc/debian_chroot.
fd, temporary_file = tempfile.mkstemp()
try:
with open(temporary_file, 'w') as handle:
handle.write('first line\n')
handle.write('second line\n')
CHROOT_FILES.insert(0, temporary_file)
# Make sure the chroot file is being read.
assert find_hostname() == 'first line'
finally:
# Clean up.
CHROOT_FILES.pop(0)
os.unlink(temporary_file)
# Test that unreadable chroot files don't break coloredlogs.
try:
CHROOT_FILES.insert(0, temporary_file)
# Make sure that a usable value is still produced.
assert find_hostname()
finally:
# Clean up.
CHROOT_FILES.pop(0)