Exemple #1
0
def tmp_dir_as_cwd(contents: DirContents = empty_dir_contents()
                   ) -> ContextManager[pathlib.Path]:
    with temp_dir() as dir_path:
        with preserved_cwd():
            os.chdir(str(dir_path))
            contents.write_to(dir_path)
            yield dir_path
Exemple #2
0
def tmp_dir_as_cwd(contents: DirContents = empty_dir_contents()) -> pathlib.Path:
    with tempfile.TemporaryDirectory() as dir_name:
        with preserved_cwd():
            dir_path = resolved_path(dir_name)
            os.chdir(str(dir_path))
            contents.write_to(dir_path)
            yield dir_path
def single_dir_setup(contents: DirContents = empty_dir_contents()
                     ) -> SingleDirSetup:
    action_dir = Dir('act', contents.file_system_elements)
    tmp_dir_contents = DirContents([action_dir])
    with tempfile.TemporaryDirectory() as dir_name:
        dir_path = resolved_path(dir_name)
        tmp_dir_contents.write_to(dir_path)
        yield SingleDirSetup(dir_path / action_dir.name, )
Exemple #4
0
def tmp_dir_in_path_with_files(
        files: DirContents) -> ContextManager[Dict[str, str]]:
    with tempfile.TemporaryDirectory(
            prefix=program_info.PROGRAM_NAME) as tmp_dir_name:
        environ = dict(os.environ)
        environ['PATH'] = os.pathsep.join((tmp_dir_name, environ['PATH']))

        files.write_to(pathlib.Path(tmp_dir_name))
        yield environ
Exemple #5
0
def tmp_dir(contents: DirContents = empty_dir_contents()) -> ContextManager[
        pathlib.Path]:
    with temp_dir() as dir_path:
        contents.write_to(dir_path)
        yield dir_path
Exemple #6
0
def tmp_dir(contents: DirContents = empty_dir_contents()) -> pathlib.Path:
    with tempfile.TemporaryDirectory() as dir_name:
        dir_path = resolved_path(dir_name)
        contents.write_to(dir_path)
        yield dir_path