本文整理汇总了Python中mi.core.instrument.instrument_protocol.CommandResponseInstrumentProtocol._get_prompts方法的典型用法代码示例。如果您正苦于以下问题:Python CommandResponseInstrumentProtocol._get_prompts方法的具体用法?Python CommandResponseInstrumentProtocol._get_prompts怎么用?Python CommandResponseInstrumentProtocol._get_prompts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mi.core.instrument.instrument_protocol.CommandResponseInstrumentProtocol
的用法示例。
在下文中一共展示了CommandResponseInstrumentProtocol._get_prompts方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestUnitInstrumentProtocol
# 需要导入模块: from mi.core.instrument.instrument_protocol import CommandResponseInstrumentProtocol [as 别名]
# 或者: from mi.core.instrument.instrument_protocol.CommandResponseInstrumentProtocol import _get_prompts [as 别名]
class TestUnitInstrumentProtocol(MiUnitTestCase):
"""
Test cases for instrument protocol class. Functions in this class provide
instrument protocol unit tests and provide a tutorial on use of
the protocol interface.
"""
def setUp(self):
"""
"""
self.callback_result = None
self._trigger_count = 0
self._events = []
self.protocol = InstrumentProtocol(self.event_callback)
def tearDown(self):
if self.protocol._scheduler:
self.protocol._scheduler._scheduler.shutdown()
def event_callback(self, event, value=None):
log.debug("Test event callback: %s" % event)
self._events.append(event)
self._trigger_count += 1
def _scheduler_callback(self):
"""
Callback to test the scheduler
"""
self._trigger_count += 1
def assert_scheduled_event_triggered(self, event_count=1):
count = 0
for i in range(0, 40):
count = self._trigger_count
log.debug("check for triggered event, count %d" % self._trigger_count)
if(count >= event_count): break
time.sleep(0.3)
self.assertGreater(count, 0)
def test_get_prompts(self):
"""
ensure prompts are returned sorted by length
"""
prompts = ['aa', 'bbb', 'c', 'dddd']
expected = ['dddd', 'bbb', 'aa', 'c']
class Prompts(BaseEnum):
A = 'aa'
B = 'bbb'
C = 'c'
D = 'dddd'
self.protocol = CommandResponseInstrumentProtocol(prompts, '\r\n', self.event_callback)
self.assertEqual(self.protocol._get_prompts(), expected)
self.protocol = CommandResponseInstrumentProtocol(Prompts, '\r\n', self.event_callback)
self.assertEqual(self.protocol._get_prompts(), expected)
def test_extraction(self):
sample_line = "SATPAR0229,10.01,2206748544,234\r\n"
ntptime = ntplib.system_to_ntp_time(time.time())
result = self.protocol._extract_sample(SatlanticPARDataParticle,
SAMPLE_REGEX,
sample_line,
ntptime,
publish=False)
log.debug("R: %s" % result)
self.assertEqual(result['stream_name'], SatlanticPARDataParticle(None, None).data_particle_type())
# Test the format of the result in the individual driver tests. Here,
# just tests that the result is there.
def test_get_param_list(self):
"""
verify get_param_list returns correct parameter lists.
"""
params = ['foo', 'bar', 'baz']
for key in params:
self.protocol._param_dict.add(key, r'', None, None)
# All can be passed in as a string
self.assertEqual(sorted(params), sorted(self.protocol._get_param_list(DriverParameter.ALL)))
# All can be passed in as a single element list
self.assertEqual(sorted(params), sorted(self.protocol._get_param_list([DriverParameter.ALL])))
# All can be in a list anywhere, not just the first element
self.assertEqual(sorted(params), sorted(self.protocol._get_param_list(['foo', DriverParameter.ALL])))
# Bad parameters raise exceptions event when ALL is specified
with self.assertRaises(InstrumentParameterException):
self.assertEqual(sorted(params), sorted(self.protocol._get_param_list(['noparam', DriverParameter.ALL])))
# An exception is raised when the param is not a list or string
with self.assertRaises(InstrumentParameterException):
self.protocol._get_param_list({'other': 'struct'})
# when a subset is given, the same set is returned.
#.........这里部分代码省略.........
示例2: TestUnitInstrumentProtocol
# 需要导入模块: from mi.core.instrument.instrument_protocol import CommandResponseInstrumentProtocol [as 别名]
# 或者: from mi.core.instrument.instrument_protocol.CommandResponseInstrumentProtocol import _get_prompts [as 别名]
class TestUnitInstrumentProtocol(MiUnitTestCase):
"""
Test cases for instrument protocol class. Functions in this class provide
instrument protocol unit tests and provide a tutorial on use of
the protocol interface.
"""
def setUp(self):
"""
"""
self.callback_result = None
self._trigger_count = 0
self._events = []
self.protocol = InstrumentProtocol(self.event_callback)
def event_callback(self, event, value=None):
log.debug("Test event callback: %s" % event)
self._events.append(event)
self._trigger_count += 1
def _scheduler_callback(self):
"""
Callback to test the scheduler
"""
self._trigger_count += 1
def assert_scheduled_event_triggered(self, event_count=1):
count = 0
for i in range(0, 40):
count = self._trigger_count
log.debug("check for triggered event, count %d" % self._trigger_count)
if(count >= event_count): break
time.sleep(0.3)
self.assertGreater(count, 0)
def test_get_prompts(self):
"""
ensure prompts are returned sorted by length
"""
prompts = ['aa', 'bbb', 'c', 'dddd']
expected = ['dddd', 'bbb', 'aa', 'c']
class Prompts(BaseEnum):
A = 'aa'
B = 'bbb'
C = 'c'
D = 'dddd'
self.protocol = CommandResponseInstrumentProtocol(prompts, '\r\n', self.event_callback)
self.assertEqual(self.protocol._get_prompts(), expected)
self.protocol = CommandResponseInstrumentProtocol(Prompts, '\r\n', self.event_callback)
self.assertEqual(self.protocol._get_prompts(), expected)
def test_extraction(self):
sample_line = "SATPAR0229,10.01,2206748544,234\r\n"
ntptime = ntplib.system_to_ntp_time(time.time())
result = self.protocol._extract_sample(SatlanticPARDataParticle,
SAMPLE_REGEX,
sample_line,
ntptime,
publish=False)
log.debug("R: %s" % result)
self.assertEqual(result['stream_name'], SatlanticPARDataParticle(None, None).data_particle_type())
# Test the format of the result in the individual driver tests. Here,
# just tests that the result is there.
@unittest.skip('Not Written')
def test_publish_raw(self):
"""
Tests to see if raw data is appropriately published back out to
the InstrumentAgent via the event callback.
"""
# build a packet
# have it published by the protocol (force state if needed)
# delay?
# catch it in the callback
# confirm it came back
# compare response to original packet
self.assertTrue(False)
@unittest.skip('Not Written')
def test_publish_parsed_data(self):
"""
Tests to see if parsed data is appropriately published back to the
InstrumentAgent via the event callback.
"""
# similar to above
self.assertTrue(False)
@unittest.skip('Not Written')
def test_publish_engineering_data(self):
"""
Tests to see if engineering data is appropriately published back to the
InstrumentAgent via the event callback.
"""
# similar to above
#.........这里部分代码省略.........