本文整理汇总了Python中behave.given方法的典型用法代码示例。如果您正苦于以下问题:Python behave.given方法的具体用法?Python behave.given怎么用?Python behave.given使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类behave
的用法示例。
在下文中一共展示了behave.given方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: step_connect_device
# 需要导入模块: import behave [as 别名]
# 或者: from behave import given [as 别名]
def step_connect_device(context, device):
"""Tries to connect to the given.
Args:
context (Context): the ``Context`` instance
device (str): name of the devie to connect to
Returns:
``None``
"""
try:
jlink = context.jlink
jlink.connect(str(device))
jlink.set_reset_strategy(pylink.JLinkResetStrategyCortexM3.NORMAL)
except pylink.JLinkException as e:
if e.code == pylink.JLinkGlobalErrors.VCC_FAILURE:
context.scenario.skip(reason='Target is not powered.')
elif e.code == pylink.JLinkGlobalErrors.NO_CPU_FOUND:
context.scenario.skip(reason='Target core not found.')
示例2: step_set_breakpoint
# 需要导入模块: import behave [as 别名]
# 或者: from behave import given [as 别名]
def step_set_breakpoint(context, addr):
"""Sets a breakpoint at the given address.
Args:
context (Context): the ``Context`` instance
addr (str): the address to set the breakpoint at
Returns:
``None``
Raises:
TypeError: if the given address cannot be converted to an int.
"""
addr = int(addr, 0)
context.handle = context.jlink.breakpoint_set(addr, thumb=True)
assert context.jlink.breakpoint_find(addr) == context.handle
bp = context.jlink.breakpoint_info(context.handle)
assert bp.Addr == addr
示例3: step_set_watchpoint
# 需要导入模块: import behave [as 别名]
# 或者: from behave import given [as 别名]
def step_set_watchpoint(context, addr, data):
"""Sets a watchpoint at the given address for the given data value.
Args:
context (Context): the ``Context`` instance
addr (str): the address the watchpoint should be set at
data (str): the data value to trigger the watchpoint on
Returns:
``None``
Raises:
TypeError: if the given address or data cannot be converted to an int.
"""
addr = int(addr, 0)
data = int(data, 0)
context.handle = context.jlink.watchpoint_set(addr, data=data)
wp = context.jlink.watchpoint_info(context.handle)
assert wp.Addr == addr
assert wp.Handle == context.handle
assert wp.Data == data
示例4: map_action
# 需要导入模块: import behave [as 别名]
# 或者: from behave import given [as 别名]
def map_action(step_text: str, existing_step_or_steps: Union[str, List[str]]) -> None:
"""
Map new "given"/"when" steps to one or many existing one(s).
Parameters are propagated to the original step(s) as well, as expected.
Examples:
- map_action('I open door', 'I send event open_door')
- map_action('Event {name} has to be sent', 'I send event {name}')
- map_action('I do two things', ['First thing to do', 'Second thing to do'])
:param step_text: Text of the new step, without the "given" or "when" keyword.
:param existing_step_or_steps: existing step, without the "given" or "when" keyword. Could be a list of steps.
"""
if not isinstance(existing_step_or_steps, str):
existing_step_or_steps = '\nand '.join(existing_step_or_steps)
@given(step_text)
def _(context, **kwargs):
context.execute_steps('Given ' + existing_step_or_steps.format(**kwargs))
@when(step_text)
def _(context, **kwargs):
context.execute_steps('When ' + existing_step_or_steps.format(**kwargs))
示例5: step_impl
# 需要导入模块: import behave [as 别名]
# 或者: from behave import given [as 别名]
def step_impl(context, args):
cbs = ','.join(context.callbacks)
context.execute_steps('given successful pgmigrate run with ' + '"%s"' %
('-a ' + cbs + ' ' + args, ))
示例6: step_has_license
# 需要导入模块: import behave [as 别名]
# 或者: from behave import given [as 别名]
def step_has_license(context):
"""Asserts the J-Link has the given licenese.
Args:
context (Context): the ``Context`` instance
Returns:
``None``
"""
jlink = context.jlink
expected = context.text.strip()
actual = jlink.custom_licenses.strip()
assert actual.startswith(expected)
assert jlink.erase_licenses()
示例7: step_flash_firmware_retries
# 需要导入模块: import behave [as 别名]
# 或者: from behave import given [as 别名]
def step_flash_firmware_retries(context, firmware, retries):
"""Tries to flash the firmware with the given number of retries.
Args:
context (Context): the ``Context`` instance
firmware (str): the name of the firmware to flash
retries (int): the number of retries to do
Returns:
``None``
"""
jlink = context.jlink
retries = int(retries)
firmware = utility.firmware_path(str(firmware))
assert firmware is not None
while True:
try:
res = utility.flash_k21(jlink, firmware)
if res >= 0:
break
else:
retries = retries - 1
except pylink.JLinkException as e:
sys.stderr.write('%s%s' % (str(e), os.linesep))
retries = retries - 1
if retries < 0:
break
assert retries >= 0
示例8: step_num_breakpoints
# 需要导入模块: import behave [as 别名]
# 或者: from behave import given [as 别名]
def step_num_breakpoints(context, num):
"""Asserts that there are the specified number of breakpoints.
Args:
context (Context): the ``Context`` instance
num (str): number of breakpoints that should exist
Returns:
``None``
Raises:
TypeError: if the given number cannot be converted to an int.
"""
assert int(num) == context.jlink.num_active_breakpoints()
示例9: step_num_watchpoints
# 需要导入模块: import behave [as 别名]
# 或者: from behave import given [as 别名]
def step_num_watchpoints(context, num):
"""Asserts that there are the specified number of watchpoints.
Args:
context (Context): the ``Context`` instance
num (str): number of watchpoints that should exist
Returns:
``None``
Raises:
TypeError: if the given number cannot be converted to an int.
"""
assert int(num) == context.jlink.num_active_watchpoints()
示例10: step_should_hit_watchpoint
# 需要导入模块: import behave [as 别名]
# 或者: from behave import given [as 别名]
def step_should_hit_watchpoint(context, addr):
"""Checks that the watchpoint is hit at the given address.
Args:
context (Context): the ``Context`` instance
addr (str): the address the watchpoint is expected to trigger on
Returns:
``None``
Raises:
TypeError: if the given address cannot be converted to an int.
"""
jlink = context.jlink
while not jlink.halted():
time.sleep(1)
cpu_halt_reasons = jlink.cpu_halt_reasons()
assert len(cpu_halt_reasons) == 1
halt_reason = cpu_halt_reasons[0]
assert halt_reason.data_breakpoint()
index = halt_reason.Index
wp = jlink.watchpoint_info(index=index)
addr = int(addr, 0)
assert addr == wp.Addr
示例11: impl
# 需要导入模块: import behave [as 别名]
# 或者: from behave import given [as 别名]
def impl(context):
context.execute_steps('''
given there is a standard user in the database
''')
context.standard_user2 = UserFactory(full_name='Another User',
email='standard.user2@test.test')
示例12: load_test_connection_file
# 需要导入模块: import behave [as 别名]
# 或者: from behave import given [as 别名]
def load_test_connection_file(context):
"""Set up the context manager for a given connection_type."""
try:
context.manager = ConnectionManager(file_name=CONNECTIONS_FILE)
context.exc = None
except Exception as e:
context.exc = e
示例13: load_test_connection_file_with_default
# 需要导入模块: import behave [as 别名]
# 或者: from behave import given [as 别名]
def load_test_connection_file_with_default(context):
"""Set up the context manager for a given connection_type."""
try:
context.manager = ConnectionManager(
file_name=CONNECTIONS_FILE_WITH_DEFAULT)
context.exc = None
except Exception as e:
context.exc = e
示例14: load_default_connection_file
# 需要导入模块: import behave [as 别名]
# 或者: from behave import given [as 别名]
def load_default_connection_file(context):
"""Set up the context manager for a given connection_type."""
try:
context.manager = ConnectionManager()
context.exc = None
except Exception as e:
context.exc = e
示例15: load_test_connection_file_with_2_defaults
# 需要导入模块: import behave [as 别名]
# 或者: from behave import given [as 别名]
def load_test_connection_file_with_2_defaults(context):
"""Set up the context manager for a given connection_type."""
try:
context.manager = ConnectionManager(
file_name=CONNECTIONS_FILE_WITH_DEFAULTS)
context.exc = None
except Exception as e:
context.exc = e