diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2010-03-15 18:08:58 (GMT) |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2010-03-15 18:08:58 (GMT) |
commit | 3cc8f211ed0d569836114d0d54c6298a21e6dde3 (patch) | |
tree | f3ceb6af8296b5cdb6d4e8860df240db5e208ac0 /Lib/test/test_support.py | |
parent | fae23dc9dc1b4e1b3138b1c933306869440408f2 (diff) | |
download | cpython-3cc8f211ed0d569836114d0d54c6298a21e6dde3.zip cpython-3cc8f211ed0d569836114d0d54c6298a21e6dde3.tar.gz cpython-3cc8f211ed0d569836114d0d54c6298a21e6dde3.tar.bz2 |
Issue #7783 and #7787: open_urlresource invalidates the outdated files from the local cache.
Use this feature to fix test_normalization.
Diffstat (limited to 'Lib/test/test_support.py')
-rw-r--r-- | Lib/test/test_support.py | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index a8f9fbf7..9bb4329 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -32,6 +32,7 @@ __all__ = ["Error", "TestFailed", "ResourceDenied", "import_module", "threading_cleanup", "reap_children", "cpython_only", "check_impl_detail", "get_attribute", "py3k_bytes"] + class Error(Exception): """Base class for regression test exceptions.""" @@ -463,15 +464,30 @@ def check_syntax_error(testcase, statement): testcase.assertRaises(SyntaxError, compile, statement, '<test string>', 'exec') -def open_urlresource(url): +def open_urlresource(url, check=None): 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) + + def check_valid_file(fn): + f = open(fn) + if check is None: + return f + elif check(f): + f.seek(0) + return f + f.close() + if os.path.exists(fn): - return open(fn) + f = check_valid_file(fn) + if f is not None: + return f + unlink(fn) + + # Verify the requirement before downloading the file + requires('urlfetch') print >> get_original_stdout(), '\tfetching %s ...' % url f = urllib2.urlopen(url, timeout=15) @@ -483,7 +499,11 @@ def open_urlresource(url): s = f.read() finally: f.close() - return open(fn) + + f = check_valid_file(fn) + if f is not None: + return f + raise TestFailed('invalid resource "%s"' % fn) class WarningsRecorder(object): |