From 5392d6346d14b49c7351c1a5b6caa39990d0d0b1 Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Tue, 22 Dec 2015 11:41:46 -0800 Subject: [PATCH] endl fixes --- tests/test_endl.py | 20 +++----------------- tests/utils.py | 5 ++++- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/tests/test_endl.py b/tests/test_endl.py index 3bdd93c9f4..fde7db1f38 100644 --- a/tests/test_endl.py +++ b/tests/test_endl.py @@ -19,26 +19,12 @@ else: from StringIO import StringIO -if sys.version_info[0] > 2: - import urllib.request as urllib -else: - import urllib +from utils import download_file def test_loadfile(): - if not os.path.isfile('epdl97_eedl_Pb'): - urllib.urlretrieve( - 'https://www-nds.iaea.org/epdl97/data/endl/eedl/za082000', - 'epdl97_eedl_Pb' - ) - with open('epdl97_eedl_Pb', 'rb') as f: - obs_hash = md5(f.read()).hexdigest() - exp_hash = '502105669e0c0ad917301d219c649aaf' - assert_equal( - obs_hash, exp_hash, - msg='epdl97_eedl_Pb hash check failed; please try redownloading' - ' the epdl97_eedl_Pb data file.' - ) + download_file('https://www-nds.iaea.org/epdl97/data/endl/eedl/za082000', + 'epdl97_eedl_Pb', '502105669e0c0ad917301d219c649aaf') testlib = Library('epdl97_eedl_Pb') # test the nuclides diff --git a/tests/utils.py b/tests/utils.py index 80b48ff596..dc34689aa4 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -14,8 +14,11 @@ def download_file(url, localfile, md5_hash): html = f.read() else: req = urllib.Request(url, headers={'User-Agent': 'Mozilla/5.0'}) - with urllib.urlopen(req, timeout=30.0) as f: + f = urllib.urlopen(req, timeout=30.0) + try: html = f.read() + finally: + f.close() with open(localfile, 'wb') as f: f.write(html) obs_hash = md5(html).hexdigest()