本文整理汇总了Python中pants.base.payload.Payload.get_field_value方法的典型用法代码示例。如果您正苦于以下问题:Python Payload.get_field_value方法的具体用法?Python Payload.get_field_value怎么用?Python Payload.get_field_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pants.base.payload.Payload
的用法示例。
在下文中一共展示了Payload.get_field_value方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_missing_payload_field
# 需要导入模块: from pants.base.payload import Payload [as 别名]
# 或者: from pants.base.payload.Payload import get_field_value [as 别名]
def test_missing_payload_field(self):
payload = Payload()
payload.add_field('foo', PrimitiveField('test-value'))
payload.add_field('bar', PrimitiveField(None))
self.assertEquals('test-value', payload.foo);
self.assertEquals('test-value', payload.get_field('foo').value)
self.assertEquals('test-value', payload.get_field_value('foo'))
self.assertEquals(None, payload.bar);
self.assertEquals(None, payload.get_field('bar').value)
self.assertEquals(None, payload.get_field_value('bar'))
self.assertEquals(None, payload.get_field('bar', default='nothing').value)
self.assertEquals(None, payload.get_field_value('bar', default='nothing'))
with self.assertRaises(KeyError):
self.assertEquals(None, payload.field_doesnt_exist)
self.assertEquals(None, payload.get_field('field_doesnt_exist'))
self.assertEquals(None, payload.get_field_value('field_doesnt_exist'))
self.assertEquals('nothing', payload.get_field('field_doesnt_exist', default='nothing'))
self.assertEquals('nothing', payload.get_field_value('field_doesnt_exist', default='nothing'))
示例2: test_missing_payload_field
# 需要导入模块: from pants.base.payload import Payload [as 别名]
# 或者: from pants.base.payload.Payload import get_field_value [as 别名]
def test_missing_payload_field(self):
payload = Payload()
payload.add_field("foo", PrimitiveField("test-value"))
payload.add_field("bar", PrimitiveField(None))
self.assertEquals("test-value", payload.foo)
self.assertEquals("test-value", payload.get_field("foo").value)
self.assertEquals("test-value", payload.get_field_value("foo"))
self.assertEquals(None, payload.bar)
self.assertEquals(None, payload.get_field("bar").value)
self.assertEquals(None, payload.get_field_value("bar"))
self.assertEquals(None, payload.get_field("bar", default="nothing").value)
self.assertEquals(None, payload.get_field_value("bar", default="nothing"))
with self.assertRaises(KeyError):
self.assertEquals(None, payload.field_doesnt_exist)
self.assertEquals(None, payload.get_field("field_doesnt_exist"))
self.assertEquals(None, payload.get_field_value("field_doesnt_exist"))
self.assertEquals("nothing", payload.get_field("field_doesnt_exist", default="nothing"))
self.assertEquals("nothing", payload.get_field_value("field_doesnt_exist", default="nothing"))