def pytest_collection_modifyitems(config, items): # # Handle slow tests marker # option_markers = {"--runslow": "slow", "--run-nightly": "nightly"} for option, marker in option_markers.items(): option_is_set = config.getoption(option) if option_is_set: continue skip_reason = pytest.mark.skip( reason= f"need {option} option to run tests marked with '@pytest.mark.{marker}'" ) for item in items: if marker in item.keywords: item.add_marker(skip_reason) # # Handle Log Level # log_level_name = config.getoption("--log-level", "info", skip=True) GlobalLoggerSettings.stop_sentry_logging() GlobalLoggerSettings.set_log_level(log_level_name) GlobalLoggerSettings.start_text_file_logging() GlobalLoggerSettings.start_json_file_logging()
def pytest_collection_modifyitems(config, items): # # Handle slow tests marker # if not config.getoption("--runslow"): # --runslow given in cli: do not skip slow tests skip_slow = pytest.mark.skip(reason="need --runslow option to run") for item in items: if "slow" in item.keywords: item.add_marker(skip_slow) # # Handle Log Level # log_level_name = config.getoption("--log-level", "info", skip=True) GlobalLoggerSettings.set_log_level(log_level_name) GlobalLoggerSettings.start_text_file_logging() GlobalLoggerSettings.start_json_file_logging()
import maya from nucypher.blockchain.eth.signers.base import Signer from nucypher.characters.lawful import Alice, Bob from nucypher.characters.lawful import Enrico as Enrico from nucypher.crypto.powers import SigningPower, DecryptingPower from nucypher.policy.payment import SubscriptionManagerPayment from nucypher.utilities.ethereum import connect_web3_provider from nucypher.utilities.logging import GlobalLoggerSettings ###################### # Boring setup stuff # ###################### LOG_LEVEL = 'info' GlobalLoggerSettings.set_log_level(log_level_name=LOG_LEVEL) GlobalLoggerSettings.start_console_logging() BOOK_PATH = Path('finnegans-wake-excerpt.txt') try: # Replace with ethereum RPC endpoint L1_PROVIDER = os.environ['DEMO_L1_PROVIDER_URI'] L2_PROVIDER = os.environ['DEMO_L2_PROVIDER_URI'] # Replace with wallet filepath. WALLET_FILEPATH = os.environ['DEMO_L2_WALLET_FILEPATH'] SIGNER_URI = f'keystore://{WALLET_FILEPATH}' # Replace with alice's ethereum address
def __init__(self, json_ipc: bool, verbose: bool, quiet: bool, no_logs: bool, console_logs: bool, file_logs: bool, sentry_logs: bool, log_level: bool, debug: bool): self.log = Logger(self.__class__.__name__) # Session Emitter for pre and post character control engagement. if verbose and quiet: raise click.BadOptionUsage( option_name="quiet", message="--verbose and --quiet are mutually exclusive " "and cannot be used at the same time.") if verbose: GroupGeneralConfig.verbosity = 2 elif quiet: GroupGeneralConfig.verbosity = 0 else: GroupGeneralConfig.verbosity = 1 if json_ipc: GlobalLoggerSettings._json_ipc = True # TODO #1754 emitter = JSONRPCStdoutEmitter( verbosity=GroupGeneralConfig.verbosity) else: emitter = StdoutEmitter(verbosity=GroupGeneralConfig.verbosity) self.emitter = emitter if verbose: self.emitter.message("Verbose mode is enabled", color='blue') # Logging if debug and no_logs: message = "--debug and --no-logs cannot be used at the same time." raise click.BadOptionUsage(option_name="no-logs", message=message) # Defaults if file_logs is None: file_logs = self.log_to_file if sentry_logs is None: sentry_logs = self.log_to_sentry if debug: console_logs = True file_logs = True sentry_logs = False log_level = 'debug' if no_logs: console_logs = False file_logs = False sentry_logs = False if json_ipc: console_logs = False GlobalLoggerSettings.set_log_level(log_level_name=log_level) if console_logs: GlobalLoggerSettings.start_console_logging() if file_logs: GlobalLoggerSettings.start_text_file_logging() GlobalLoggerSettings.start_json_file_logging() if sentry_logs: GlobalLoggerSettings.start_sentry_logging(self.sentry_endpoint) if json_ipc: GlobalLoggerSettings.stop_console_logging() # JSON-RPC Protection self.debug = debug self.json_ipc = json_ipc
def setup(): """Prepares the filesystem and logger for grant metrics collection""" shutil.rmtree(TEMP_ALICE_DIR, ignore_errors=True) GlobalLoggerSettings.start_console_logging() GlobalLoggerSettings.set_log_level('info')
def set_options(self, mock_networking, no_registry, json_ipc, verbose, quiet, no_logs, console_logs, file_logs, sentry_logs, log_level, debug): # Session Emitter for pre and post character control engagement. if verbose and quiet: raise click.BadOptionUsage( option_name="quiet", message="--verbose and --quiet are mutually exclusive " "and cannot be used at the same time.") if verbose: verbosity = 2 elif quiet: verbosity = 0 else: verbosity = 1 if json_ipc: emitter = JSONRPCStdoutEmitter(verbosity=verbosity) else: emitter = StdoutEmitter(verbosity=verbosity) self.attach_emitter(emitter) if verbose: self.emitter.message("Verbose mode is enabled", color='blue') # Logging if debug and no_logs: raise click.BadOptionUsage( option_name="no-logs", message="--debug and --no-logs cannot be used at the same time." ) # Defaults if file_logs is None: file_logs = self.log_to_file if sentry_logs is None: sentry_logs = self.log_to_sentry if debug: console_logs = True file_logs = True sentry_logs = False log_level = 'debug' if no_logs: console_logs = False file_logs = False sentry_logs = False GlobalLoggerSettings.set_log_level(log_level_name=log_level) if console_logs: GlobalLoggerSettings.start_console_logging() if file_logs: GlobalLoggerSettings.start_text_file_logging() GlobalLoggerSettings.start_json_file_logging() if sentry_logs: GlobalLoggerSettings.start_sentry_logging(self.sentry_endpoint) # CLI Session Configuration self.mock_networking = mock_networking self.no_registry = no_registry self.debug = debug self.json_ipc = json_ipc # Only used for testing outputs; # Redirects outputs to in-memory python containers. if mock_networking: self.emitter.message("WARNING: Mock networking is enabled") self.middleware = MockRestMiddleware() else: self.middleware = RestMiddleware()
from nucypher.utilities.logging import GlobalLoggerSettings from nucypher.utilities.sandbox.constants import TEMPORARY_DOMAIN ###################### # Boring setup stuff # ###################### # Execute the download script (download_finnegans_wake.sh) to retrieve the book BOOK_PATH = os.path.join('.', 'finnegans-wake.txt') # Change this value to to perform more or less total re-encryptions # in order to avoid processing the entire book's text. (it's long) NUMBER_OF_LINES_TO_REENCRYPT = 25 # Twisted Logger GlobalLoggerSettings.set_log_level(log_level_name='debug') GlobalLoggerSettings.start_console_logging() ####################################### # Finnegan's Wake on NuCypher Testnet # # (will fail with bad connection) ##### ####################################### # if your ursulas are NOT running on your current host, # run like this: python finnegans-wake-demo.py 172.28.1.3:11500 # otherwise the default will be fine. try: SEEDNODE_URI = sys.argv[1] except IndexError: SEEDNODE_URI = "localhost:11500"
import os from pathlib import Path from web3.main import Web3 from nucypher.blockchain.eth.signers.base import Signer from nucypher.characters.lawful import Alice, Bob, Ursula from nucypher.characters.lawful import Enrico as Enrico from nucypher.crypto.powers import SigningPower, DecryptingPower from nucypher.utilities.ethereum import connect_web3_provider from nucypher.utilities.logging import GlobalLoggerSettings ###################### # Boring setup stuff # ###################### GlobalLoggerSettings.set_log_level(log_level_name='info') GlobalLoggerSettings.start_console_logging() BOOK_PATH = Path('finnegans-wake-excerpt.txt') try: # Replace with ethereum RPC endpoint ETH_PROVIDER_URI = os.environ['DEMO_ETH_PROVIDER_URI'] # Replace with wallet filepath. WALLET_FILEPATH = os.environ['DEMO_WALLET_FILEPATH'] SIGNER_URI = f'keystore://{WALLET_FILEPATH}' # Replace with alice's ethereum address ALICE_ADDRESS = os.environ['DEMO_ALICE_ADDRESS']