Index: Lib/test/test_support.py =================================================================== --- Lib/test/test_support.py (revision 77755) +++ Lib/test/test_support.py (working copy) @@ -438,15 +438,22 @@ testcase.assertRaises(SyntaxError, compile, statement, '', 'exec') -def open_urlresource(url): +def open_urlresource(url, check=lambda f: True): import urlparse, urllib2 - requires('urlfetch') filename = urlparse.urlparse(url)[2].split('/')[-1] # '/': it's URL! fn = os.path.join(os.path.dirname(__file__), "data", filename) if os.path.exists(fn): - return open(fn) + f = open(fn) + if check(f): + f.seek(0) + return f + f.close() + unlink(fn) + + # Verify the requirement if we *really* need to download the file + requires('urlfetch') print >> get_original_stdout(), '\tfetching %s ...' % url f = urllib2.urlopen(url, timeout=15) @@ -458,7 +465,12 @@ s = f.read() finally: f.close() - return open(fn) + f = open(fn) + if not check(f): + f.close() + raise TestFailed('invalid resource "%s"' % fn) + f.seek(0) + return f class WarningsRecorder(object):