Rename a few variables to be consistent with elsewhere

This commit is contained in:
Bruno Alla 2023-01-25 22:59:30 +00:00
parent 099e49b728
commit c2c10bd65a
No known key found for this signature in database

View File

@ -5,19 +5,21 @@ from pathlib import Path
import pytest import pytest
BASE_DIR = Path(__file__).parent.resolve() BASE_DIR = Path(__file__).parent.resolve()
PRODUCTION_DOTENVS_DIR_PATH = BASE_DIR / ".envs" / ".production" PRODUCTION_DOTENVS_DIR = BASE_DIR / ".envs" / ".production"
PRODUCTION_DOTENV_FILE_PATHS = [ PRODUCTION_DOTENV_FILES = [
PRODUCTION_DOTENVS_DIR_PATH / ".django", PRODUCTION_DOTENVS_DIR / ".django",
PRODUCTION_DOTENVS_DIR_PATH / ".postgres", PRODUCTION_DOTENVS_DIR / ".postgres",
] ]
DOTENV_FILE_PATH = BASE_DIR / ".env" DOTENV_FILE = BASE_DIR / ".env"
def merge( def merge(
output_file_path: str, merged_file_paths: Sequence[str], append_linesep: bool = True output_file: Path,
merged_files: Sequence[Path],
append_linesep: bool = True,
) -> None: ) -> None:
with open(output_file_path, "w") as output_file: with open(output_file, "w") as output_file:
for merged_file_path in merged_file_paths: for merged_file_path in merged_files:
with open(merged_file_path) as merged_file: with open(merged_file_path) as merged_file:
merged_file_content = merged_file.read() merged_file_content = merged_file.read()
output_file.write(merged_file_content) output_file.write(merged_file_content)
@ -26,38 +28,38 @@ def merge(
def main(): def main():
merge(DOTENV_FILE_PATH, PRODUCTION_DOTENV_FILE_PATHS) merge(DOTENV_FILE, PRODUCTION_DOTENV_FILES)
@pytest.mark.parametrize("merged_file_count", range(3)) @pytest.mark.parametrize("merged_file_count", range(3))
@pytest.mark.parametrize("append_linesep", [True, False]) @pytest.mark.parametrize("append_linesep", [True, False])
def test_merge(tmpdir_factory, merged_file_count: int, append_linesep: bool): def test_merge(tmpdir_factory, merged_file_count: int, append_linesep: bool):
tmp_dir_path = Path(str(tmpdir_factory.getbasetemp())) tmp_dir = Path(str(tmpdir_factory.getbasetemp()))
output_file_path = tmp_dir_path / ".env" output_file = tmp_dir / ".env"
expected_output_file_content = "" expected_output_file_content = ""
merged_file_paths = [] merged_files = []
for i in range(merged_file_count): for i in range(merged_file_count):
merged_file_ord = i + 1 merged_file_ord = i + 1
merged_filename = f".service{merged_file_ord}" merged_filename = f".service{merged_file_ord}"
merged_file_path = tmp_dir_path / merged_filename merged_file = tmp_dir / merged_filename
merged_file_content = merged_filename * merged_file_ord merged_file_content = merged_filename * merged_file_ord
with open(merged_file_path, "w+") as file: with open(merged_file, "w+") as file:
file.write(merged_file_content) file.write(merged_file_content)
expected_output_file_content += merged_file_content expected_output_file_content += merged_file_content
if append_linesep: if append_linesep:
expected_output_file_content += os.linesep expected_output_file_content += os.linesep
merged_file_paths.append(merged_file_path) merged_files.append(merged_file)
merge(output_file_path, merged_file_paths, append_linesep) merge(output_file, merged_files, append_linesep)
with open(output_file_path) as output_file: with open(output_file) as output_file:
actual_output_file_content = output_file.read() actual_output_file_content = output_file.read()
assert actual_output_file_content == expected_output_file_content assert actual_output_file_content == expected_output_file_content