本文整理汇总了Python中test.helper.capture_log函数的典型用法代码示例。如果您正苦于以下问题:Python capture_log函数的具体用法?Python capture_log怎么用?Python capture_log使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了capture_log函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_message_when_invalid
def test_message_when_invalid(self):
config['format_item'] = u'$artist - $album - $title'
config['format_album'] = u'$albumartist - $album'
# Test album with invalid mb_albumid.
# The default format for an album include $albumartist so
# set that here, too.
album_invalid = Item(
albumartist=u'album info',
album=u'album info',
mb_albumid=u'a1b2c3d4',
path=''
)
self.lib.add_album([album_invalid])
# default format
with capture_log('beets.mbsync') as logs:
self.run_command('mbsync')
e = u'mbsync: Skipping album with invalid mb_albumid: ' + \
u'album info - album info'
self.assertEqual(e, logs[0])
# custom format
with capture_log('beets.mbsync') as logs:
self.run_command('mbsync', '-f', "'$album'")
e = u"mbsync: Skipping album with invalid mb_albumid: 'album info'"
self.assertEqual(e, logs[0])
# restore the config
config['format_item'] = u'$artist - $album - $title'
config['format_album'] = u'$albumartist - $album'
# Test singleton with invalid mb_trackid.
# The default singleton format includes $artist and $album
# so we need to stub them here
item_invalid = Item(
artist=u'album info',
album=u'album info',
title=u'old title',
mb_trackid=u'a1b2c3d4',
path='',
)
self.lib.add(item_invalid)
# default format
with capture_log('beets.mbsync') as logs:
self.run_command('mbsync')
e = u'mbsync: Skipping singleton with invalid mb_trackid: ' + \
u'album info - album info - old title'
self.assertEqual(e, logs[0])
# custom format
with capture_log('beets.mbsync') as logs:
self.run_command('mbsync', '-f', "'$title'")
e = u"mbsync: Skipping singleton with invalid mb_trackid: 'old title'"
self.assertEqual(e, logs[0])
开发者ID:arogl,项目名称:beets,代码行数:56,代码来源:test_mbsync.py
示例2: test_command_logging
def test_command_logging(self):
self.config['verbose'] = 0
with helper.capture_log() as logs:
self.run_command('dummy')
self.assertIn('dummy: warning cmd', logs)
self.assertIn('dummy: info cmd', logs)
self.assertNotIn('dummy: debug cmd', logs)
for level in (1, 2):
self.config['verbose'] = level
with helper.capture_log() as logs:
self.run_command('dummy')
self.assertIn('dummy: warning cmd', logs)
self.assertIn('dummy: info cmd', logs)
self.assertIn('dummy: debug cmd', logs)
开发者ID:scztt,项目名称:beets,代码行数:15,代码来源:test_logging.py
示例3: test_command_level1
def test_command_level1(self):
self.config['verbose'] = 1
with helper.capture_log() as logs:
self.run_command('dummy')
self.assertIn(u'dummy: warning cmd', logs)
self.assertIn(u'dummy: info cmd', logs)
self.assertIn(u'dummy: debug cmd', logs)
开发者ID:Kraymer,项目名称:beets,代码行数:7,代码来源:test_logging.py
示例4: test_listener_level2
def test_listener_level2(self):
self.config['verbose'] = 2
with helper.capture_log() as logs:
plugins.send('dummy_event')
self.assertIn(u'dummy: warning listener', logs)
self.assertIn(u'dummy: info listener', logs)
self.assertIn(u'dummy: debug listener', logs)
开发者ID:Kraymer,项目名称:beets,代码行数:7,代码来源:test_logging.py
示例5: test_parse_release_without_required_fields
def test_parse_release_without_required_fields(self):
"""Test parsing of a release that does not have the required fields."""
release = Bag(data={}, refresh=lambda *args: None)
with capture_log() as logs:
d = DiscogsPlugin().get_album_info(release)
self.assertEqual(d, None)
self.assertIn('Release does not contain the required fields', logs[0])
开发者ID:arogl,项目名称:beets,代码行数:8,代码来源:test_discogs.py
示例6: test_import_stage_level2
def test_import_stage_level2(self):
self.config['verbose'] = 2
with helper.capture_log() as logs:
importer = self.create_importer()
importer.run()
self.assertIn(u'dummy: warning import_stage', logs)
self.assertIn(u'dummy: info import_stage', logs)
self.assertIn(u'dummy: debug import_stage', logs)
开发者ID:Kraymer,项目名称:beets,代码行数:8,代码来源:test_logging.py
示例7: test_itunesstore_requestexception
def test_itunesstore_requestexception(self):
responses.add(responses.GET, fetchart.ITunesStore.API_URL,
json={'error': 'not found'}, status=404)
expected = u'iTunes search failed: 404 Client Error'
with capture_log('beets.test_art') as logs:
with self.assertRaises(StopIteration):
next(self.source.get(self.album, self.settings, []))
self.assertIn(expected, logs[1])
开发者ID:beetbox,项目名称:beets,代码行数:9,代码来源:test_art.py
示例8: test_itunesstore_no_result
def test_itunesstore_no_result(self):
json = '{"results": []}'
self.mock_response(fetchart.ITunesStore.API_URL, json)
expected = u"got no results"
with capture_log('beets.test_art') as logs:
with self.assertRaises(StopIteration):
next(self.source.get(self.album, self.settings, []))
self.assertIn(expected, logs[1])
开发者ID:beetbox,项目名称:beets,代码行数:9,代码来源:test_art.py
示例9: test_itunesstore_returns_no_result_when_error_received
def test_itunesstore_returns_no_result_when_error_received(self):
json = '{"error": {"errors": [{"reason": "some reason"}]}}'
self.mock_response(fetchart.ITunesStore.API_URL, json)
expected = u"not found in json. Fields are"
with capture_log('beets.test_art') as logs:
with self.assertRaises(StopIteration):
next(self.source.get(self.album, self.settings, []))
self.assertIn(expected, logs[1])
开发者ID:beetbox,项目名称:beets,代码行数:9,代码来源:test_art.py
示例10: test_itunesstore_returns_no_result_with_malformed_response
def test_itunesstore_returns_no_result_with_malformed_response(self):
json = """bla blup"""
self.mock_response(fetchart.ITunesStore.API_URL, json)
expected = u"Could not decode json response:"
with capture_log('beets.test_art') as logs:
with self.assertRaises(StopIteration):
next(self.source.get(self.album, self.settings, []))
self.assertIn(expected, logs[1])
开发者ID:beetbox,项目名称:beets,代码行数:9,代码来源:test_art.py
示例11: test_message_when_skipping
def test_message_when_skipping(self):
config["format_item"] = u"$artist - $album - $title"
config["format_album"] = u"$albumartist - $album"
# Test album with no mb_albumid.
# The default format for an album include $albumartist so
# set that here, too.
album_invalid = Item(albumartist=u"album info", album=u"album info", path="")
self.lib.add_album([album_invalid])
# default format
with capture_log("beets.mbsync") as logs:
self.run_command("mbsync")
e = u"mbsync: Skipping album with no mb_albumid: " + u"album info - album info"
self.assertEqual(e, logs[0])
# custom format
with capture_log("beets.mbsync") as logs:
self.run_command("mbsync", "-f", "'$album'")
e = u"mbsync: Skipping album with no mb_albumid: 'album info'"
self.assertEqual(e, logs[0])
# restore the config
config["format_item"] = "$artist - $album - $title"
config["format_album"] = "$albumartist - $album"
# Test singleton with no mb_trackid.
# The default singleton format includes $artist and $album
# so we need to stub them here
item_invalid = Item(artist=u"album info", album=u"album info", title=u"old title", path="")
self.lib.add(item_invalid)
# default format
with capture_log("beets.mbsync") as logs:
self.run_command("mbsync")
e = u"mbsync: Skipping singleton with no mb_trackid: " + u"album info - album info - old title"
self.assertEqual(e, logs[0])
# custom format
with capture_log("beets.mbsync") as logs:
self.run_command("mbsync", "-f", "'$title'")
e = u"mbsync: Skipping singleton with no mb_trackid: 'old title'"
self.assertEqual(e, logs[0])
开发者ID:angelsanz,项目名称:beets,代码行数:43,代码来源:test_mbsync.py
示例12: __run
def __run(self, expected_lines, singletons=False):
self.load_plugins('filefilter')
import_files = [self.import_dir]
self._setup_import_session(singletons=singletons)
self.importer.paths = import_files
with capture_log() as logs:
self.importer.run()
self.unload_plugins()
FileFilterPlugin.listeners = None
logs = [line for line in logs if not line.startswith('Sending event:')]
self.assertEqual(logs, expected_lines)
开发者ID:Cornellio,项目名称:beets,代码行数:15,代码来源:test_filefilter.py
示例13: test_root_logger_levels
def test_root_logger_levels(self):
"""Root logger level should be shared between threads.
"""
self.config['threaded'] = True
blog.getLogger('beets').set_global_level(blog.WARNING)
with helper.capture_log() as logs:
importer = self.create_importer()
importer.run()
self.assertEqual(logs, [])
blog.getLogger('beets').set_global_level(blog.INFO)
with helper.capture_log() as logs:
importer = self.create_importer()
importer.run()
for l in logs:
self.assertIn(u"import", l)
self.assertIn(u"album", l)
blog.getLogger('beets').set_global_level(blog.DEBUG)
with helper.capture_log() as logs:
importer = self.create_importer()
importer.run()
self.assertIn(u"Sending event: database_change", logs)
开发者ID:Kraymer,项目名称:beets,代码行数:24,代码来源:test_logging.py
示例14: test_itunesstore_returns_result_without_artwork
def test_itunesstore_returns_result_without_artwork(self):
json = """{
"results":
[
{
"artistName": "some artist",
"collectionName": "some album"
}
]
}"""
self.mock_response(fetchart.ITunesStore.API_URL, json)
expected = u'Malformed itunes candidate'
with capture_log('beets.test_art') as logs:
with self.assertRaises(StopIteration):
next(self.source.get(self.album, self.settings, []))
self.assertIn(expected, logs[1])
开发者ID:beetbox,项目名称:beets,代码行数:17,代码来源:test_art.py
示例15: test_import_task_created
def test_import_task_created(self):
import_files = [self.import_dir]
self._setup_import_session(singletons=False)
self.importer.paths = import_files
with helper.capture_log() as logs:
self.importer.run()
self.unload_plugins()
# Exactly one event should have been imported (for the album).
# Sentinels do not get emitted.
self.assertEqual(logs.count('Sending event: import_task_created'), 1)
logs = [line for line in logs if not line.startswith('Sending event:')]
self.assertEqual(logs, [
'Album: {0}'.format(os.path.join(self.import_dir, 'album')),
' {0}'.format(self.file_paths[0]),
' {0}'.format(self.file_paths[1]),
])
开发者ID:lcharlick,项目名称:beets,代码行数:19,代码来源:test_plugins.py
示例16: test_import_task_created_with_plugin
def test_import_task_created_with_plugin(self):
class ToSingletonPlugin(plugins.BeetsPlugin):
def __init__(self):
super(ToSingletonPlugin, self).__init__()
self.register_listener('import_task_created',
self.import_task_created_event)
def import_task_created_event(self, session, task):
if isinstance(task, SingletonImportTask) \
or isinstance(task, SentinelImportTask)\
or isinstance(task, ArchiveImportTask):
return task
new_tasks = []
for item in task.items:
new_tasks.append(SingletonImportTask(task.toppath, item))
return new_tasks
to_singleton_plugin = ToSingletonPlugin
self.register_plugin(to_singleton_plugin)
import_files = [self.import_dir]
self._setup_import_session(singletons=False)
self.importer.paths = import_files
with helper.capture_log() as logs:
self.importer.run()
self.unload_plugins()
# Exactly one event should have been imported (for the album).
# Sentinels do not get emitted.
self.assertEqual(logs.count(u'Sending event: import_task_created'), 1)
logs = [line for line in logs if not line.startswith(
u'Sending event:')]
self.assertEqual(logs, [
u'Singleton: {0}'.format(displayable_path(self.file_paths[0])),
u'Singleton: {0}'.format(displayable_path(self.file_paths[1])),
])
开发者ID:Gondlar,项目名称:beets,代码行数:41,代码来源:test_plugins.py
示例17: test_update_library
def test_update_library(self, track_for_id, album_for_id):
album_for_id.return_value = \
generate_album_info(
'album id',
[('track id', {'release_track_id': u'release track id'})]
)
track_for_id.return_value = \
generate_track_info(u'singleton track id',
{'title': u'singleton info'})
album_item = Item(
album=u'old title',
mb_albumid=u'81ae60d4-5b75-38df-903a-db2cfa51c2c6',
mb_trackid=u'old track id',
mb_releasetrackid=u'release track id',
path=''
)
album = self.lib.add_album([album_item])
item = Item(
title=u'old title',
mb_trackid=u'b8c2cf90-83f9-3b5f-8ccd-31fb866fcf37',
path='',
)
self.lib.add(item)
with capture_log() as logs:
self.run_command('mbsync')
self.assertIn('Sending event: albuminfo_received', logs)
self.assertIn('Sending event: trackinfo_received', logs)
item.load()
self.assertEqual(item.title, u'singleton info')
album_item.load()
self.assertEqual(album_item.title, u'track info')
self.assertEqual(album_item.mb_trackid, u'track id')
album.load()
self.assertEqual(album.album, u'album info')
开发者ID:arogl,项目名称:beets,代码行数:41,代码来源:test_mbsync.py
示例18: test_empty_query
def test_empty_query(self):
with capture_log('beets.convert') as logs:
self.run_convert('An impossible query')
self.assertEqual(logs[0], u'convert: Empty query result.')
开发者ID:Kraymer,项目名称:beets,代码行数:4,代码来源:test_convert.py
注:本文中的test.helper.capture_log函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论