2016-04-16 10:01:43 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2016-10-28 22:21:41 +00:00
|
|
|
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs
|
2016-04-16 10:01:43 +00:00
|
|
|
# Copyright (C) 2012-2014 Bastian Kleineidam
|
2019-12-03 22:35:41 +00:00
|
|
|
# Copyright (C) 2015-2019 Tobias Gruetzmacher
|
2016-04-26 06:03:34 +00:00
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
2016-04-16 10:01:43 +00:00
|
|
|
|
|
|
|
import re
|
|
|
|
import operator
|
|
|
|
import os
|
|
|
|
|
2019-12-03 22:35:41 +00:00
|
|
|
import pytest
|
|
|
|
from xdist.dsession import LoadScopeScheduling
|
|
|
|
|
2016-04-16 10:01:43 +00:00
|
|
|
from dosagelib import scraper
|
|
|
|
|
|
|
|
|
|
|
|
def get_test_scrapers():
|
|
|
|
"""Return scrapers that should be tested."""
|
|
|
|
if "TESTALL" in os.environ:
|
|
|
|
# test all comics (this will take some time)
|
|
|
|
scrapers = scraper.get_scrapers()
|
|
|
|
else:
|
|
|
|
if 'TESTCOMICS' in os.environ:
|
|
|
|
scraper_pattern = re.compile(os.environ['TESTCOMICS'])
|
|
|
|
else:
|
|
|
|
# Get limited number of scraper tests on Travis builds to make it
|
|
|
|
# faster
|
|
|
|
testscrapernames = [
|
2018-06-29 17:26:17 +00:00
|
|
|
# "classic" _BasicScraper
|
|
|
|
'AbstruseGoose',
|
|
|
|
# complex _ParserScraper
|
|
|
|
'GoComics/CalvinAndHobbes',
|
|
|
|
# _WordPressScraper
|
|
|
|
'GrrlPower'
|
2016-04-16 10:01:43 +00:00
|
|
|
]
|
2016-04-26 06:03:34 +00:00
|
|
|
scraper_pattern = re.compile('^(' + '|'.join(testscrapernames) +
|
|
|
|
')$')
|
2016-04-16 10:01:43 +00:00
|
|
|
|
|
|
|
scrapers = [
|
|
|
|
scraperobj for scraperobj in scraper.get_scrapers()
|
|
|
|
if scraper_pattern.match(scraperobj.name)
|
|
|
|
]
|
|
|
|
return scrapers
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_generate_tests(metafunc):
|
|
|
|
if 'scraperobj' in metafunc.fixturenames:
|
2020-01-10 13:55:34 +00:00
|
|
|
scrapers = get_test_scrapers()
|
|
|
|
scraperids = list(x.name for x in scrapers)
|
|
|
|
metafunc.parametrize('scraperobj', scrapers, ids=scraperids)
|
2019-12-03 22:35:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LoadModScheduling(LoadScopeScheduling):
|
|
|
|
"""Implement load scheduling for comic modules. See xdist for details."""
|
|
|
|
|
|
|
|
def _split_scope(self, nodeid):
|
|
|
|
mod, test = nodeid.split("::", 1)
|
|
|
|
return mod + "::" + test.split("/", 1)[0]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.trylast
|
|
|
|
def pytest_xdist_make_scheduler(config, log):
|
|
|
|
return LoadModScheduling(config, log)
|