本文整理汇总了Python中ecpy.tasks.base_tasks.RootTask.format_and_eval_string方法的典型用法代码示例。如果您正苦于以下问题:Python RootTask.format_and_eval_string方法的具体用法?Python RootTask.format_and_eval_string怎么用?Python RootTask.format_and_eval_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ecpy.tasks.base_tasks.RootTask
的用法示例。
在下文中一共展示了RootTask.format_and_eval_string方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestEvaluation
# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import format_and_eval_string [as 别名]
class TestEvaluation(object):
"""Test evaluating strings and caching in running mode.
"""
def setup(self):
self.root = RootTask()
database = self.root.database
database.set_value('root', 'val1', 1)
database.create_node('root', 'node1')
database.set_value('root/node1', 'val2', 10.0)
database.add_access_exception('root', 'root/node1', 'val2')
def test_eval_pure_string_editing_mode(self):
"""Test evaluating a word.
"""
test = 'test'
formatted = self.root.format_and_eval_string(test)
assert formatted == 'test'
def test_eval_editing_mode1(self):
"""Test eval expression with only standard operators.
"""
test = '{val1}/{val2}'
formatted = self.root.format_and_eval_string(test)
assert formatted == 0.1
assert not self.root._eval_cache
def test_eval_editing_mode2(self):
"""Test eval expression containing a math function.
"""
test = 'cos({val1}/{val2})'
formatted = self.root.format_and_eval_string(test)
assert formatted == cos(0.1)
assert not self.root._eval_cache
def test_eval_editing_mode3(self):
"""Test eval expression containing a cmath function.
"""
self.root.database.set_value('root', 'val1', 10.0)
test = 'cm.sqrt({val1}/{val2})'
formatted = self.root.format_and_eval_string(test)
assert formatted == 1+0j
assert not self.root._eval_cache
def test_eval_editing_mode4(self):
"""Test eval expression containing a numpy function.
"""
self.root.database.set_value('root', 'val1', [1.0, -1.0])
test = 'np.abs({val1})'
formatted = self.root.format_and_eval_string(test)
assert_array_equal(formatted, numpy.array((1.0, 1.0)))
assert not self.root._eval_cache
def test_eval_pure_string_running_mode(self):
"""Test evaluating a word.
"""
self.root.database.prepare_to_run()
test = 'test'
formatted = self.root.format_and_eval_string(test)
assert formatted == 'test'
def test_eval_running_mode1(self):
"""Test eval expression with only standard operators.
"""
self.root.database.prepare_to_run()
test = '{val1}/{val2}'
formatted = self.root.format_and_eval_string(test)
assert formatted == 0.1
assert self.root._eval_cache
assert test in self.root._eval_cache
self.root.database.set_value('root', 'val1', 2)
formatted = self.root.format_and_eval_string(test)
assert formatted == 0.2
def test_eval_running_mode2(self):
"""Test eval expression containing a math function.
"""
self.root.database.prepare_to_run()
test = 'cos({val1}/{val2})'
formatted = self.root.format_and_eval_string(test)
assert formatted == cos(0.1)
assert self.root._eval_cache
assert test in self.root._eval_cache
self.root.database.set_value('root', 'val1', 2)
formatted = self.root.format_and_eval_string(test)
assert formatted == cos(0.2)
def test_eval_running_mode3(self):
"""Test eval expression containing a cmath function.
"""
#.........这里部分代码省略.........