Skip to content

Commit

Permalink
fixed try except blocks and added a test for the key error
Browse files Browse the repository at this point in the history
  • Loading branch information
Flan committed Apr 28, 2016
1 parent 15f8d8b commit 3b73a56
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
36 changes: 18 additions & 18 deletions pyne/origen22.py
Original file line number Diff line number Diff line change
Expand Up @@ -1512,27 +1512,27 @@ def xslibs(nucs=NUCS, xscache=None, nlb=(201, 202, 203), verbose=False):
if verbose:
print('computing {0}'.format(nucname.name(nuc)))
key = nucname.zzaaam(nuc)
try:
if nuc in ACTIVATION_PRODUCT_NUCS:
if nuc in ACTIVATION_PRODUCT_NUCS:
try:
_compute_xslib(nuc, key, t9[nlb[0]], xscache)
except KeyError:
if verbose:
print('Key Error with ', key, ' in a computing activation product cross sections')
continue
try:
if nuc in ACTINIDE_AND_DAUGHTER_NUCS:
except KeyError:
if verbose:
print('Key Error with ', key, ' in a computing activation product cross sections')
continue
if nuc in ACTINIDE_AND_DAUGHTER_NUCS:
try:
_compute_xslib(nuc, key, t9[nlb[1]], xscache)
except KeyError:
if verbose:
print('Key Error with ', key, ' in a computing actinide and daughter cross sections')
continue
try:
if nuc in FISSION_PRODUCT_NUCS:
except KeyError:
if verbose:
print('Key Error with ', key, ' in a computing actinide and daughter cross sections')
continue
if nuc in FISSION_PRODUCT_NUCS:
try:
_compute_xslib(nuc, key, t9[nlb[2]], xscache)
except KeyError:
if verbose:
print('Key Error with ', key, ' in a computing fission product cross sections')
continue
except KeyError:
if verbose:
print('Key Error with ', key, ' in a computing fission product cross sections')
continue
xscache['E_g'] = old_group_struct
xscache['phi_g'] = old_flux
return t9
Expand Down
4 changes: 4 additions & 0 deletions tests/xs/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ def test_xs_cache_set_E_g():
xs_cache['E_g'] = [10.0, 8.0, 2.0, 1.0]
assert_true(xs_cache['phi_g'] is None)
assert_false((10010, 'fiss') in xs_cache)

# Assert that KeyError is raised if (nuclide, reaction, temp) key does not exist.
xs_cache.clear()
assert_raises(KeyError, xs_cache[10010, 1089, 300])


def test_xs_cache_get_phi_g():
Expand Down

0 comments on commit 3b73a56

Please sign in to comment.