Best Python code snippet using behave
command_steps.py
Source:command_steps.py
...39# -----------------------------------------------------------------------------40# STEPS: Create files with contents41# -----------------------------------------------------------------------------42@given(u'a file named "{filename}" with')43def step_a_file_named_filename_with(context, filename):44 """45 Creates a textual file with the content provided as docstring.46 """47 assert context.text is not None, "ENSURE: multiline text is provided."48 assert not os.path.isabs(filename)49 command_util.ensure_workdir_exists(context)50 filename2 = os.path.join(context.workdir, filename)51 pathutil.create_textfile_with_contents(filename2, context.text)52 # -- SPECIAL CASE: For usage with behave steps.53 if filename.endswith(".feature"):54 command_util.ensure_context_attribute_exists(context, "features", [])55 context.features.append(filename)56@given(u'an empty file named "{filename}"')57def step_an_empty_file_named_filename(context, filename):...
git_steps.py
Source:git_steps.py
...23@given("a starting git repo")24def step_a_starting_git_repo(context):25 step_an_empty_git_repo_with_initial_branch(context, "main")26 context.surrogate_text = "foo bar"27 step_a_file_named_filename_with(context, "initial_commit_file")28 step_add_file_to_index(context, "initial_commit_file")29 step_commit_index_with_message(context, "chore: initial commit")30@given('a starting git repo with "{initial_branch}" as initial branch')31def step_a_starting_git_repo_with_initial_branch(context, initial_branch):32 step_an_empty_git_repo_with_initial_branch(context, initial_branch)33 context.surrogate_text = "foo bar"34 step_a_file_named_filename_with(context, "initial_commit_file")35 step_add_file_to_index(context, "initial_commit_file")36 step_commit_index_with_message(context, "chore: initial commit")37@then("a git repo should exist")38def step_a_git_repo_should_exist(context):39 assert_that(40 calling(Repo).with_args(context.workdir),41 not_(raises(InvalidGitRepositoryError)),42 )43# -----------------------------------------------------------------------------44# STEPS: Commits45# -----------------------------------------------------------------------------46@then("the head commit should contain the files")47def step_current_commit_should_contain_files(context):48 assert context.table is not None and context.table.has_column(...
steps.py
Source:steps.py
2import dbt.main3from behave import given, when, then4@given(u'a seed "{name}" with')5def a_seed_with_body(context, name):6 behave4cmd0.command_steps.step_a_file_named_filename_with(7 context,8 "data/{}.csv".format(name)9 )10@given(u'a model "{name}" with')11def a_model_with_body(context, name):12 behave4cmd0.command_steps.step_a_file_named_filename_with(13 context,14 "models/{}.sql".format(name)15 )16@given(u'a macro file "{name}" with')17def a_macro_file_with_body(context, name):18 behave4cmd0.command_steps.step_a_file_named_filename_with(19 context,20 "macros/{}.sql".format(name)21 )22@when(u'I successfully run "{command}"')23@when(u'I successfully run `{command}`')24def step_i_successfully_execute_command(context, command):25 command += " --profile {}".format(26 context.config.userdata.get('profile_name')27 )28 behave4cmd0.command_steps.step_i_run_command(context, command)29 behave4cmd0.command_steps.step_it_should_pass(context)30@when(u'I update model "{name}" to')31def update_model_with_body(context, name):32 behave4cmd0.command_steps.step_a_file_named_filename_with(33 context,34 "models/{}.sql".format(name)35 )36@then(u'"{relation_one}" and "{relation_two}" should be equivalent')37def seed_and_view_should_be_equivalent(context, relation_one, relation_two):38 raise NotImplementedError(39 u'STEP: "{}" and "{}" should be equivalent',40 relation_one,41 relation_two...
adr_steps.py
Source:adr_steps.py
...17Context and problem statement.18## Decision Outcome19Decision outcome.20"""21 step_a_file_named_filename_with(context, filename)22@given('an accepted adr file named "{filename}"')23def step_an_accepted_adr_file_named_filename(context, filename):24 path = Path(filename)25 assert_that(path.name, matches_regexp(VALID_ADR_FILENAME_WITH_ID_REGEX))26 title_slug = path.stem.split("-", 1)[1]27 title = " ".join([word.capitalize() for word in title_slug.split("-")])28 context.surrogate_text = f"""29# {title}30* Status: accepted31* Date: 2020-03-2632## Context and Problem Statement33Context and problem statement.34## Decision Outcome35Decision outcome.36"""...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!