diff --git a/src/fava/cli.py b/src/fava/cli.py index 5ade5ddf8..6d9b45594 100644 --- a/src/fava/cli.py +++ b/src/fava/cli.py @@ -18,7 +18,7 @@ class AddressInUse(click.ClickException): # noqa: D101 - def __init__(self, port: int) -> None: + def __init__(self, port: int) -> None: # pragma: no cover super().__init__( f"Cannot start Fava because port {port} is already in use." "\nPlease choose a different port with the '-p' option.", @@ -33,7 +33,7 @@ def __init__(self, path: str) -> None: class NoFileSpecifiedError(click.UsageError): # noqa: D101 - def __init__(self) -> None: + def __init__(self) -> None: # pragma: no cover super().__init__("No file specified") diff --git a/tests/test_cli.py b/tests/test_cli.py index b502d1240..c670ef171 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,6 +1,8 @@ from __future__ import annotations +import os import sys +from pathlib import Path from socket import socket from subprocess import PIPE from subprocess import Popen @@ -11,11 +13,35 @@ import pytest +from fava.cli import _add_env_filenames +from fava.cli import NonAbsolutePathError + if TYPE_CHECKING: # pragma: no cover - from pathlib import Path from typing import IO +def test__add_env_filenames( + monkeypatch: pytest.MonkeyPatch, +) -> None: + absolute_path = Path.cwd().resolve() + absolute = str(absolute_path) + asdf = str(absolute_path / "asdf") + other = str(absolute_path / "other") + + monkeypatch.delenv("BEANCOUNT_FILE", raising=False) + assert _add_env_filenames((asdf,)) == {asdf} + + monkeypatch.setenv("BEANCOUNT_FILE", "path") + with pytest.raises(NonAbsolutePathError): + _add_env_filenames((asdf,)) + + monkeypatch.setenv("BEANCOUNT_FILE", absolute) + assert _add_env_filenames((asdf,)) == {absolute, asdf} + + monkeypatch.setenv("BEANCOUNT_FILE", os.pathsep.join([absolute, other])) + assert _add_env_filenames((asdf,)) == {absolute, other, asdf} + + @pytest.fixture() def open_port() -> int: """Get an open port.""" @@ -40,6 +66,7 @@ def output_contains(stdout: IO[str], output: str) -> bool: @pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows") +@pytest.mark.no_cover() def test_cli( monkeypatch: pytest.MonkeyPatch, test_data_dir: Path,