2021-12-16 14:07:47 +03:00
|
|
|
"""Unit tests for the hooks"""
|
2024-01-26 13:49:52 +03:00
|
|
|
|
2021-12-16 14:07:47 +03:00
|
|
|
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()
|
2023-04-15 17:43:04 +03:00
|
|
|
assert gitignore_file.read_bytes() == b"node_modules/" + linesep + b".envs/*" + linesep
|
2021-12-16 14:07:47 +03:00
|
|
|
assert gitignore_file.read_text() == "node_modules/\n.envs/*\n"
|