diff --git a/src/obsidian_metadata/_utils/utilities.py b/src/obsidian_metadata/_utils/utilities.py index ce7cb8d..8bedcf8 100644 --- a/src/obsidian_metadata/_utils/utilities.py +++ b/src/obsidian_metadata/_utils/utilities.py @@ -132,7 +132,7 @@ def clean_dictionary(dictionary: dict[str, Any]) -> dict[str, Any]: return new_dict -def clear_screen() -> None: +def clear_screen() -> None: # pragma: no cover """Clears the screen.""" # for windows _ = system("cls") if name == "nt" else system("clear") diff --git a/src/obsidian_metadata/models/application.py b/src/obsidian_metadata/models/application.py index 52bf715..de25aa0 100644 --- a/src/obsidian_metadata/models/application.py +++ b/src/obsidian_metadata/models/application.py @@ -34,8 +34,6 @@ class Application: ] ) - clear_screen() - def load_vault(self, path_filter: str = None) -> None: """Load the vault. @@ -47,6 +45,7 @@ class Application: def main_app(self) -> None: # noqa: C901 """Questions for the main application.""" + clear_screen() self.load_vault() while True: diff --git a/src/obsidian_metadata/models/vault.py b/src/obsidian_metadata/models/vault.py index b951e5b..dbe99bf 100644 --- a/src/obsidian_metadata/models/vault.py +++ b/src/obsidian_metadata/models/vault.py @@ -53,7 +53,7 @@ class Vault: self.metadata.add_metadata(_note.inline_metadata.dict) self.metadata.add_metadata({_note.inline_tags.metadata_key: _note.inline_tags.list}) - def __rich_repr__(self) -> rich.repr.Result: + def __rich_repr__(self) -> rich.repr.Result: # pragma: no cover """Define rich representation of Vault.""" yield "vault_path", self.vault_path yield "dry_run", self.dry_run diff --git a/tests/application_test.py b/tests/application_test.py new file mode 100644 index 0000000..6f528ea --- /dev/null +++ b/tests/application_test.py @@ -0,0 +1,18 @@ +# type: ignore +"""Tests for the application module.""" + + +from obsidian_metadata._config import Config +from obsidian_metadata.models.application import Application + + +def test_load_vault(test_vault) -> None: + """Test application.""" + vault_path = test_vault + config = Config(config_path="tests/fixtures/test_vault_config.toml", vault_path=vault_path) + app = Application(config=config, dry_run=False) + app.load_vault() + + assert app.dry_run is False + assert app.config == config + assert app.vault.num_notes() == 2 diff --git a/tests/cli_test.py b/tests/cli_test.py index e00c8f1..d645bbc 100644 --- a/tests/cli_test.py +++ b/tests/cli_test.py @@ -4,7 +4,8 @@ from typer.testing import CliRunner from obsidian_metadata.cli import app -from tests.helpers import Regex + +from .helpers import KeyInputs, Regex # noqa: F401 runner = CliRunner() @@ -14,3 +15,29 @@ def test_version() -> None: result = runner.invoke(app, ["--version"]) assert result.exit_code == 0 assert result.output == Regex(r"obsidian_metadata: v\d+\.\d+\.\d+$") + + +def test_application(test_vault, tmp_path) -> None: + """Test the application.""" + vault_path = test_vault + config_path = tmp_path / "config.toml" + result = runner.invoke( + app, + ["--vault-path", vault_path, "--config-file", config_path], + # input=KeyInputs.DOWN + KeyInputs.DOWN + KeyInputs.DOWN + KeyInputs.ENTER, # noqa: ERA001 + ) + + banner = r""" + ___ _ _ _ _ + / _ \| |__ ___(_) __| (_) __ _ _ __ + | | | | '_ \/ __| |/ _` | |/ _` | '_ \ + | |_| | |_) \__ \ | (_| | | (_| | | | | + \___/|_.__/|___/_|\__,_|_|\__,_|_| |_| + | \/ | ___| |_ __ _ __| | __ _| |_ __ _ + | |\/| |/ _ \ __/ _` |/ _` |/ _` | __/ _` | + | | | | __/ || (_| | (_| | (_| | || (_| | + |_| |_|\___|\__\__,_|\__,_|\__,_|\__\__,_| +""" + + assert banner in result.output + assert result.exit_code == 1 diff --git a/tests/helpers.py b/tests/helpers.py index e574401..7812284 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -4,6 +4,24 @@ import re +class KeyInputs: + """Key inputs for testing.""" + + DOWN = "\x1b[B" + UP = "\x1b[A" + LEFT = "\x1b[D" + RIGHT = "\x1b[C" + ENTER = "\r" + ESCAPE = "\x1b" + CONTROLC = "\x03" + BACK = "\x7f" + SPACE = " " + TAB = "\x09" + ONE = "1" + TWO = "2" + THREE = "3" + + class Regex: """Assert that a given string meets some expectations.