Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion mpas_analysis/configuration/MpasAnalysisConfigParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ def getExpression(self, section, option, elementType=None, usenumpyfunc=False):
"""
expressionString = self.get(section, option)
if usenumpyfunc:
sanitizedstr = expressionString.replace('np.', '').replace('numpy.','')
assert '__' not in expressionString, \
"'__' is not allowed in {} "\
"for `usenumpyfunc=True`".format(expressionString)
sanitizedstr = expressionString.replace('np.', '')\
.replace('numpy.','')\
.replace('__','')
result = eval(sanitizedstr, npallow)
else:
result = ast.literal_eval(expressionString)
Expand Down
2 changes: 2 additions & 0 deletions mpas_analysis/test/test_mpas_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,7 @@ def test_read_config_numpy(self):
np.linspace(0, 1, 10))
for testNumpy in ['testNumpypi' + str(ii) for ii in np.arange(3)] + ['testNumpyPi']:
self.assertEqual(self.config.getExpression('TestNumpy', testNumpy, usenumpyfunc=True), np.pi)
with self.assertRaisesRegexp(AssertionError, "'__' is not allowed in .* for `usenumpyfunc=True`"):
self.config.getExpression('TestNumpy', 'testBadStr', usenumpyfunc=True),

# vim: foldmethod=marker ai ts=4 sts=4 et sw=4 ft=python
1 change: 1 addition & 0 deletions mpas_analysis/test/test_mpas_config_parser/config.analysis
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ testNumpypi0 = pi
testNumpypi1 = np.pi
testNumpypi2 = numpy.pi
testNumpyPi = Pi
testBadStr = __bad_string__