def step_an_empty_file_named_filename(context, filename): """ Creates an empty file. """ assert not os.path.isabs(filename) command_util.ensure_workdir_exists(context) filename2 = os.path.join(context.workdir, filename) command_util.create_textfile_with_contents(filename2, "")
def step_a_file_named_filename_with(context, filename): """ Creates a textual file with the content provided as docstring. """ assert context.text is not None, "ENSURE: multiline text is provided." assert not os.path.isabs(filename) command_util.ensure_workdir_exists(context) filename2 = os.path.join(context.workdir, filename) command_util.create_textfile_with_contents(filename2, context.text) # -- SPECIAL CASE: For usage with behave steps. if filename.endswith(".feature"): command_util.ensure_context_attribute_exists(context, "features", []) context.features.append(filename)
def step_a_file_named_filename_with(context, filename): """ Creates a textual file with the content provided as docstring. """ assert context.text is not None, "ENSURE: multiline text is provided." assert not os.path.isabs(filename) command_util.ensure_workdir_exists(context) filename2 = os.path.join(context.workdir, filename) command_util.create_textfile_with_contents(filename2, context.text) # -- SPECIAL CASE: For usage with behave steps. if filename.endswith(".feature"): command_util.ensure_context_resource_exists(context, "features", []) context.features.append(filename)
def create_scenario(text, cwd="."): """ Creates a feature file with a scenario. """ global scenario_index template = """Feature: Something {0} """ contents = template.format(text) scenario_index += 1 feature_name = "scenario_{0}.feature".format(scenario_index) filename = os.path.abspath(os.path.join(cwd, feature_name)) command_util.create_textfile_with_contents(filename, contents) return filename
def create_step_definition(text, cwd="."): """ Create a step definition file from its text. """ global step_definition_index template = """ from behave import given, when, then {0} """ contents = template.format(text) step_definition_index += 1 dirname = os.path.normpath(os.path.join(cwd, "features", "steps")) step_filename = "step_{0}.py".format(step_definition_index) filename = os.path.abspath(os.path.join(dirname, step_filename)) command_util.create_textfile_with_contents(filename, contents) return filename