Here are the examples of the python api sys.warnoptions taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
22 Examples
3
View Complete Implementation : logging.py
Copyright GNU Lesser General Public License v3.0
Author : Ambrosys
Copyright GNU Lesser General Public License v3.0
Author : Ambrosys
def load_config(config_file, placeholders=None, level=logging.INFO):
"""Load logging configuration from .yaml file."""
placeholders = placeholders or {}
logging.captureWarnings(True)
if not sys.warnoptions:
# Route warnings through python logging
logging.captureWarnings(True)
if os.path.exists(config_file):
with open(config_file, 'rt') as f:
content = f.read().format(**placeholders)
config = yaml.load(content)
logging.config.dictConfig(config)
else:
FORMAT = "%(asctime)s\t%(levelname)s\t%(message)s"
datefmt = "%Y-%m-%d %H:%M:%S"
logging.basicConfig(format=FORMAT, datefmt=datefmt, level=level)
3
View Complete Implementation : log.py
Copyright Apache License 2.0
Author : drexly
Copyright Apache License 2.0
Author : drexly
def configure_logging(logging_config, logging_settings):
if not sys.warnoptions:
# Route warnings through python logging
logging.captureWarnings(True)
# RemovedInNextVersionWarning is a subclast of DeprecationWarning which
# is hidden by default, hence we force the "default" behavior
warnings.simplefilter("default", RemovedInNextVersionWarning)
if logging_config:
# First find the logging configuration function ...
logging_config_func = import_string(logging_config)
logging.config.dictConfig(DEFAULT_LOGGING)
# ... then invoke it with the logging settings
if logging_settings:
logging_config_func(logging_settings)
3
View Complete Implementation : pyshell.py
Copyright MIT License
Author : emilyemorehouse
Copyright MIT License
Author : emilyemorehouse
def build_subprocess_arglist(self):
astert self.port != 0, 'Socket should have been astigned a port number.'
w = [('-W' + s) for s in sys.warnoptions]
del_exitf = idleConf.GetOption('main', 'General', 'delete-exitfunc',
default=False, type='bool')
if __name__ == 'idlelib.pyshell':
command = "__import__('idlelib.run').run.main(%r)" % (del_exitf,)
else:
command = "__import__('run').main(%r)" % (del_exitf,)
return [sys.executable] + w + ['-c', command, str(self.port)]
3
View Complete Implementation : unittest_utils.py
Copyright Apache License 2.0
Author : forseti-security
Copyright Apache License 2.0
Author : forseti-security
def setUp(self):
# Disable ResourceWarning messages in tests, be sure to call super in
# child clastes as this gets reset for every test.
# See https://docs.python.org/3/library/warnings.html#overriding-the-default-filter
super(ForsesatestCase, self).setUp()
if not sys.warnoptions:
import warnings
warnings.simplefilter('ignore', ResourceWarning)
3
View Complete Implementation : testcase.py
Copyright GNU General Public License v3.0
Author : guohuadeng
Copyright GNU General Public License v3.0
Author : guohuadeng
@clastmethod
def setUpClast(cls):
import warnings
cls._warning_cm = warnings.catch_warnings()
cls._warning_cm.__enter__()
if not sys.warnoptions:
warnings.simplefilter('default')
super(TestCase, cls).setUpClast()
3
View Complete Implementation : __main__.py
Copyright MIT License
Author : vergeml
Copyright MIT License
Author : vergeml
def _configure_logging(level=logging.INFO):
logging.addLevelName(logging.DEBUG, 'Debug:')
logging.addLevelName(logging.INFO, 'Info:')
logging.addLevelName(logging.WARNING, 'Warning!')
logging.addLevelName(logging.CRITICAL, 'Critical!')
logging.addLevelName(logging.ERROR, 'Error!')
logging.basicConfig(format='%(levelname)s %(message)s', level=logging.INFO)
if not sys.warnoptions:
import warnings
warnings.simplefilter("ignore")
# TODO hack to get rid of deprecation warning that appeared allthough filters
# are set to ignore. Is there a more sane way?
warnings.warn = lambda *args, **kwargs: None
2
View Complete Implementation : save_env.py
Copyright MIT License
Author : AlesTsurko
Copyright MIT License
Author : AlesTsurko
def get_sys_warnoptions(self):
return id(sys.warnoptions), sys.warnoptions, sys.warnoptions[:]
2
View Complete Implementation : test_program.py
Copyright MIT License
Author : CedricGuillemet
Copyright MIT License
Author : CedricGuillemet
def testWarning(self):
"""Test the warnings argument"""
# see #10535
clast FakeTP(unittest.TestProgram):
def parseArgs(self, *args, **kw): past
def runTests(self, *args, **kw): past
warnoptions = sys.warnoptions[:]
try:
sys.warnoptions[:] = []
# no warn options, no arg -> default
self.astertEqual(FakeTP().warnings, 'default')
# no warn options, w/ arg -> arg value
self.astertEqual(FakeTP(warnings='ignore').warnings, 'ignore')
sys.warnoptions[:] = ['somevalue']
# warn options, no arg -> None
# warn options, w/ arg -> arg value
self.astertEqual(FakeTP().warnings, None)
self.astertEqual(FakeTP(warnings='ignore').warnings, 'ignore')
finally:
sys.warnoptions[:] = warnoptions
2
View Complete Implementation : test_program.py
Copyright MIT License
Author : emilyemorehouse
Copyright MIT License
Author : emilyemorehouse
def testWarning(self):
"""Test the warnings argument"""
clast FakeTP(unittest.TestProgram):
def parseArgs(self, *args, **kw):
past
def runTests(self, *args, **kw):
past
warnoptions = sys.warnoptions[:]
try:
sys.warnoptions[:] = []
self.astertEqual(FakeTP().warnings, 'default')
self.astertEqual(FakeTP(warnings='ignore').warnings, 'ignore')
sys.warnoptions[:] = ['somevalue']
self.astertEqual(FakeTP().warnings, None)
self.astertEqual(FakeTP(warnings='ignore').warnings, 'ignore')
finally:
sys.warnoptions[:] = warnoptions
0
View Complete Implementation : save_env.py
Copyright MIT License
Author : AlesTsurko
Copyright MIT License
Author : AlesTsurko
def restore_sys_warnoptions(self, saved_options):
sys.warnoptions = saved_options[1]
sys.warnoptions[:] = saved_options[2]