]> granicus.if.org Git - python/commitdiff
Fix a bug in test.test_support.open_urlresource().
authorCollin Winter <collinw@gmail.com>
Wed, 9 May 2007 04:14:36 +0000 (04:14 +0000)
committerCollin Winter <collinw@gmail.com>
Wed, 9 May 2007 04:14:36 +0000 (04:14 +0000)
If the call to requires() doesn't precede the filesystem check, we get the following situation:
1. ./python Lib/test/regrtest.py test_foo # test needs urlfetch, not enabled, so skipped
2. ./python Lib/test/regrtest.py -u urlfetch test_foo # test runs
3. ./python Lib/test/regrtest.py test_foo # test runs (!)

By moving the call to requires() *before* the filesystem check, the fact that fetched files are cached on the local disk becomes an implementation detail, rather than a semantics-changing point of note.

Lib/test/test_support.py

index 1ac9a223136daea605f9ac4c943a3d9451784af4..cdaee922fd4023ba9929426d5d893f93c98c4c9c 100644 (file)
@@ -259,6 +259,7 @@ def check_syntax_error(testcase, statement):
 def open_urlresource(url):
     import urllib, urlparse
 
+    requires('urlfetch')
     filename = urlparse.urlparse(url)[2].split('/')[-1] # '/': it's URL!
 
     for path in [os.path.curdir, os.path.pardir]:
@@ -266,7 +267,6 @@ def open_urlresource(url):
         if os.path.exists(fn):
             return open(fn)
 
-    requires('urlfetch')
     print >> get_original_stdout(), '\tfetching %s ...' % url
     fn, _ = urllib.urlretrieve(url, filename)
     return open(fn)