mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-22 09:36:52 +03:00
Fix carriage return in .gitignore
on Windows (#3456)
This commit is contained in:
parent
4ba33fa353
commit
ce1c76e34e
26
.github/workflows/ci.yml
vendored
26
.github/workflows/ci.yml
vendored
|
@ -16,9 +16,17 @@ jobs:
|
||||||
- name: Run pre-commit
|
- name: Run pre-commit
|
||||||
uses: pre-commit/action@v2.0.3
|
uses: pre-commit/action@v2.0.3
|
||||||
|
|
||||||
tox:
|
tests:
|
||||||
runs-on: ubuntu-latest
|
strategy:
|
||||||
name: "Test with tox"
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os:
|
||||||
|
- ubuntu-latest
|
||||||
|
- windows-latest
|
||||||
|
- macOS-latest
|
||||||
|
|
||||||
|
name: "Run tests"
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v2
|
||||||
|
@ -26,14 +34,11 @@ jobs:
|
||||||
python-version: "3.9"
|
python-version: "3.9"
|
||||||
cache: pip
|
cache: pip
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: pip install -r requirements.txt
|
||||||
python -m pip install -U pip
|
- name: Run tests
|
||||||
python -m pip install -U tox
|
run: pytest tests
|
||||||
- name: Run tox
|
|
||||||
run: tox -e py39
|
|
||||||
|
|
||||||
docker:
|
docker:
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
|
@ -44,6 +49,7 @@ jobs:
|
||||||
args: "use_celery=y use_drf=y js_task_runner=Gulp"
|
args: "use_celery=y use_drf=y js_task_runner=Gulp"
|
||||||
|
|
||||||
name: "${{ matrix.script.name }} Docker"
|
name: "${{ matrix.script.name }} Docker"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
DOCKER_BUILDKIT: 1
|
DOCKER_BUILDKIT: 1
|
||||||
COMPOSE_DOCKER_CLI_BUILD: 1
|
COMPOSE_DOCKER_CLI_BUILD: 1
|
||||||
|
@ -58,7 +64,6 @@ jobs:
|
||||||
run: sh tests/test_docker.sh ${{ matrix.script.args }}
|
run: sh tests/test_docker.sh ${{ matrix.script.args }}
|
||||||
|
|
||||||
bare:
|
bare:
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
|
@ -68,6 +73,7 @@ jobs:
|
||||||
- name: With Gulp
|
- name: With Gulp
|
||||||
args: "js_task_runner=Gulp custom_bootstrap_compilation=y"
|
args: "js_task_runner=Gulp custom_bootstrap_compilation=y"
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
name: "${{ matrix.script.name }} Bare metal"
|
name: "${{ matrix.script.name }} Bare metal"
|
||||||
services:
|
services:
|
||||||
redis:
|
redis:
|
||||||
|
|
|
@ -139,13 +139,6 @@ def remove_dotgithub_folder():
|
||||||
shutil.rmtree(".github")
|
shutil.rmtree(".github")
|
||||||
|
|
||||||
|
|
||||||
def append_to_project_gitignore(path):
|
|
||||||
gitignore_file_path = ".gitignore"
|
|
||||||
with open(gitignore_file_path, "a") as gitignore_file:
|
|
||||||
gitignore_file.write(path)
|
|
||||||
gitignore_file.write(os.linesep)
|
|
||||||
|
|
||||||
|
|
||||||
def generate_random_string(
|
def generate_random_string(
|
||||||
length, using_digits=False, using_ascii_letters=False, using_punctuation=False
|
length, using_digits=False, using_ascii_letters=False, using_punctuation=False
|
||||||
):
|
):
|
||||||
|
@ -260,10 +253,10 @@ def set_celery_flower_password(file_path, value=None):
|
||||||
return celery_flower_password
|
return celery_flower_password
|
||||||
|
|
||||||
|
|
||||||
def append_to_gitignore_file(s):
|
def append_to_gitignore_file(ignored_line):
|
||||||
with open(".gitignore", "a") as gitignore_file:
|
with open(".gitignore", "a") as gitignore_file:
|
||||||
gitignore_file.write(s)
|
gitignore_file.write(ignored_line)
|
||||||
gitignore_file.write(os.linesep)
|
gitignore_file.write("\n")
|
||||||
|
|
||||||
|
|
||||||
def set_flags_in_envs(postgres_user, celery_flower_user, debug=False):
|
def set_flags_in_envs(postgres_user, celery_flower_user, debug=False):
|
||||||
|
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
|
@ -1,14 +1,20 @@
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
try:
|
||||||
import sh
|
import sh
|
||||||
|
except (ImportError, ModuleNotFoundError):
|
||||||
|
sh = None # sh doesn't support Windows
|
||||||
import yaml
|
import yaml
|
||||||
from binaryornot.check import is_binary
|
from binaryornot.check import is_binary
|
||||||
from cookiecutter.exceptions import FailedHookException
|
from cookiecutter.exceptions import FailedHookException
|
||||||
|
|
||||||
PATTERN = r"{{(\s?cookiecutter)[.](.*?)}}"
|
PATTERN = r"{{(\s?cookiecutter)[.](.*?)}}"
|
||||||
RE_OBJ = re.compile(PATTERN)
|
RE_OBJ = re.compile(PATTERN)
|
||||||
|
IS_WINDOWS = sys.platform.startswith("win")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -111,7 +117,7 @@ UNSUPPORTED_COMBINATIONS = [
|
||||||
|
|
||||||
|
|
||||||
def _fixture_id(ctx):
|
def _fixture_id(ctx):
|
||||||
"""Helper to get a user friendly test name from the parametrized context."""
|
"""Helper to get a user-friendly test name from the parametrized context."""
|
||||||
return "-".join(f"{key}:{value}" for key, value in ctx.items())
|
return "-".join(f"{key}:{value}" for key, value in ctx.items())
|
||||||
|
|
||||||
|
|
||||||
|
@ -151,6 +157,7 @@ def test_project_generation(cookies, context, context_override):
|
||||||
check_paths(paths)
|
check_paths(paths)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(IS_WINDOWS, reason="sh doesn't support windows")
|
||||||
@pytest.mark.parametrize("context_override", SUPPORTED_COMBINATIONS, ids=_fixture_id)
|
@pytest.mark.parametrize("context_override", SUPPORTED_COMBINATIONS, ids=_fixture_id)
|
||||||
def test_flake8_passes(cookies, context_override):
|
def test_flake8_passes(cookies, context_override):
|
||||||
"""Generated project should pass flake8."""
|
"""Generated project should pass flake8."""
|
||||||
|
@ -162,6 +169,7 @@ def test_flake8_passes(cookies, context_override):
|
||||||
pytest.fail(e.stdout.decode())
|
pytest.fail(e.stdout.decode())
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(IS_WINDOWS, reason="sh doesn't support windows")
|
||||||
@pytest.mark.parametrize("context_override", SUPPORTED_COMBINATIONS, ids=_fixture_id)
|
@pytest.mark.parametrize("context_override", SUPPORTED_COMBINATIONS, ids=_fixture_id)
|
||||||
def test_black_passes(cookies, context_override):
|
def test_black_passes(cookies, context_override):
|
||||||
"""Generated project should pass black."""
|
"""Generated project should pass black."""
|
||||||
|
@ -265,7 +273,7 @@ def test_github_invokes_linter_and_pytest(
|
||||||
|
|
||||||
@pytest.mark.parametrize("slug", ["project slug", "Project_Slug"])
|
@pytest.mark.parametrize("slug", ["project slug", "Project_Slug"])
|
||||||
def test_invalid_slug(cookies, context, slug):
|
def test_invalid_slug(cookies, context, slug):
|
||||||
"""Invalid slug should failed pre-generation hook."""
|
"""Invalid slug should fail pre-generation hook."""
|
||||||
context.update({"project_slug": slug})
|
context.update({"project_slug": slug})
|
||||||
|
|
||||||
result = cookies.bake(extra_context=context)
|
result = cookies.bake(extra_context=context)
|
||||||
|
|
28
tests/test_hooks.py
Normal file
28
tests/test_hooks.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
"""Unit tests for the hooks"""
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from hooks.post_gen_project import append_to_gitignore_file
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def working_directory(tmp_path):
|
||||||
|
prev_cwd = Path.cwd()
|
||||||
|
os.chdir(tmp_path)
|
||||||
|
try:
|
||||||
|
yield tmp_path
|
||||||
|
finally:
|
||||||
|
os.chdir(prev_cwd)
|
||||||
|
|
||||||
|
|
||||||
|
def test_append_to_gitignore_file(working_directory):
|
||||||
|
gitignore_file = working_directory / ".gitignore"
|
||||||
|
gitignore_file.write_text("node_modules/\n")
|
||||||
|
append_to_gitignore_file(".envs/*")
|
||||||
|
linesep = os.linesep.encode()
|
||||||
|
assert (
|
||||||
|
gitignore_file.read_bytes() == b"node_modules/" + linesep + b".envs/*" + linesep
|
||||||
|
)
|
||||||
|
assert gitignore_file.read_text() == "node_modules/\n.envs/*\n"
|
Loading…
Reference in New Issue
Block a user