本文整理汇总了Python中mi.core.instrument.protocol_param_dict.ProtocolParameterDict.get_current_timestamp方法的典型用法代码示例。如果您正苦于以下问题:Python ProtocolParameterDict.get_current_timestamp方法的具体用法?Python ProtocolParameterDict.get_current_timestamp怎么用?Python ProtocolParameterDict.get_current_timestamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mi.core.instrument.protocol_param_dict.ProtocolParameterDict
的用法示例。
在下文中一共展示了ProtocolParameterDict.get_current_timestamp方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get
# 需要导入模块: from mi.core.instrument.protocol_param_dict import ProtocolParameterDict [as 别名]
# 或者: from mi.core.instrument.protocol_param_dict.ProtocolParameterDict import get_current_timestamp [as 别名]
def test_get(self):
"""
test getting values with expiration
"""
# from mi.core.exceptions import InstrumentParameterExpirationException
pd = ProtocolParameterDict()
# No expiration, should work just fine
pd.add('noexp', r'', None, None, expiration=None)
pd.add('zeroexp', r'', None, None, expiration=0)
pd.add('lateexp', r'', None, None, expiration=2)
###
# Set and get with no expire
###
pd.set_value('noexp', 1)
self.assertEqual(pd.get('noexp'), 1)
###
# Set and get with a 0 expire
###
basetime = pd.get_current_timestamp()
pd.set_value('zeroexp', 2)
# We should fail because we are calculating exp against current time
with self.assertRaises(InstrumentParameterExpirationException):
pd.get('zeroexp')
# Should succeed because exp is calculated using basetime
self.assertEqual(pd.get('zeroexp', basetime), 2)
###
# Set and get with a delayed expire
###
basetime = pd.get_current_timestamp()
futuretime = pd.get_current_timestamp(3)
self.assertGreater(futuretime - basetime, 3)
pd.set_value('lateexp', 2)
# Success because data is not expired
self.assertEqual(pd.get('lateexp', basetime), 2)
# Fail because data is expired (simulated three seconds from now)
with self.assertRaises(InstrumentParameterExpirationException):
pd.get('lateexp', futuretime)