mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-08-15 09:24:52 +03:00
Rewrite test to be dumber
This commit is contained in:
parent
44f9e1ab08
commit
d1b0aa86ef
|
@ -30,30 +30,54 @@ def main():
|
||||||
merge(DOTENV_FILE, PRODUCTION_DOTENV_FILES)
|
merge(DOTENV_FILE, PRODUCTION_DOTENV_FILES)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("files_count", range(3))
|
@pytest.mark.parametrize(
|
||||||
@pytest.mark.parametrize("append_linesep", [True, False])
|
("input_contents", "append_linesep", "expected_output"),
|
||||||
def test_merge(tmp_path: Path, files_count: int, append_linesep: bool):
|
[
|
||||||
|
# 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"
|
output_file = tmp_path / ".env"
|
||||||
|
|
||||||
expected_output_file_content = ""
|
|
||||||
files_to_merge = []
|
files_to_merge = []
|
||||||
for num in range(1, files_count + 1):
|
for num, input_content in enumerate(input_contents, start=1):
|
||||||
merge_filename = f".service{num}"
|
merge_file = tmp_path / f".service{num}"
|
||||||
merge_file = tmp_path / merge_filename
|
merge_file.write_text(input_content)
|
||||||
|
|
||||||
merge_file_content = merge_filename * num
|
|
||||||
merge_file.write_text(merge_file_content)
|
|
||||||
|
|
||||||
expected_output_file_content += merge_file_content
|
|
||||||
if append_linesep:
|
|
||||||
expected_output_file_content += os.linesep
|
|
||||||
|
|
||||||
files_to_merge.append(merge_file)
|
files_to_merge.append(merge_file)
|
||||||
|
|
||||||
merge(output_file, files_to_merge, append_linesep)
|
merge(output_file, files_to_merge, append_linesep)
|
||||||
|
|
||||||
actual_output_file_content = output_file.read_text()
|
assert output_file.read_text() == expected_output
|
||||||
assert actual_output_file_content == expected_output_file_content
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue
Block a user