Skip to content

Commit

Permalink
endl fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
scopatz committed Dec 22, 2015
1 parent e670a38 commit 5392d63
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
20 changes: 3 additions & 17 deletions tests/test_endl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 5392d63

Please sign in to comment.