Move test parametrization into its own file.
This commit is contained in:
parent
7c3a87970b
commit
7708c678a6
2 changed files with 41 additions and 33 deletions
41
tests/conftest.py
Normal file
41
tests/conftest.py
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (C) 2004-2005 Tristan Seligmann and Jonathan Jacobs
|
||||||
|
# Copyright (C) 2012-2014 Bastian Kleineidam
|
||||||
|
# Copyright (C) 2014-2016 Tobias Gruetzmacher
|
||||||
|
|
||||||
|
import re
|
||||||
|
import operator
|
||||||
|
import os
|
||||||
|
|
||||||
|
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 = [
|
||||||
|
'AbstruseGoose',
|
||||||
|
'GoComics/CalvinAndHobbes',
|
||||||
|
'xkcd'
|
||||||
|
]
|
||||||
|
scraper_pattern = re.compile('|'.join(testscrapernames))
|
||||||
|
|
||||||
|
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:
|
||||||
|
metafunc.parametrize('scraperobj', get_test_scrapers(),
|
||||||
|
ids=operator.attrgetter('name'))
|
|
@ -5,13 +5,11 @@
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import operator
|
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
try:
|
try:
|
||||||
from urllib.parse import urlsplit
|
from urllib.parse import urlsplit
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from urlparse import urlsplit
|
from urlparse import urlsplit
|
||||||
from dosagelib import scraper
|
|
||||||
|
|
||||||
|
|
||||||
def get_host(url):
|
def get_host(url):
|
||||||
|
@ -119,34 +117,3 @@ def _check_stripurl(strip, scraperobj):
|
||||||
err = 'strip URL %r does not match stripUrl pattern %s' % (
|
err = 'strip URL %r does not match stripUrl pattern %s' % (
|
||||||
strip.stripUrl, urlmatch)
|
strip.stripUrl, urlmatch)
|
||||||
assert mo is not None, err
|
assert mo is not None, err
|
||||||
|
|
||||||
|
|
||||||
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 = [
|
|
||||||
'AbstruseGoose',
|
|
||||||
'GoComics/CalvinAndHobbes',
|
|
||||||
'xkcd'
|
|
||||||
]
|
|
||||||
scraper_pattern = re.compile('|'.join(testscrapernames))
|
|
||||||
|
|
||||||
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:
|
|
||||||
metafunc.parametrize('scraperobj', get_test_scrapers(),
|
|
||||||
ids=operator.attrgetter('name'))
|
|
||||||
|
|
Loading…
Reference in a new issue