当前位置: 首页>>代码示例>>Python>>正文


Python Payload.get_field方法代码示例

本文整理汇总了Python中pants.base.payload.Payload.get_field方法的典型用法代码示例。如果您正苦于以下问题:Python Payload.get_field方法的具体用法?Python Payload.get_field怎么用?Python Payload.get_field使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pants.base.payload.Payload的用法示例。


在下文中一共展示了Payload.get_field方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_missing_payload_field

# 需要导入模块: from pants.base.payload import Payload [as 别名]
# 或者: from pants.base.payload.Payload import get_field [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'))
开发者ID:pcurry,项目名称:pants,代码行数:20,代码来源:test_payload.py

示例2: test_missing_payload_field

# 需要导入模块: from pants.base.payload import Payload [as 别名]
# 或者: from pants.base.payload.Payload import get_field [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"))
开发者ID:jduan,项目名称:pants,代码行数:20,代码来源:test_payload.py


注:本文中的pants.base.payload.Payload.get_field方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。