Mercurial > cpython-lru_cache-weakref
diff Lib/test/support.py @ 59720:8a28be45c242
Merged revisions 78982,78986 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78982 | florent.xicluna | 2010-03-15 15:00:58 +0100 (lun, 15 mar 2010) | 2 lines
Remove py3k deprecation warnings from these Unicode tools.
........
r78986 | florent.xicluna | 2010-03-15 19:08:58 +0100 (lun, 15 mar 2010) | 3 lines
Issue #7783 and #7787: open_urlresource invalidates the outdated files from the local cache.
Use this feature to fix test_normalization.
........
| author | Florent Xicluna <florent.xicluna@gmail.com> |
|---|---|
| date | Fri, 19 Mar 2010 14:25:03 +0000 |
| parents | 485fe20dab12 |
| children | b4f60df31b14 |
line wrap: on
line diff
--- a/Lib/test/support.py Fri Mar 19 13:37:08 2010 +0000 +++ b/Lib/test/support.py Fri Mar 19 14:25:03 2010 +0000 @@ -33,6 +33,7 @@ "reap_children", "cpython_only", "check_impl_detail", "get_attribute", "swap_item", "swap_attr"] + class Error(Exception): """Base class for regression test exceptions.""" @@ -444,12 +445,29 @@ def open_urlresource(url, *args, **kw): import urllib.request, urllib.parse - requires('urlfetch') + check = kw.pop('check', None) + filename = urllib.parse.urlparse(url)[2].split('/')[-1] # '/': it's URL! fn = os.path.join(os.path.dirname(__file__), "data", filename) + + def check_valid_file(fn): + f = open(fn, *args, **kw) + if check is None: + return f + elif check(f): + f.seek(0) + return f + f.close() + if os.path.exists(fn): - return open(fn, *args, **kw) + f = check_valid_file(fn) + if f is not None: + return f + unlink(fn) + + # Verify the requirement before downloading the file + requires('urlfetch') print('\tfetching %s ...' % url, file=get_original_stdout()) f = urllib.request.urlopen(url, timeout=15) @@ -461,7 +479,12 @@ s = f.read() finally: f.close() - return open(fn, *args, **kw) + + f = check_valid_file(fn) + if f is not None: + return f + raise TestFailed('invalid resource "%s"' % fn) + class WarningsRecorder(object): """Convenience wrapper for the warnings list returned on
