本文整理汇总了Python中mi.core.instrument.instrument_driver.SingleConnectionInstrumentDriver.test_force_state方法的典型用法代码示例。如果您正苦于以下问题:Python SingleConnectionInstrumentDriver.test_force_state方法的具体用法?Python SingleConnectionInstrumentDriver.test_force_state怎么用?Python SingleConnectionInstrumentDriver.test_force_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mi.core.instrument.instrument_driver.SingleConnectionInstrumentDriver
的用法示例。
在下文中一共展示了SingleConnectionInstrumentDriver.test_force_state方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestUnitInstrumentDriver
# 需要导入模块: from mi.core.instrument.instrument_driver import SingleConnectionInstrumentDriver [as 别名]
# 或者: from mi.core.instrument.instrument_driver.SingleConnectionInstrumentDriver import test_force_state [as 别名]
class TestUnitInstrumentDriver(IonUnitTestCase):
"""
Test cases for instrument driver class. Functions in this class provide
instrument driver unit tests and provide a tutorial on use of
the driver interface.
"""
def setUp(self):
self.mock = DotDict()
self.mock.port_agent = Mock(name='port_agent_client')
self.mock.callback = Mock(name='callback')
self.driver = SingleConnectionInstrumentDriver(self.mock.callback)
def test_test_mode(self):
"""
Test driver test mode.
Ensure driver test mode attribute is set properly and verify
exceptions are thrown when not in test mode.
"""
# Ensure that we default to test mode off
self.assertFalse(self.driver._test_mode)
exception = False
try:
self.driver.set_test_mode(False)
self.driver.test_force_state(state=1)
except(TestModeException):
exception = True
except(Exception):
# ignore other exceptions
pass
self.assertTrue(exception)
# Now set test mode and try to run again.
exception = False
try:
self.driver.set_test_mode(True)
self.assertTrue(self.driver._test_mode)
self.driver.test_force_state(state=1)
except(TestModeException):
exception = True
except(Exception):
# ignore other exceptions
pass
self.assertFalse(exception)
示例2: TestUnitInstrumentDriver
# 需要导入模块: from mi.core.instrument.instrument_driver import SingleConnectionInstrumentDriver [as 别名]
# 或者: from mi.core.instrument.instrument_driver.SingleConnectionInstrumentDriver import test_force_state [as 别名]
class TestUnitInstrumentDriver(MiUnitTestCase):
"""
Test cases for instrument driver class. Functions in this class provide
instrument driver unit tests and provide a tutorial on use of
the driver interface.
"""
def setUp(self):
self.mock = DotDict()
self.mock.port_agent = Mock(name='port_agent_client')
self.mock.callback = Mock(name='callback')
def mock_set(values):
assert isinstance(values, dict)
return_string = ""
for key in values.keys():
return_string += "%s=%s" % (key, values[key]) # inefficient, I know
return return_string
self.driver = SingleConnectionInstrumentDriver(self.mock.callback)
# set some values
self.driver._protocol = InstrumentProtocol(self.mock.callback)
self.driver.set_resource = mock_set
self.driver._protocol._param_dict.add("foo", r'foo=(.*)',
lambda match : int(match.group(1)),
lambda x : str(x),
direct_access=True,
startup_param=True,
default_value=10)
self.driver._protocol._param_dict.set_default("foo")
self.driver._protocol._param_dict.add("bar", r'bar=(.*)',
lambda match : int(match.group(1)),
lambda x : str(x),
direct_access=False,
startup_param=True,
default_value=15)
self.driver._protocol._param_dict.set_default("bar")
self.driver._protocol._param_dict.add("baz", r'baz=(.*)',
lambda match : int(match.group(1)),
lambda x : str(x),
direct_access=True,
default_value=30)
self.driver._protocol._param_dict.set_default("baz")
self.driver._protocol._param_dict.add("bat", r'bat=(.*)',
lambda match : int(match.group(1)),
lambda x : str(x),
startup_param=False,
default_value=40)
self.driver._protocol._param_dict.set_default("bat")
def test_test_mode(self):
"""
Test driver test mode.
Ensure driver test mode attribute is set properly and verify
exceptions are thrown when not in test mode.
"""
# Ensure that we default to test mode off
self.assertFalse(self.driver._test_mode)
exception = False
try:
self.driver.set_test_mode(False)
self.driver.test_force_state(state=1)
except(TestModeException):
exception = True
except(Exception):
# ignore other exceptions
pass
self.assertTrue(exception)
# Now set test mode and try to run again.
exception = False
try:
self.driver.set_test_mode(True)
self.assertTrue(self.driver._test_mode)
self.driver.test_force_state(state=1)
except(TestModeException):
exception = True
except(Exception):
# ignore other exceptions
pass
self.assertFalse(exception)
def test_direct_access_params(self):
"""
Tests to see how direct access parameters are setup and that they are
working properly.
"""
self.assertTrue(self.driver._protocol._param_dict.get("foo"), 10)
self.assertTrue(self.driver._protocol._param_dict.get("bar"), 15)
# use real driver sets here, the direct poke of the param dict is just
#.........这里部分代码省略.........