本文整理汇总了Python中openmdao.main.expreval.ExprEvaluator.scope方法的典型用法代码示例。如果您正苦于以下问题:Python ExprEvaluator.scope方法的具体用法?Python ExprEvaluator.scope怎么用?Python ExprEvaluator.scope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openmdao.main.expreval.ExprEvaluator
的用法示例。
在下文中一共展示了ExprEvaluator.scope方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_reparse_on_scope_change
# 需要导入模块: from openmdao.main.expreval import ExprEvaluator [as 别名]
# 或者: from openmdao.main.expreval.ExprEvaluator import scope [as 别名]
def test_reparse_on_scope_change(self):
self.top.comp.x = 99.5
self.top.comp.y = -3.14
ex = ExprEvaluator('comp.x', self.top)
self.assertEqual(99.5, ex.evaluate())
self.assertEqual(new_text(ex), "scope.get('comp.x')")
ex.scope = self.top.a
try:
ex.set(0.5)
except AttributeError as err:
self.assertEqual(str(err), "a: object has no attribute 'comp.x'")
else:
self.fail("AttributeError expected")
self.assertEqual(new_text(ex), "scope.get('comp.x')")
self.assertEqual(99.5, ex.evaluate(self.top)) # set scope back to self.top
self.assertEqual(new_text(ex), "scope.get('comp.x')")
ex.text = 'comp.y'
try:
ex.evaluate(self.top.a)
except AttributeError as err:
self.assertEqual(str(err), "can't evaluate expression 'comp.y':"
" a: 'A' object has no attribute 'comp'")
else:
self.fail("AttributeError expected")
ex.scope = self.top
ex.set(11.1)
self.assertEqual(11.1, self.top.comp.y)
self.assertEqual(new_text(ex), "scope.get('comp.y')")
示例2: test_get_referenced_varpaths
# 需要导入模块: from openmdao.main.expreval import ExprEvaluator [as 别名]
# 或者: from openmdao.main.expreval.ExprEvaluator import scope [as 别名]
def test_get_referenced_varpaths(self):
ex = ExprEvaluator('comp.x[0] = 10*(3.2+ a.a1d[3]* 1.1*a.a1d[2 ])', self.top.a)
self.assertEqual(ex.get_referenced_varpaths(), set(['comp.x','a.a1d']))
ex.text = 'comp.contlist[1].a2d[2][1]'
self.assertEqual(ex.get_referenced_varpaths(), set(['comp.contlist']))
ex.scope = self.top.comp
ex.text = 'comp.contlist[1]'
self.assertEqual(ex.get_referenced_varpaths(), set(['comp.contlist']))
示例3: test_resolve
# 需要导入模块: from openmdao.main.expreval import ExprEvaluator [as 别名]
# 或者: from openmdao.main.expreval.ExprEvaluator import scope [as 别名]
def test_resolve(self):
ex = ExprEvaluator('comp.x[0] = 10*(3.2+ a.a1d[3]* 1.1*a.a1d[2 ])', self.top)
self.assertEqual(ex.check_resolve(), True)
ex.text = 'comp.contlist[1].a2d[2][1]'
self.assertEqual(ex.check_resolve(), True)
ex.scope = self.top.comp
ex.text = 'contlist[1]'
self.assertEqual(ex.check_resolve(), True)
ex.text = 'contlist[1]-foo.flambe'
self.assertEqual(ex.check_resolve(), False)
示例4: test_get_referenced_compnames
# 需要导入模块: from openmdao.main.expreval import ExprEvaluator [as 别名]
# 或者: from openmdao.main.expreval.ExprEvaluator import scope [as 别名]
def test_get_referenced_compnames(self):
ex = ExprEvaluator('comp.x[0] = 10*(3.2+ a.a1d[3]* 1.1*a.a1d[2 ].foobar)', self.top.a)
self.assertEqual(ex.get_referenced_compnames(), set(['comp', 'a']))
ex.text = 'comp.contlist[1].a2d[2][1]'
self.assertEqual(ex.get_referenced_compnames(), set(['comp']))
ex.scope = self.top.comp
ex.text = 'comp.contlist[1]'
self.assertEqual(ex.get_referenced_compnames(), set(['comp']))
ex.text = 'comp.contlist[1].foo'
self.assertEqual(ex.get_referenced_compnames(), set(['comp']))
ex.text = 'contlist[1].foo'
self.assertEqual(ex.get_referenced_compnames(), set())
ex.text = 'asm2.comp3.contlist[1].foo'
self.assertEqual(ex.get_referenced_compnames(), set(['asm2']))