tests: remove pyfakefs due to issues with pathlib and sqlite in favor of a simple tempfolder where to store test files

This commit is contained in:
cătălin 2023-11-29 18:42:30 +01:00
commit c6d361f649
Signed by: catalin
GPG key ID: 0178DF42F43E5FD2
6 changed files with 45 additions and 29 deletions

View file

@ -41,11 +41,26 @@ def ssh_recipient(halig_ssh_public_key: str) -> Recipient:
return Recipient.from_str(halig_ssh_public_key)
# @pytest.fixture()
# def halig_path(fs, halig_ssh_public_key, halig_ssh_private_key) -> Path:
# fs.add_real_paths(["/etc/localtime"])
# ssh_path = Path("~/.ssh").expanduser()
# ssh_path.mkdir(parents=True)
#
# with (ssh_path / "id_ed25519").open("w") as f:
# f.write(halig_ssh_private_key)
#
# with (ssh_path / "id_ed25519.pub").open("w") as f:
# f.write(halig_ssh_public_key)
#
# halig_path = Path("~/.config/halig").expanduser()
# halig_path.mkdir(parents=True)
# return halig_path
@pytest.fixture()
def halig_path(fs, halig_ssh_public_key, halig_ssh_private_key) -> Path:
fs.add_real_paths(["/etc/localtime"])
ssh_path = Path("~/.ssh").expanduser()
ssh_path.mkdir(parents=True)
def halig_ssh_path(tmp_path: Path, halig_ssh_public_key, halig_ssh_private_key) -> Path:
ssh_path = tmp_path / ".ssh"
ssh_path.mkdir()
with (ssh_path / "id_ed25519").open("w") as f:
f.write(halig_ssh_private_key)
@ -53,26 +68,35 @@ def halig_path(fs, halig_ssh_public_key, halig_ssh_private_key) -> Path:
with (ssh_path / "id_ed25519.pub").open("w") as f:
f.write(halig_ssh_public_key)
halig_path = Path("~/.config/halig").expanduser()
return ssh_path
@pytest.fixture()
def halig_config_path(tmp_path: Path):
halig_path = tmp_path / ".config/halig"
halig_path.mkdir(parents=True)
return halig_path
@pytest.fixture()
def notebooks_path(halig_path) -> Path:
notebooks_path = Path("~/Notebooks").expanduser()
notebooks_path.mkdir(parents=True)
def notebooks_path(tmp_path) -> Path:
notebooks_path = tmp_path / "Notebooks"
notebooks_path.mkdir()
return notebooks_path
@pytest.fixture()
def settings(notebooks_path: Path) -> Settings:
return Settings(notebooks_root_path=notebooks_path)
def settings(notebooks_path: Path, halig_ssh_path) -> Settings:
return Settings(
notebooks_root_path=notebooks_path,
identity_paths=[halig_ssh_path / "id_ed25519"],
recipient_paths=[halig_ssh_path / "id_ed25519.pub"]
)
@pytest.fixture()
def settings_file_path(halig_path: Path, notebooks_path: Path) -> Path:
yaml_file = halig_path / "halig.yml"
def settings_file_path(halig_config_path: Path, notebooks_path: Path) -> Path:
yaml_file = halig_config_path / "halig.yml"
yaml_file.touch()
s = Settings(notebooks_root_path=notebooks_path)
# `.dict()` doesn't serialize some fields that yaml doesn't understand
@ -83,8 +107,8 @@ def settings_file_path(halig_path: Path, notebooks_path: Path) -> Path:
@pytest.fixture()
def empty_file_path(halig_path: Path) -> Path:
empty_path = halig_path / "empty"
def empty_file_path(halig_config_path: Path) -> Path:
empty_path = halig_config_path / "empty"
empty_path.touch()
return empty_path