2014-07-24 07:16:50 -04:00
|
|
|
from misc.colour_terminal import print_red
|
|
|
|
from conf import hook
|
|
|
|
from exc.test_failed import TestFailed
|
|
|
|
|
2014-08-08 01:54:08 -04:00
|
|
|
""" Post-Test Hook: FilesCrawled
|
|
|
|
This is a post test hook that is invoked in tests that check wget's behaviour
|
|
|
|
in recursive mode. It expects an ordered list of the request lines that Wget
|
|
|
|
must send to the server. If the requests received by the server do not match
|
|
|
|
the provided list, IN THE GIVEN ORDER, then it raises a TestFailed exception.
|
|
|
|
Such a test can be used to check the implementation of the recursion algorithm
|
|
|
|
in Wget too.
|
|
|
|
"""
|
|
|
|
|
2014-07-24 07:16:50 -04:00
|
|
|
|
|
|
|
@hook()
|
|
|
|
class FilesCrawled:
|
|
|
|
def __init__(self, request_headers):
|
|
|
|
self.request_headers = request_headers
|
|
|
|
|
|
|
|
def __call__(self, test_obj):
|
|
|
|
for headers, remaining in zip(map(set, self.request_headers),
|
|
|
|
test_obj.request_remaining()):
|
|
|
|
diff = headers.symmetric_difference(remaining)
|
|
|
|
|
|
|
|
if diff:
|
2015-04-14 01:06:20 -04:00
|
|
|
print_red(str(diff))
|
2014-07-24 07:16:50 -04:00
|
|
|
raise TestFailed('Not all files were crawled correctly.')
|