当前位置: 首页>>代码示例>>Python>>正文


Python helper.capture_log函数代码示例

本文整理汇总了Python中test.helper.capture_log函数的典型用法代码示例。如果您正苦于以下问题:Python capture_log函数的具体用法?Python capture_log怎么用?Python capture_log使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了capture_log函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的test.helper.capture_log函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。