Ejemplo n.º 1
0
def step_a_new_working_directory(context):
    """
    Creates a new, empty working directory
    """
    command_util.ensure_context_attribute_exists(context, "workdir", None)
    command_util.ensure_workdir_exists(context)
    shutil.rmtree(context.workdir, ignore_errors=True)
Ejemplo n.º 2
0
def step_a_new_working_directory(context):
    """
    Creates a new, empty working directory
    """
    command_util.ensure_context_attribute_exists(context, "workdir", None)
    command_util.ensure_workdir_exists(context)
    shutil.rmtree(context.workdir, ignore_errors=True)
Ejemplo n.º 3
0
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)
    pathutil.create_textfile_with_contents(filename2, "")
Ejemplo n.º 4
0
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)
    pathutil.create_textfile_with_contents(filename2, "")
Ejemplo n.º 5
0
def step_a_file_named_filename_and_encoding_with(context, filename, encoding):
    """Creates a textual file with the content provided as docstring."""
    __encoding_is_valid = True
    assert context.text is not None, "ENSURE: multiline text is provided."
    assert not os.path.isabs(filename)
    assert __encoding_is_valid
    command_util.ensure_workdir_exists(context)
    filename2 = os.path.join(context.workdir, filename)
    pathutil.create_textfile_with_contents(filename2, context.text, encoding)
Ejemplo n.º 6
0
def step_a_file_named_filename_and_encoding_with(context, filename, encoding):
    """Creates a textual file with the content provided as docstring."""
    __encoding_is_valid = True
    assert context.text is not None, "ENSURE: multiline text is provided."
    assert not os.path.isabs(filename)
    assert __encoding_is_valid
    command_util.ensure_workdir_exists(context)
    filename2 = os.path.join(context.workdir, filename)
    pathutil.create_textfile_with_contents(filename2, context.text, encoding)
Ejemplo n.º 7
0
def step_i_run_command(context, command):
    """
    Run a command as subprocess, collect its output and returncode.
    """
    command_util.ensure_workdir_exists(context)
    context.command_result = command_shell.run(command, cwd=context.workdir)
    command_util.workdir_save_coverage_files(context.workdir)
    if False and DEBUG:
        print(u"run_command: {0}".format(command))
        print(u"run_command.output {0}".format(context.command_result.output))
Ejemplo n.º 8
0
def step_i_run_command(context, command):
    """
    Run a command as subprocess, collect its output and returncode.
    """
    command_util.ensure_workdir_exists(context)
    context.command_result = command_shell.run(command, cwd=context.workdir)
    command_util.workdir_save_coverage_files(context.workdir)
    if False and DEBUG:
        print(u"run_command: {0}".format(command))
        print(u"run_command.output {0}".format(context.command_result.output))
Ejemplo n.º 9
0
def step_copytree_to_workdir_with_destdir(ctx, source_dir, dest_dir):
    ensure_workdir_exists(ctx)
    workdir = Path(ctx.workdir or "__WORKDIR__").normpath()
    source_dir = Path(source_dir).normpath()
    dest_dir = Path(dest_dir).normpath()
    workpath_dest_dir = workdir / Path(dest_dir)
    workpath_dest_dir = workpath_dest_dir.normpath()

    assert source_dir.isdir(), "ENSURE: source_dir=%s exists" % source_dir
    workpath_dest_dir.rmtree_p()
    source_dir.copytree(workpath_dest_dir)
    assert workpath_dest_dir.isdir()
Ejemplo n.º 10
0
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)
    pathutil.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)
Ejemplo n.º 11
0
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)
    pathutil.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)
Ejemplo n.º 12
0
def step_a_file_named_filename_and_encoding_with(context, filename, encoding):
    """Creates a textual file with the content provided as docstring."""
    __encoding_is_valid = True
    text_to_use = context.text
    # TODO refactor this try/except
    try:
        if context.surrogate_text is not None:
            text_to_use = context.surrogate_text
        else:
            assert context.text is not None, "ENSURE: multiline text is provided."
    except AttributeError:
        assert context.text is not None, "ENSURE: multiline text is provided."
    assert not os.path.isabs(filename)
    assert __encoding_is_valid
    command_util.ensure_workdir_exists(context)
    filename2 = os.path.join(context.workdir, filename)
    pathutil.create_textfile_with_contents(filename2, text_to_use, encoding)
