Ejemplo n.º 1
0
def run_tests(spider, output_file, settings):
    """
    Helper for running test contractors for a spider and output an
    XUnit file (for CI)

    For using offline input the HTTP cache is enabled
    """

    settings.overrides.update({
        "HTTPCACHE_ENABLED": True,
        "HTTPCACHE_EXPIRATION_SECS": 0,
    })

    crawler = CrawlerProcess(settings)

    contracts = build_component_list(
        crawler.settings['SPIDER_CONTRACTS_BASE'],
        crawler.settings['SPIDER_CONTRACTS'],
    )

    xunit = Xunit()
    xunit.enabled = True
    xunit.configure(AttributeDict(xunit_file=output_file), Config())
    xunit.stopTest = lambda *x: None

    check = CheckCommand()
    check.set_crawler(crawler)
    check.settings = settings
    check.conman = ContractsManager([load_object(c) for c in contracts])
    check.results = xunit
    # this are specially crafted requests that run tests as callbacks
    requests = check.get_requests(spider)

    crawler.install()
    crawler.configure()
    crawler.crawl(spider, requests)
    log.start(loglevel='DEBUG')

    # report is called when the crawler finishes, it creates the XUnit file
    report = lambda: check.results.report(check.results.error_report_file)
    dispatcher.connect(report, signals.engine_stopped)

    crawler.start()
Ejemplo n.º 2
0
        metavar='int',
        help="tolerance for relative precision in comparison (trumps strict)")

    all_strict = ['high', 'medium', 'low']
    parser.add_option("",
                      "--strict",
                      dest="strict",
                      default='low',
                      metavar='str',
                      help="strictness for testing precision: [%s]" %
                      " ,".join(all_strict))

    xunit_plugin = Xunit()
    # Make sure this plugin get called by setting its score to be the highest.
    xunit_plugin.score = 1000000
    xunit_plugin.enabled = True

    # Set up a dummy env for xunit to parse. Note we are using nose's xunit,
    # not the one bundled in yt
    env = {"NOSE_XUNIT_FILE": "nosetests.xml"}
    xunit_plugin.options(parser, env)

    answer_plugin = AnswerTesting()
    answer_plugin.enabled = True
    answer_plugin.options(parser)
    reporting_plugin = ResultsSummary()
    reporting_plugin.enabled = True
    pdb_plugin = debug.Pdb()

    all_suites = ['quick', 'push', 'full']
    suite_vars = [suite + "suite" for suite in all_suites]