mirror of
https://github.com/natelandau/obsidian-metadata.git
synced 2025-11-17 01:13:39 -05:00
refactor(application): refactor questions to separate class (#7)
* refactor(application): refactor questions to separate class * test(application): add tests for`Application` class
This commit is contained in:
@@ -6,6 +6,9 @@ from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from obsidian_metadata._config import Config
|
||||
from obsidian_metadata.models.application import Application
|
||||
|
||||
|
||||
def remove_all(root: Path):
|
||||
"""Remove all files and directories in a directory."""
|
||||
@@ -72,3 +75,27 @@ def test_vault(tmp_path) -> Path:
|
||||
|
||||
if backup_dir.exists():
|
||||
shutil.rmtree(backup_dir)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def test_application(tmp_path) -> Application:
|
||||
"""Fixture which creates a sample vault."""
|
||||
source_dir = Path(__file__).parent / "fixtures" / "sample_vault"
|
||||
dest_dir = Path(tmp_path / "application")
|
||||
backup_dir = Path(f"{dest_dir}.bak")
|
||||
|
||||
if not source_dir.exists():
|
||||
raise FileNotFoundError(f"Sample vault not found: {source_dir}")
|
||||
|
||||
shutil.copytree(source_dir, dest_dir)
|
||||
config = Config(config_path="tests/fixtures/test_vault_config.toml", vault_path=dest_dir)
|
||||
vault_config = config.vaults[0]
|
||||
app = Application(config=vault_config, dry_run=False)
|
||||
|
||||
yield app
|
||||
|
||||
# after test - remove fixtures
|
||||
shutil.rmtree(dest_dir)
|
||||
|
||||
if backup_dir.exists():
|
||||
shutil.rmtree(backup_dir)
|
||||
|
||||
Reference in New Issue
Block a user