Ejemplo n.º 13
0
def step_i_run_command(ctx, command, directory):
    """Run a command as subprocess in another directory,
    collect its output and returncode.
    """
    command_util.ensure_workdir_exists(ctx)
    workdir2 = Path(directory)
    if not workdir2.isabs():
        # -- USE: WORKDIR
        workdir2 = Path(ctx.workdir) / directory
    if not workdir2.isdir():
        assert False, "NEW WORKDIR={0} does not exists".format(
            workdir2.relpath())

    with cd(workdir2):
        # print("RUN: {0} (cwd={1})".format(command, Path(".").abspath()))
        text = u'When I run "{0}"'.format(command)
        ctx.execute_steps(text)
Ejemplo n.º 14
0
def step_use_directory_as_working_directory(context, directory):
    """Uses the directory as new working directory"""
    command_util.ensure_context_attribute_exists(context, "workdir", None)
    current_workdir = context.workdir
    if not current_workdir:
        current_workdir = os.getcwd()

    if not os.path.isabs(directory):
        new_workdir = os.path.join(current_workdir, directory)
        exists_relto_current_dir = os.path.isdir(directory)
        exists_relto_current_workdir = os.path.isdir(new_workdir)
        if exists_relto_current_workdir or not exists_relto_current_dir:
            # -- PREFER: Relative to current workdir
            workdir = new_workdir
        else:
            assert exists_relto_current_workdir
            workdir = directory
        workdir = os.path.abspath(workdir)

    context.workdir = workdir
    command_util.ensure_workdir_exists(context)
Ejemplo n.º 15
0
def step_use_directory_as_working_directory(context, directory):
    """Uses the directory as new working directory"""
    command_util.ensure_context_attribute_exists(context, "workdir", None)
    current_workdir = context.workdir
    if not current_workdir:
        current_workdir = os.getcwd()

    if not os.path.isabs(directory):
        new_workdir = os.path.join(current_workdir, directory)
        exists_relto_current_dir = os.path.isdir(directory)
        exists_relto_current_workdir = os.path.isdir(new_workdir)
        if exists_relto_current_workdir or not exists_relto_current_dir:
            # -- PREFER: Relative to current workdir
            workdir = new_workdir
        else:
            assert exists_relto_current_workdir
            workdir = directory
        workdir = os.path.abspath(workdir)

    context.workdir = workdir
    command_util.ensure_workdir_exists(context)
Ejemplo n.º 16
0
def step_file_named_filename_should_not_exist(context, filename):
    command_util.ensure_workdir_exists(context)
    filename_ = pathutil.realpath_with_context(filename, context)
    assert_that(not os.path.exists(filename_))
Ejemplo n.º 17
0
def step_copytree_to_workdir(ctx, source_dir):
    """Copy a directory :param:`source_dir` -> workdir:basename(source_dir)/"""
    ensure_workdir_exists(ctx)
    source_dir = Path(source_dir).normpath()
    dest_dir = source_dir.basename()
    step_copytree_to_workdir_with_destdir(ctx, source_dir, dest_dir)
Ejemplo n.º 18
0
def step_file_named_filename_should_not_exist(context, filename):
    command_util.ensure_workdir_exists(context)
    filename_ = pathutil.realpath_with_context(filename, context)
    assert_that(not os.path.exists(filename_))
Ejemplo n.º 19
0
def step_use_curdir_as_working_directory(context):
    """
    Uses the current directory as working directory
    """
    context.workdir = os.path.abspath(".")
    command_util.ensure_workdir_exists(context)
Ejemplo n.º 20
0
def step_use_curdir_as_working_directory(context):
    """
    Uses the current directory as working directory
    """
    context.workdir = os.path.abspath(".")
    command_util.ensure_workdir_exists(context)