Fix test running.
This commit is contained in:
parent
7c471afe7b
commit
5fa8792007
2 changed files with 22 additions and 14 deletions
2
Makefile
2
Makefile
|
@ -6,7 +6,7 @@ ARCHIVE:=dosage-$(VERSION).tar.gz
|
||||||
PY_FILES_DIRS := dosage dosagelib tests *.py
|
PY_FILES_DIRS := dosage dosagelib tests *.py
|
||||||
PY2APPOPTS ?=
|
PY2APPOPTS ?=
|
||||||
NUMPROCESSORS:=$(shell grep -c processor /proc/cpuinfo)
|
NUMPROCESSORS:=$(shell grep -c processor /proc/cpuinfo)
|
||||||
MAXFAILEDTESTS:=200
|
MAXFAILEDTESTS:=2
|
||||||
# Pytest options:
|
# Pytest options:
|
||||||
# - stop after MAXFAILEDTESTS failed errors
|
# - stop after MAXFAILEDTESTS failed errors
|
||||||
# - use multiple processors
|
# - use multiple processors
|
||||||
|
|
|
@ -12,40 +12,48 @@ class _ComicTester(TestCase):
|
||||||
"""Basic comic test class."""
|
"""Basic comic test class."""
|
||||||
scraperclass=None
|
scraperclass=None
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.name = self.scraperclass.get_name()
|
||||||
|
|
||||||
def test_comic(self):
|
def test_comic(self):
|
||||||
# Test a scraper. It must be able to traverse backward for
|
# Test a scraper. It must be able to traverse backward for
|
||||||
# at least 5 pages from the start, and find strip images
|
# at least 5 pages from the start, and find strip images
|
||||||
# on at least 4 pages.
|
# on at least 4 pages.
|
||||||
module = self.scraperclass()
|
scraperobj = self.scraperclass()
|
||||||
num = empty = 0
|
num = empty = 0
|
||||||
for n, comics in izip(xrange(5), module):
|
for n, strip in izip(xrange(5), scraperobj.getAllStrips()):
|
||||||
if len(comics) == 0:
|
images = strips.getImages()
|
||||||
|
if len(images) == 0:
|
||||||
empty += 1
|
empty += 1
|
||||||
for comic in comics:
|
for image in images:
|
||||||
self.save(comic)
|
self.save(image)
|
||||||
num += 1
|
num += 1
|
||||||
self.assertTrue(num >= 4, 'Traversal failed after %d strips.' % num)
|
self.check(num >= 4, 'traversal failed after %d strips.' % num)
|
||||||
self.assertTrue(empty <= 1, 'Failed to find images on %d pages.' % empty)
|
self.check(empty <= 1, 'failed to find images on %d pages.' % empty)
|
||||||
|
|
||||||
def save(self, comic):
|
def save(self, image):
|
||||||
# create a temporary directory
|
# create a temporary directory
|
||||||
tmpdir = tempfile.mkdtemp()
|
tmpdir = tempfile.mkdtemp()
|
||||||
try:
|
try:
|
||||||
filename, saved = comic.save(tmpdir)
|
image.save(tmpdir)
|
||||||
self.assertTrue(saved, 'Could not save comic %s to %s' % (comic, tmpdir))
|
except Exception, msg:
|
||||||
|
self.check(False, 'could not save to %s: %s' % (tmpdir, msg))
|
||||||
finally:
|
finally:
|
||||||
shutil.rmtree(tmpdir)
|
shutil.rmtree(tmpdir)
|
||||||
|
|
||||||
|
def check(self, condition, msg):
|
||||||
|
self.assertTrue(condition, "%s: %s" % (self.name, msg))
|
||||||
|
|
||||||
|
|
||||||
def generate_comic_testers():
|
def generate_comic_testers():
|
||||||
"""For each comic scraper, create a test class.
|
"""For each comic scraper, create a test class.
|
||||||
This currently generates over 4000 test classes (one for each comic),
|
This currently generates over 4000 test classes (one for each comic),
|
||||||
so this takes a while."""
|
so this takes a while."""
|
||||||
for s in scraper.items():
|
for scraperclass in scraper.get_scrapers():
|
||||||
name = 'Test'+s.__name__
|
name = 'Test'+scraperclass.__name__
|
||||||
globals()[name] = type(name,
|
globals()[name] = type(name,
|
||||||
(_ComicTester,),
|
(_ComicTester,),
|
||||||
dict(scraperclass=s)
|
dict(scraperclass=scraperclass)
|
||||||
)
|
)
|
||||||
|
|
||||||
generate_comic_testers()
|
generate_comic_testers()
|
||||||
|
|
Loading…
Reference in a new issue