Skip to content

Commit

Permalink
Merge pull request #1 from boegel/download_timeout_float
Browse files Browse the repository at this point in the history
fix value type of --download-timeout in options.py + enhanced unit test
  • Loading branch information
rjeschmi committed Mar 26, 2015
2 parents b031afe + 2510ad5 commit 2e86591
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion easybuild/tools/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def download_file(filename, url, path):

_log.debug("Trying to download %s from %s to %s", filename, url, path)

timeout = float(build_option('download_timeout'))
timeout = build_option('download_timeout')
if timeout is None:
# default to 10sec timeout if none was specified
# default system timeout (used is nothing is specified) may be infinite (?)
Expand Down
2 changes: 1 addition & 1 deletion easybuild/tools/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def override_options(self):
'cleanup-builddir': ("Cleanup build dir after successful installation.", None, 'store_true', True),
'deprecated': ("Run pretending to be (future) version, to test removal of deprecated code.",
None, 'store', None),
'download-timeout': ("Timeout for initiating downloads (in seconds)", None, 'store', None),
'download-timeout': ("Timeout for initiating downloads (in seconds)", float, 'store', None),
'easyblock': ("easyblock to use for processing the spec file or dumping the options",
None, 'store', None, 'e', {'metavar': 'CLASS'}),
'experimental': ("Allow experimental code (with behaviour that can be changed/removed at any given time).",
Expand Down
14 changes: 13 additions & 1 deletion test/framework/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import stat
import tempfile
import urllib2
from test.framework.utilities import EnhancedTestCase
from test.framework.utilities import EnhancedTestCase, init_config
from unittest import TestLoader, main

import easybuild.tools.filetools as ft
Expand Down Expand Up @@ -201,6 +201,18 @@ def test_download_file(self):
res = ft.download_file(fn, source_url, target_location)
self.assertEqual(res, target_location, "'download' of local file works after removing broken proxy")

# make sure specified timeout is parsed correctly (as a float, not a string)
opts = init_config(args=['--download-timeout=5.3'])
init_config(build_options={'download_timeout': opts.download_timeout})
target_location = os.path.join(self.test_prefix, 'jenkins_robots.txt')
url = 'https://jenkins1.ugent.be/robots.txt'
try:
urllib2.urlopen(url)
res = ft.download_file(fn, url, target_location)
self.assertEqual(res, target_location, "download with specified timeout works")
except urllib2.URLError:
print "Skipping timeout test in test_download_file (working offline)"

def test_mkdir(self):
"""Test mkdir function."""
tmpdir = tempfile.mkdtemp()
Expand Down

0 comments on commit 2e86591

Please sign in to comment.