mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-08-15 09:24:52 +03:00
Move tests outside of the script
This commit is contained in:
parent
d1b0aa86ef
commit
437e09a7cf
|
@ -293,6 +293,7 @@ def set_flags_in_settings_files():
|
||||||
def remove_envs_and_associated_files():
|
def remove_envs_and_associated_files():
|
||||||
shutil.rmtree(".envs")
|
shutil.rmtree(".envs")
|
||||||
os.remove("merge_production_dotenvs_in_dotenv.py")
|
os.remove("merge_production_dotenvs_in_dotenv.py")
|
||||||
|
shutil.rmtree("tests")
|
||||||
|
|
||||||
|
|
||||||
def remove_celery_compose_dirs():
|
def remove_celery_compose_dirs():
|
||||||
|
|
|
@ -2,8 +2,6 @@ import os
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
BASE_DIR = Path(__file__).parent.resolve()
|
BASE_DIR = Path(__file__).parent.resolve()
|
||||||
PRODUCTION_DOTENVS_DIR = BASE_DIR / ".envs" / ".production"
|
PRODUCTION_DOTENVS_DIR = BASE_DIR / ".envs" / ".production"
|
||||||
PRODUCTION_DOTENV_FILES = [
|
PRODUCTION_DOTENV_FILES = [
|
||||||
|
@ -30,55 +28,5 @@ def main():
|
||||||
merge(DOTENV_FILE, PRODUCTION_DOTENV_FILES)
|
merge(DOTENV_FILE, PRODUCTION_DOTENV_FILES)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
("input_contents", "append_linesep", "expected_output"),
|
|
||||||
[
|
|
||||||
# No line separator
|
|
||||||
([], False, ""),
|
|
||||||
([""], False, ""),
|
|
||||||
(["\n"], False, "\n"),
|
|
||||||
(["TEST=1"], False, "TEST=1"),
|
|
||||||
(["THIS=2", "THAT='example'"], False, "THIS=2THAT='example'"),
|
|
||||||
(["ONE=1\n", "TWO=2"], False, "ONE=1\nTWO=2"),
|
|
||||||
(["A=0", "B=1", "C=2"], False, "A=0B=1C=2"),
|
|
||||||
# With line separator
|
|
||||||
(
|
|
||||||
[],
|
|
||||||
True,
|
|
||||||
"",
|
|
||||||
),
|
|
||||||
(
|
|
||||||
[""],
|
|
||||||
True,
|
|
||||||
"\n",
|
|
||||||
),
|
|
||||||
(
|
|
||||||
["JANE=doe"],
|
|
||||||
True,
|
|
||||||
"JANE=doe\n",
|
|
||||||
),
|
|
||||||
(["SEP=true", "AR=ator"], True, "SEP=true\nAR=ator\n"),
|
|
||||||
(["X=x\n", "Y=y", "Z=z\n"], True, "X=x\n\nY=y\nZ=z\n\n"),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_merge(
|
|
||||||
tmp_path: Path,
|
|
||||||
input_contents: list[str],
|
|
||||||
append_linesep: bool,
|
|
||||||
expected_output: str,
|
|
||||||
):
|
|
||||||
output_file = tmp_path / ".env"
|
|
||||||
|
|
||||||
files_to_merge = []
|
|
||||||
for num, input_content in enumerate(input_contents, start=1):
|
|
||||||
merge_file = tmp_path / f".service{num}"
|
|
||||||
merge_file.write_text(input_content)
|
|
||||||
files_to_merge.append(merge_file)
|
|
||||||
|
|
||||||
merge(output_file, files_to_merge, append_linesep)
|
|
||||||
|
|
||||||
assert output_file.read_text() == expected_output
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from merge_production_dotenvs_in_dotenv import merge
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("input_contents", "append_linesep", "expected_output"),
|
||||||
|
[
|
||||||
|
# No line separator
|
||||||
|
([], False, ""),
|
||||||
|
([""], False, ""),
|
||||||
|
(["\n"], False, "\n"),
|
||||||
|
(["TEST=1"], False, "TEST=1"),
|
||||||
|
(["THIS=2", "THAT='example'"], False, "THIS=2THAT='example'"),
|
||||||
|
(["ONE=1\n", "TWO=2"], False, "ONE=1\nTWO=2"),
|
||||||
|
(["A=0", "B=1", "C=2"], False, "A=0B=1C=2"),
|
||||||
|
# With line separator
|
||||||
|
([], True, ""),
|
||||||
|
([""], True, "\n"),
|
||||||
|
(["JANE=doe"], True, "JANE=doe\n"),
|
||||||
|
(["SEP=true", "AR=ator"], True, "SEP=true\nAR=ator\n"),
|
||||||
|
(["X=x\n", "Y=y", "Z=z\n"], True, "X=x\n\nY=y\nZ=z\n\n"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_merge(
|
||||||
|
tmp_path: Path,
|
||||||
|
input_contents: list[str],
|
||||||
|
append_linesep: bool,
|
||||||
|
expected_output: str,
|
||||||
|
):
|
||||||
|
output_file = tmp_path / ".env"
|
||||||
|
|
||||||
|
files_to_merge = []
|
||||||
|
for num, input_content in enumerate(input_contents, start=1):
|
||||||
|
merge_file = tmp_path / f".service{num}"
|
||||||
|
merge_file.write_text(input_content)
|
||||||
|
files_to_merge.append(merge_file)
|
||||||
|
|
||||||
|
merge(output_file, files_to_merge, append_linesep)
|
||||||
|
|
||||||
|
assert output_file.read_text() == expected_output
|
Loading…
Reference in New Issue
Block a user