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


Python TextTestRunner.printErrors方法代码示例

本文整理汇总了Python中unittest.TextTestRunner.printErrors方法的典型用法代码示例。如果您正苦于以下问题:Python TextTestRunner.printErrors方法的具体用法?Python TextTestRunner.printErrors怎么用?Python TextTestRunner.printErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unittest.TextTestRunner的用法示例。


在下文中一共展示了TextTestRunner.printErrors方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Command

# 需要导入模块: from unittest import TextTestRunner [as 别名]
# 或者: from unittest.TextTestRunner import printErrors [as 别名]
class Command(ScrapyCommand):
    requires_project = True
    default_settings = {"LOG_ENABLED": False}

    def syntax(self):
        return "[options] <spider>"

    def short_desc(self):
        return "Check spider contracts"

    def add_options(self, parser):
        ScrapyCommand.add_options(self, parser)
        parser.add_option(
            "-l", "--list", dest="list", action="store_true", help="only list contracts, without checking them"
        )
        parser.add_option("-v", "--verbose", dest="verbose", default=1, action="count", help="print all contract hooks")

    def run(self, args, opts):
        # load contracts
        contracts = build_component_list(self.settings["SPIDER_CONTRACTS_BASE"], self.settings["SPIDER_CONTRACTS"])
        self.conman = ContractsManager([load_object(c) for c in contracts])
        self.results = TextTestRunner(verbosity=opts.verbose)._makeResult()

        # contract requests
        contract_reqs = defaultdict(list)

        spman_cls = load_object(self.settings["SPIDER_MANAGER_CLASS"])
        spiders = spman_cls.from_settings(self.settings)

        for spider in args or spiders.list():
            spider = spiders.create(spider)
            requests = self.get_requests(spider)

            if opts.list:
                for req in requests:
                    contract_reqs[spider.name].append(req.callback.__name__)
            elif requests:
                crawler = self.crawler_process.create_crawler(spider.name)
                crawler.crawl(spider, requests)

        # start checks
        if opts.list:
            for spider, methods in sorted(contract_reqs.iteritems()):
                print spider
                for method in sorted(methods):
                    print "  * %s" % method
        else:
            self.crawler_process.start()
            self.results.printErrors()

    def get_requests(self, spider):
        requests = []

        for key, value in vars(type(spider)).items():
            if callable(value) and value.__doc__:
                bound_method = value.__get__(spider, type(spider))
                request = self.conman.from_method(bound_method, self.results)

                if request:
                    request.callback = _generate(request.callback)
                    requests.append(request)

        return requests
开发者ID:amferraz,项目名称:scrapy,代码行数:65,代码来源:check.py


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