def test_ascii_in_unicode_out(self):
# ASCII input is converted to Unicode. The original_encoding
# attribute is set to 'utf-8', a superset of ASCII.
chardet = bs4.dammit.chardet_dammit
logging.disable(logging.WARNING)
try:
def noop(str):
return None
# Disable chardet, which will realize that the ASCII is ASCII.
bs4.dammit.chardet_dammit = noop
ascii = b"<foo>a</foo>"
soup_from_ascii = self.soup(ascii)
unicode_output = soup_from_ascii.decode()
self.assertTrue(isinstance(unicode_output, unicode))
self.assertEqual(unicode_output, self.document_for(ascii.decode()))
self.assertEqual(soup_from_ascii.original_encoding.lower(), "utf-8")
finally:
logging.disable(logging.NOTSET)
bs4.dammit.chardet_dammit = chardet
python类disable()的实例源码
test_soup.py 文件源码
项目:ServerlessCrawler-VancouverRealState
作者: MarcelloLins
项目源码
文件源码
阅读 26
收藏 0
点赞 0
评论 0
def configure_logger(log_level):
"""Configure the program's logger.
:param log_level: Log level for configuring logging
:type log_level: str
:rtype: None
"""
if log_level is None:
logging.disable(logging.CRITICAL)
return None
if log_level in constants.VALID_LOG_LEVEL_VALUES:
logging.basicConfig(
format=('%(threadName)s: '
'%(asctime)s '
'%(pathname)s:%(funcName)s:%(lineno)d - '
'%(message)s'),
stream=sys.stderr,
level=log_level.upper())
return None
msg = 'Log level set to an unknown value {!r}. Valid values are {!r}'
raise DCOSException(
msg.format(log_level, constants.VALID_LOG_LEVEL_VALUES))
def test_ascii_in_unicode_out(self):
# ASCII input is converted to Unicode. The original_encoding
# attribute is set to 'utf-8', a superset of ASCII.
chardet = bs4.dammit.chardet_dammit
logging.disable(logging.WARNING)
try:
def noop(str):
return None
# Disable chardet, which will realize that the ASCII is ASCII.
bs4.dammit.chardet_dammit = noop
ascii = b"<foo>a</foo>"
soup_from_ascii = self.soup(ascii)
unicode_output = soup_from_ascii.decode()
self.assertTrue(isinstance(unicode_output, unicode))
self.assertEqual(unicode_output, self.document_for(ascii.decode()))
self.assertEqual(soup_from_ascii.original_encoding.lower(), "utf-8")
finally:
logging.disable(logging.NOTSET)
bs4.dammit.chardet_dammit = chardet
def test_ascii_in_unicode_out(self):
# ASCII input is converted to Unicode. The original_encoding
# attribute is set to 'utf-8', a superset of ASCII.
chardet = bs4.dammit.chardet_dammit
logging.disable(logging.WARNING)
try:
def noop(str):
return None
# Disable chardet, which will realize that the ASCII is ASCII.
bs4.dammit.chardet_dammit = noop
ascii = b"<foo>a</foo>"
soup_from_ascii = self.soup(ascii)
unicode_output = soup_from_ascii.decode()
self.assertTrue(isinstance(unicode_output, unicode))
self.assertEqual(unicode_output, self.document_for(ascii.decode()))
self.assertEqual(soup_from_ascii.original_encoding.lower(), "utf-8")
finally:
logging.disable(logging.NOTSET)
bs4.dammit.chardet_dammit = chardet
def test_ascii_in_unicode_out(self):
# ASCII input is converted to Unicode. The original_encoding
# attribute is set to 'utf-8', a superset of ASCII.
chardet = bs4.dammit.chardet_dammit
logging.disable(logging.WARNING)
try:
def noop(str):
return None
# Disable chardet, which will realize that the ASCII is ASCII.
bs4.dammit.chardet_dammit = noop
ascii = b"<foo>a</foo>"
soup_from_ascii = self.soup(ascii)
unicode_output = soup_from_ascii.decode()
self.assertTrue(isinstance(unicode_output, unicode))
self.assertEqual(unicode_output, self.document_for(ascii.decode()))
self.assertEqual(soup_from_ascii.original_encoding.lower(), "utf-8")
finally:
logging.disable(logging.NOTSET)
bs4.dammit.chardet_dammit = chardet
def test_ascii_in_unicode_out(self):
# ASCII input is converted to Unicode. The original_encoding
# attribute is set to 'utf-8', a superset of ASCII.
chardet = bs4.dammit.chardet_dammit
logging.disable(logging.WARNING)
try:
def noop(str):
return None
# Disable chardet, which will realize that the ASCII is ASCII.
bs4.dammit.chardet_dammit = noop
ascii = b"<foo>a</foo>"
soup_from_ascii = self.soup(ascii)
unicode_output = soup_from_ascii.decode()
self.assertTrue(isinstance(unicode_output, unicode))
self.assertEqual(unicode_output, self.document_for(ascii.decode()))
self.assertEqual(soup_from_ascii.original_encoding.lower(), "utf-8")
finally:
logging.disable(logging.NOTSET)
bs4.dammit.chardet_dammit = chardet
def test_ascii_in_unicode_out(self):
# ASCII input is converted to Unicode. The original_encoding
# attribute is set to 'utf-8', a superset of ASCII.
chardet = bs4.dammit.chardet_dammit
logging.disable(logging.WARNING)
try:
def noop(str):
return None
# Disable chardet, which will realize that the ASCII is ASCII.
bs4.dammit.chardet_dammit = noop
ascii = b"<foo>a</foo>"
soup_from_ascii = self.soup(ascii)
unicode_output = soup_from_ascii.decode()
self.assertTrue(isinstance(unicode_output, str))
self.assertEqual(unicode_output, self.document_for(ascii.decode()))
self.assertEqual(soup_from_ascii.original_encoding.lower(), "utf-8")
finally:
logging.disable(logging.NOTSET)
bs4.dammit.chardet_dammit = chardet
def test_process_msg_exception(self):
"""
Tests the process_msg function when an exception is raised.
"""
logging.disable(logging.NOTSET)
with patch('receiver.receiver.logging.getLogger', return_value=LOGGER):
with patch('receiver.receiver.json.loads', side_effect=Exception('foo')):
with LogCapture() as log_capture:
process_msg(**self.kwargs)
log_capture.check(
('receiver',
'ERROR',
'An error occurred while processing the message \'{"@uuid": "12345", '
'"collection": "elasticsearch.test_index.test_logs", "message": '
'"foobar"}\':\n'
' foo'),
)
test_l3_opencontrail.py 文件源码
项目:networking-opencontrail
作者: openstack
项目源码
文件源码
阅读 29
收藏 0
点赞 0
评论 0
def setUp(self):
super(L3OpenContrailTestCases, self).setUp()
logging.disable(logging.CRITICAL)
test_l3_opencontrail.py 文件源码
项目:networking-opencontrail
作者: openstack
项目源码
文件源码
阅读 30
收藏 0
点赞 0
评论 0
def tearDown(self):
super(L3OpenContrailTestCases, self).tearDown()
logging.disable(logging.NOTSET)
test_drv_opencontrail.py 文件源码
项目:networking-opencontrail
作者: openstack
项目源码
文件源码
阅读 28
收藏 0
点赞 0
评论 0
def setUp(self):
super(ApiRequestsTestCases, self).setUp()
logging.disable(logging.CRITICAL)
test_drv_opencontrail.py 文件源码
项目:networking-opencontrail
作者: openstack
项目源码
文件源码
阅读 31
收藏 0
点赞 0
评论 0
def tearDown(self):
super(ApiRequestsTestCases, self).tearDown()
logging.disable(logging.NOTSET)
test_drv_opencontrail.py 文件源码
项目:networking-opencontrail
作者: openstack
项目源码
文件源码
阅读 28
收藏 0
点赞 0
评论 0
def setUp(self):
super(ApiCrudTestCases, self).setUp()
logging.disable(logging.CRITICAL)
test_contrail_driver_base.py 文件源码
项目:networking-opencontrail
作者: openstack
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
def setUp(self):
super(ErrorTestCases, self).setUp()
logging.disable(logging.CRITICAL)
test_contrail_driver_base.py 文件源码
项目:networking-opencontrail
作者: openstack
项目源码
文件源码
阅读 26
收藏 0
点赞 0
评论 0
def tearDown(self):
super(ErrorTestCases, self).tearDown()
logging.disable(logging.NOTSET)
test_contrail_driver_base.py 文件源码
项目:networking-opencontrail
作者: openstack
项目源码
文件源码
阅读 27
收藏 0
点赞 0
评论 0
def setUp(self):
super(NetworkTestCases, self).setUp()
logging.disable(logging.CRITICAL)
test_contrail_driver_base.py 文件源码
项目:networking-opencontrail
作者: openstack
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def tearDown(self):
super(NetworkTestCases, self).tearDown()
logging.disable(logging.NOTSET)
test_contrail_driver_base.py 文件源码
项目:networking-opencontrail
作者: openstack
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def setUp(self):
super(SubnetTestCases, self).setUp()
logging.disable(logging.CRITICAL)
test_contrail_driver_base.py 文件源码
项目:networking-opencontrail
作者: openstack
项目源码
文件源码
阅读 26
收藏 0
点赞 0
评论 0
def setUp(self):
super(SecurityGroupTestCases, self).setUp()
logging.disable(logging.CRITICAL)
test_contrail_driver_base.py 文件源码
项目:networking-opencontrail
作者: openstack
项目源码
文件源码
阅读 25
收藏 0
点赞 0
评论 0
def tearDown(self):
super(SecurityGroupTestCases, self).tearDown()
logging.disable(logging.NOTSET)