本文整理汇总了Python中helpers.FakeArgs.kind方法的典型用法代码示例。如果您正苦于以下问题:Python FakeArgs.kind方法的具体用法?Python FakeArgs.kind怎么用?Python FakeArgs.kind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helpers.FakeArgs
的用法示例。
在下文中一共展示了FakeArgs.kind方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_slice_name_validation
# 需要导入模块: from helpers import FakeArgs [as 别名]
# 或者: from helpers.FakeArgs import kind [as 别名]
def test_slice_name_validation(self):
xproto = \
"""
policy test_policy < not obj.id -> {{ obj.name.startswith(obj.site.login_base) }} >
"""
args = FakeArgs()
args.inputs = xproto
args.target = self.target
output = XOSGenerator.generate(args)
obj = FakeArgs()
obj.isolation = 'container'
obj.kind = 'not a container'
exec(output) # This loads the generated function, which should look like this:
"""
def policy_output_validator(obj, ctx):
i3 = obj.id
i4 = obj.name.startswith(obj.site.login_base)
i2 = ((not i3) or i4)
i1 = (not i2)
if (not i1):
raise ValidationError('Necessary Failure')
"""
with self.assertRaises(Exception):
policy_output_validator(obj, {})
示例2: test_instance_container
# 需要导入模块: from helpers import FakeArgs [as 别名]
# 或者: from helpers.FakeArgs import kind [as 别名]
def test_instance_container(self):
xproto = \
"""
policy test_policy < (obj.isolation = "container" | obj.isolation = "container_vm" ) -> (obj.image.kind = "container") >
"""
args = FakeArgs()
args.inputs = xproto
args.target = self.target
output = XOSGenerator.generate(args)
obj = FakeArgs()
obj.isolation = 'container'
obj.kind = 'not a container'
exec(output) # This loads the generated function, which should look like this:
"""
def policy_output_validator(obj, ctx):
i4 = (obj.isolation == 'container')
i5 = (self.isolation == 'container_vm')
i2 = (i4 or i5)
i3 = (obj.image.kind == 'container')
i1 = (i2 or i3)
return i1
"""
with self.assertRaises(Exception):
policy_output_validator(obj, {})