Python behave.when() Examples
The following are 12
code examples of behave.when().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
behave
, or try the search function
.
Example #1
Source File: local_run_steps.py From paasta with Apache License 2.0 | 6 votes |
def non_interactive_local_run(context, var, val): with Path("fake_simple_service"): # The local-run invocation here is designed to run and return a sentinel # exit code that we can look out for. It also sleeps a few seconds # because the local-run code currently crashes when the docker # container dies before it gets a chance to lookup the containerid # (which causes jenkins flakes) The sleep can be removed once local-run # understands that containers can die quickly. localrun_cmd = ( "paasta local-run " "--yelpsoa-config-root ../fake_soa_configs_local_run/ " "--service fake_simple_service " "--cluster test-cluster " "--instance main " "--build " """--cmd '/bin/sh -c "echo \\"%s=$%s\\" && sleep 2s && exit 42"' """ % (var, var) ) context.return_code, context.output = _run(command=localrun_cmd, timeout=90)
Example #2
Source File: wrappers.py From sismic with GNU Lesser General Public License v3.0 | 6 votes |
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))
Example #3
Source File: callbacks.py From pgmigrate with PostgreSQL License | 5 votes |
def step_impl(context, args): cbs = ','.join(context.callbacks) context.execute_steps('when we run pgmigrate with ' + '"%s"' % ('-a ' + cbs + ' ' + args, ))
Example #4
Source File: callbacks.py From pgmigrate with PostgreSQL License | 5 votes |
def step_impl(context, cb_type, args): p_args = '-a ' + cb_type + ':' + context.migr_dir + '/callbacks/ ' + args context.execute_steps('when we run pgmigrate with "%s"' % (p_args, ))
Example #5
Source File: common.py From pylink with Apache License 2.0 | 5 votes |
def step_flash_firmware_bytestream_retries(context, retries): """Tries to flash the firmware from a bytestream. Args: context (Context): the ``Context`` instance retries (int): the number of retries when flashing Returns: ``None`` """ jlink = context.jlink retries = int(retries) data = context.data while retries >= 0: try: res = jlink.flash(context.data, 0) if res >= 0: break except pylink.JLinkException as e: retries = retries - 1 assert retries >= 0 written = list(map(int, jlink.memory_read8(0, len(data)))) assert written == data
Example #6
Source File: swo.py From pylink with Apache License 2.0 | 5 votes |
def step_enable_swo_on_port(context, port): """Enables Serial Wire Output. Args: context (Context): the ``Context`` instance port (int): the port SWO is enabled on Returns: ``None`` """ jlink = context.jlink # Have to halt the CPU before getting its speed. jlink.reset() jlink.halt() assert jlink.halted() cpu_speed = jlink.cpu_speed() swo_speed = jlink.swo_supported_speeds(cpu_speed, 3)[0] # Enable SWO and flush. This must come before the reset to ensure that no # data is present in the SWO buffer when the core restarts. jlink.swo_start(swo_speed) jlink.swo_flush() assert jlink.swo_enabled() # Reset the core without halting so that it runs. jlink.reset(ms=10, halt=False) time.sleep(1)
Example #7
Source File: common.py From connect with BSD 3-Clause "New" or "Revised" License | 5 votes |
def impl(context): context.execute_steps(''' when I visit the "login" page when I enter "standard.user@test.test" into the "username" field when I enter "pass" into the "password" field when I submit the form ''')
Example #8
Source File: common.py From connect with BSD 3-Clause "New" or "Revised" License | 5 votes |
def impl(context): context.execute_steps(''' when I visit the "login" page when I enter "moderator@test.test" into the "username" field when I enter "pass" into the "password" field when I submit the form ''')
Example #9
Source File: mail_list.py From pixelated-user-agent with GNU Affero General Public License v3.0 | 5 votes |
def impl(context, tag): context.execute_steps("when I select the tag '%s'" % tag) context.execute_steps(u'When I open the first mail in the mail list')
Example #10
Source File: connection-mode.py From SimQLe with MIT License | 5 votes |
def test_mode_environment_check(context): """Test that the SIMQLE_MODE env variable switches the connections.""" # When there is no SIMQLE_MODE set, production mode is used by default assert os.getenv("SIMQLE_MODE", None) is None production_manager = ConnectionManager() production_engine = production_manager.get_engine("my-sqlite-database") production_url = str(production_engine.url) assert production_url == "sqlite:////tmp/production-database.db" # when SIMQLE_MODE is "production", then production mode is active os.environ["SIMQLE_MODE"] = "production" production_manager = ConnectionManager() production_engine = production_manager.get_engine("my-sqlite-database") production_url = str(production_engine.url) assert production_url == "sqlite:////tmp/production-database.db" # when SIMQLE_MODE is "development", then development mode is active os.environ["SIMQLE_MODE"] = "development" development_manager = ConnectionManager() development_engine = development_manager.get_engine("my-sqlite-database") development_url = str(development_engine.url) assert development_url == "sqlite:////tmp/development-database.db" # when SIMQLE_MODE is "testing", then testing mode is active os.environ["SIMQLE_MODE"] = "testing" development_manager = ConnectionManager() development_engine = development_manager.get_engine("my-sqlite-database") development_url = str(development_engine.url) assert development_url == "sqlite:////tmp/test-database.db" # del SIMQLE_MODE for the next test del os.environ["SIMQLE_MODE"]
Example #11
Source File: connection-mode.py From SimQLe with MIT License | 5 votes |
def test_mode_environment_check(context): """Test that the SIMQLE_TEST env variable switches the connections to test mode, despite SIMQLE_MODE.""" # When there is no SIMQLE_MODE set, production mode is used by default assert os.getenv("SIMQLE_TEST", None) is None production_manager = ConnectionManager() production_engine = production_manager.get_engine("my-sqlite-database") production_url = str(production_engine.url) assert production_url == "sqlite:////tmp/production-database.db" # when SIMQLE_TEST is "true", then test mode is active os.environ["SIMQLE_TEST"] = "true" test_manager = ConnectionManager() test_engine = test_manager.get_engine("my-sqlite-database") test_url = str(test_engine.url) assert test_url == "sqlite:////tmp/test-database.db" # Same thing, despite SIMQLE_MODE os.environ["SIMQLE_TEST"] = "true" os.environ["SIMQLE_MODE"] = "development" test_manager = ConnectionManager() test_engine = test_manager.get_engine("my-sqlite-database") test_url = str(test_engine.url) assert test_url == "sqlite:////tmp/test-database.db" del os.environ["SIMQLE_MODE"] del os.environ["SIMQLE_TEST"] # --- Then ---
Example #12
Source File: step_definitions.py From dockerpty with Apache License 2.0 | 5 votes |
def step_impl(ctx): # you should check `actual` when tests fail actual = util.read_printable(ctx.pty).splitlines() wanted = ctx.text.splitlines() expect(actual[-len(wanted):]).to(equal(wanted))