This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
from slic.utils.dotdir import *
|
||||
|
||||
@pytest.fixture
|
||||
def patch_home(monkeypatch, tmp_path):
|
||||
# Temporarily replace Path.home() with a temporary directory to avoid modifying the real user home during tests
|
||||
monkeypatch.setattr("pathlib.Path.home", lambda: tmp_path)
|
||||
return tmp_path # provide tmp_path for use inside tests
|
||||
|
||||
# test (__init__)
|
||||
def test_dotdir_creation_and_base_exists(patch_home):
|
||||
# Instantiate DotDir with a folder name
|
||||
dotdir = DotDir(".testfolder")
|
||||
|
||||
# Assert that the base path is tmp_path/.testfolder
|
||||
assert dotdir.base == patch_home / ".testfolder"
|
||||
|
||||
# Assert that the directory was physically created on disk
|
||||
assert dotdir.base.exists()
|
||||
|
||||
# Assert that the path is indeed a directory, not a file
|
||||
assert dotdir.base.is_dir()
|
||||
|
||||
# test (__repr__)
|
||||
def test_dotdir_repr_returns_path_str(patch_home):
|
||||
dotdir = DotDir(".testfolder")
|
||||
|
||||
# Assert that __repr__ returns the string version of the good base path
|
||||
assert repr(dotdir) == str(dotdir.base)
|
||||
|
||||
# test (__call__)
|
||||
def test_dotdir_call(patch_home):
|
||||
dotdir = DotDir(".testfolder")
|
||||
child_name = "config.yaml"
|
||||
|
||||
# Call the DotDir instance with a filename to get full child path
|
||||
child_path = dotdir(child_name)
|
||||
|
||||
# Assert the returned path matches base path joined with child name
|
||||
assert child_path == dotdir.base / child_name
|
||||
Reference in New Issue
Block a user