def data(tmpdir_factory, _cookiecutter_config_file, docker_compose): p = tmpdir_factory.mktemp("data") compose = p.join("docker-compose.yaml") compose.write(docker_compose) snakefile = p.join("Snakefile") SNAKEFILE.copy(snakefile) cluster_config = p.join("cluster-config.yaml") CLUSTERCONFIG.copy(cluster_config) template = os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir) output_factory = tmpdir_factory.mktemp c = Cookies(template, output_factory, _cookiecutter_config_file) c._new_output_dir = lambda: str(p.join("slurm")) c.bake( extra_context={ 'partition': 'normal', 'output': 'logs/slurm-%j.out', 'error': 'logs/slurm-%j.err' }) # Advanced setting c = Cookies(template, output_factory, _cookiecutter_config_file) c._new_output_dir = lambda: str(p.join("slurm-advanced")) c.bake( extra_context={ 'partition': 'normal', 'output': 'logs/slurm-%j.out', 'error': 'logs/slurm-%j.err', 'submit_script': 'slurm-submit-advanced.py' }) return p
def data(tmpdir_factory, _cookiecutter_config_file, docker_compose): p = tmpdir_factory.mktemp("data") compose = p.join("docker-compose.yaml") compose.write(docker_compose) snakefile = p.join("Snakefile") SNAKEFILE.copy(snakefile) template = os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir) output_factory = tmpdir_factory.mktemp c = Cookies(template, output_factory, _cookiecutter_config_file) c._new_output_dir = lambda: str(p) c.bake(extra_context={'partition': 'normal'}) return p
def test_initial_run_without_change_on_template_just_initializes_branch( cookiecutter_template_directory: Path, cookies: Cookies): result: Result = cookies.bake( extra_context=SAMPLE_CONTEXT, template=str(cookiecutter_template_directory)) if result.exception is not None: raise result.exception project_directory = Path(result.project) _initialize_git_repo(project_directory) subprocess.run(["git", "add", "-A"], cwd=str(project_directory), check=True) subprocess.run(["git", "commit", "-m", "initial"], cwd=str(project_directory), check=True) context = json.loads( project_directory.joinpath( "docs", "cookiecutter_input.json").read_text(encoding="utf-8")) update_project_template_branch(context, str(project_directory), "cookiecutter-template", merge_now=None, push_template_branch_changes=False, exclude_pathspecs=None) subprocess.run(["git", "rev-parse", "cookiecutter-template"], cwd=str(project_directory), check=True)
def test_exclude_paths(cookiecutter_template_directory: Path, cookies: Cookies): result: Result = cookies.bake( extra_context=SAMPLE_CONTEXT, template=str(cookiecutter_template_directory)) if result.exception is not None: raise result.exception project_directory = Path(result.project) _initialize_git_repo(project_directory) subprocess.run(["git", "add", "-A"], cwd=str(project_directory), check=True) subprocess.run(["git", "commit", "-m", "initial"], cwd=str(project_directory), check=True) context = json.loads( project_directory.joinpath( "docs", "cookiecutter_input.json").read_text(encoding="utf-8")) context['_template'] = str(cookiecutter_template_directory) context['project_slug'] = 'a_new_name' update_project_template_branch(context, str(project_directory), "cookiecutter-template", merge_now=True, push_template_branch_changes=False, exclude_pathspecs='README.rst') readme = project_directory.joinpath("README.rst").read_text( encoding="utf-8") assert 'a_new_name' not in readme
def cookies(request, _cookiecutter_config_file): template_dir = request.config.option.template p = py.path.local('tests/projects') if p.exists(): p.remove() output_factory = py.path.local('tests').mkdir('projects').mkdir return Cookies(template_dir, output_factory, _cookiecutter_config_file)
def test_first_run_creates_branch_on_first_commit_and_updates_based_on_template( cookiecutter_template_directory: Path, cookies: Cookies): result: Result = cookies.bake( extra_context=SAMPLE_CONTEXT, template=str(cookiecutter_template_directory)) if result.exception is not None: raise result.exception project_directory = Path(result.project) _initialize_git_repo(project_directory) subprocess.run(["git", "add", "-A"], cwd=str(project_directory), check=True) subprocess.run(["git", "commit", "-m", "initial"], cwd=str(project_directory), check=True) context = json.loads( project_directory.joinpath( "docs", "cookiecutter_input.json").read_text(encoding="utf-8")) cookiecutter_template_directory.joinpath( "{{cookiecutter.project_slug}}", "README.rst").write_text("updated readme") cookiecutter_template_directory.joinpath("{{cookiecutter.project_slug}}", ".file_with_dot.txt") \ .write_text("updated content") new_template_file_with_dot_at_start = cookiecutter_template_directory.joinpath( "{{cookiecutter.project_slug}}", ".travis.yml") new_template_file_with_dot_at_start.touch() new_template_file_with_dot_at_start.write_text("new file text") subprocess.run(["git", "add", "-A"], cwd=str(cookiecutter_template_directory), check=True) subprocess.run(["git", "commit", "-m", "updated readme"], cwd=str(cookiecutter_template_directory), check=True) context['_template'] = str(cookiecutter_template_directory) update_project_template_branch(context, str(project_directory), "cookiecutter-template", "master", merge_now=None, push_template_branch_changes=False, exclude_pathspecs=(), interactive=False) subprocess.run(["git", "merge", "cookiecutter-template"], cwd=str(project_directory), check=True) readme = project_directory.joinpath("README.rst").read_text( encoding="utf-8") assert readme == "updated readme" assert project_directory.joinpath(".file_with_dot.txt").read_text( encoding="utf-8") == "updated content" project_new_file = project_directory.joinpath(".travis.yml") assert project_new_file.exists() assert project_new_file.read_text(encoding="utf-8") == "new file text"
def test_change_project_slug(cookiecutter_template_directory: Path, cookies: Cookies): result: Result = cookies.bake( extra_context=SAMPLE_CONTEXT, template=str(cookiecutter_template_directory)) if result.exception is not None: raise result.exception project_directory = Path(result.project) _initialize_git_repo(project_directory) subprocess.run(["git", "add", "-A"], cwd=str(project_directory), check=True) subprocess.run(["git", "commit", "-m", "initial"], cwd=str(project_directory), check=True) context = json.loads( project_directory.joinpath( "docs", "cookiecutter_input.json").read_text(encoding="utf-8")) cookiecutter_template_directory.joinpath( "{{cookiecutter.project_slug}}", "README.rst").write_text("updated readme") subprocess.run(["git", "add", "-A"], cwd=str(cookiecutter_template_directory), check=True) subprocess.run(["git", "commit", "-m", "updated readme"], cwd=str(cookiecutter_template_directory), check=True) context['_template'] = str(cookiecutter_template_directory) context['project_name'] = "My New Name For Project" old_project_slug = context['project_slug'] new_project_slug = "my_new_name_for_project" context['project_slug'] = new_project_slug update_project_template_branch(context, str(project_directory), "cookiecutter-template", "master", merge_now=True, push_template_branch_changes=False, exclude_pathspecs=(), interactive=False) readme = project_directory.joinpath("README.rst").read_text( encoding="utf-8") assert readme == "updated readme" assert project_directory.joinpath(new_project_slug).is_dir() assert not project_directory.joinpath(old_project_slug).exists()
def test_changes_from_zip_file(cookiecutter_template_directory: Path, cookies: Cookies): result: Result = cookies.bake( extra_context=SAMPLE_CONTEXT, template=str(cookiecutter_template_directory)) if result.exception is not None: raise result.exception project_directory = Path(result.project) _initialize_git_repo(project_directory) subprocess.run(["git", "add", "-A"], cwd=str(project_directory), check=True) subprocess.run(["git", "commit", "-m", "initial"], cwd=str(project_directory), check=True) context = json.loads( project_directory.joinpath( "docs", "cookiecutter_input.json").read_text(encoding="utf-8")) cookiecutter_template_directory.joinpath( "{{cookiecutter.project_slug}}", "README.rst").write_text("updated readme for zip test") subprocess.run(["git", "add", "-A"], cwd=str(cookiecutter_template_directory), check=True) subprocess.run(["git", "commit", "-m", "updated readme for zip test"], cwd=str(cookiecutter_template_directory), check=True) # Pack dummy template to zip file zipfile_path = '' with CreateTempDirectory("testzip") as testdir: zipfile_path = str( testdir.joinpath( basename(cookiecutter_template_directory) + ".zip")) with ZipFile(str(zipfile_path), 'w', ZIP_DEFLATED) as zip: # this line is needed for cookiecutter zip verification zip.write(cookiecutter_template_directory, str(basename(cookiecutter_template_directory))) for folderName, subfolders, filenames in os.walk( cookiecutter_template_directory): for filename in filenames: filePath = os.path.join(folderName, filename) zip.write( filePath, str(filePath).replace( str(cookiecutter_template_directory), basename(str(cookiecutter_template_directory)))) context['_template'] = str(zipfile_path) update_project_template_branch(context, str(project_directory), "cookiecutter-template", "master", merge_now=True, push_template_branch_changes=False, exclude_pathspecs=(), interactive=False) readme = project_directory.joinpath("README.rst").read_text( encoding="utf-8") assert readme == "updated readme for zip test"