2020-04-18 11:45:44 +00:00
|
|
|
# SPDX-License-Identifier: MIT
|
2023-06-01 22:07:26 +00:00
|
|
|
# SPDX-FileCopyrightText: © 2004 Tristan Seligmann and Jonathan Jacobs
|
|
|
|
# SPDX-FileCopyrightText: © 2012 Bastian Kleineidam
|
|
|
|
# SPDX-FileCopyrightText: © 2015 Tobias Gruetzmacher
|
2016-04-16 10:01:43 +00:00
|
|
|
import re
|
|
|
|
import os
|
2022-06-04 07:26:05 +00:00
|
|
|
from operator import attrgetter
|
2016-04-16 10:01:43 +00:00
|
|
|
|
2019-12-03 22:35:41 +00:00
|
|
|
import pytest
|
|
|
|
from xdist.dsession import LoadScopeScheduling
|
|
|
|
|
2020-10-01 16:49:14 +00:00
|
|
|
from dosagelib.scraper import scrapers
|
2016-04-16 10:01:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_test_scrapers():
|
|
|
|
"""Return scrapers that should be tested."""
|
2021-04-02 08:15:18 +00:00
|
|
|
if 'TESTALL' in os.environ:
|
2016-04-16 10:01:43 +00:00
|
|
|
# test all comics (this will take some time)
|
2022-06-04 08:56:25 +00:00
|
|
|
return scrapers.all()
|
2021-04-02 08:15:18 +00:00
|
|
|
elif 'TESTCOMICS' in os.environ:
|
|
|
|
scraper_pattern = os.environ['TESTCOMICS']
|
2016-04-16 10:01:43 +00:00
|
|
|
else:
|
2020-04-18 11:03:02 +00:00
|
|
|
# Get limited number of scraper tests as default
|
|
|
|
testscrapernames = [
|
2022-06-06 10:08:32 +00:00
|
|
|
# "classic" BasicScraper
|
2020-04-18 11:03:02 +00:00
|
|
|
'AbstruseGoose',
|
2022-06-06 10:08:32 +00:00
|
|
|
# complex ParserScraper
|
2020-04-18 11:03:02 +00:00
|
|
|
'GoComics/CalvinAndHobbes',
|
2022-06-06 10:08:32 +00:00
|
|
|
# WordPressScraper
|
2020-10-11 18:15:27 +00:00
|
|
|
'GrrlPower',
|
2016-04-16 10:01:43 +00:00
|
|
|
]
|
2021-04-02 08:15:18 +00:00
|
|
|
scraper_pattern = '^(' + '|'.join(testscrapernames) + ')$'
|
2020-04-18 11:03:02 +00:00
|
|
|
|
2021-04-02 08:15:18 +00:00
|
|
|
matcher = re.compile(scraper_pattern)
|
2020-04-18 11:03:02 +00:00
|
|
|
return [
|
2022-06-04 08:56:25 +00:00
|
|
|
scraperobj for scraperobj in scrapers.all()
|
2021-04-02 08:15:18 +00:00
|
|
|
if matcher.match(scraperobj.name)
|
2020-04-18 11:03:02 +00:00
|
|
|
]
|
2016-04-16 10:01:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
def pytest_generate_tests(metafunc):
|
|
|
|
if 'scraperobj' in metafunc.fixturenames:
|
2022-06-04 07:26:05 +00:00
|
|
|
scrapers = sorted(get_test_scrapers(), key=attrgetter('name'))
|
|
|
|
metafunc.parametrize('scraperobj', scrapers, ids=attrgetter('name'))
|
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]
|
|
|
|
|
|
|
|
|
2023-06-01 22:07:26 +00:00
|
|
|
@pytest.hookimpl(trylast=True)
|
2019-12-03 22:35:41 +00:00
|
|
|
def pytest_xdist_make_scheduler(config, log):
|
|
|
|
return LoadModScheduling(config, log)
|