mirror of
https://github.com/natelandau/obsidian-metadata.git
synced 2025-11-17 09:23:40 -05:00
feat: greatly improve capturing all formats of inline metadata (#41)
feat: greatly improve capturing metadata all formats of inline metadata
This commit is contained in:
@@ -6,87 +6,87 @@ import pytest
|
||||
|
||||
from obsidian_metadata._utils import alerts
|
||||
from obsidian_metadata._utils.alerts import logger as log
|
||||
from tests.helpers import Regex
|
||||
from tests.helpers import Regex, strip_ansi
|
||||
|
||||
|
||||
def test_dryrun(capsys):
|
||||
"""Test dry run."""
|
||||
alerts.dryrun("This prints in dry run")
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out == "DRYRUN | This prints in dry run\n"
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert captured == "DRYRUN | This prints in dry run\n"
|
||||
|
||||
|
||||
def test_success(capsys):
|
||||
"""Test success."""
|
||||
alerts.success("This prints in success")
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out == "SUCCESS | This prints in success\n"
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert captured == "SUCCESS | This prints in success\n"
|
||||
|
||||
|
||||
def test_error(capsys):
|
||||
"""Test success."""
|
||||
alerts.error("This prints in error")
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out == "ERROR | This prints in error\n"
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert captured == "ERROR | This prints in error\n"
|
||||
|
||||
|
||||
def test_warning(capsys):
|
||||
"""Test warning."""
|
||||
alerts.warning("This prints in warning")
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out == "WARNING | This prints in warning\n"
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert captured == "WARNING | This prints in warning\n"
|
||||
|
||||
|
||||
def test_notice(capsys):
|
||||
"""Test notice."""
|
||||
alerts.notice("This prints in notice")
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out == "NOTICE | This prints in notice\n"
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert captured == "NOTICE | This prints in notice\n"
|
||||
|
||||
|
||||
def test_alerts_debug(capsys):
|
||||
"""Test debug."""
|
||||
alerts.debug("This prints in debug")
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out == "DEBUG | This prints in debug\n"
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert captured == "DEBUG | This prints in debug\n"
|
||||
|
||||
|
||||
def test_usage(capsys):
|
||||
"""Test usage."""
|
||||
alerts.usage("This prints in usage")
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out == "USAGE | This prints in usage\n"
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert captured == "USAGE | This prints in usage\n"
|
||||
|
||||
alerts.usage(
|
||||
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua",
|
||||
width=80,
|
||||
)
|
||||
captured = capsys.readouterr()
|
||||
assert "USAGE | Lorem ipsum dolor sit amet" in captured.out
|
||||
assert " | incididunt ut labore et dolore magna aliqua" in captured.out
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert "USAGE | Lorem ipsum dolor sit amet" in captured
|
||||
assert " | incididunt ut labore et dolore magna aliqua" in captured
|
||||
|
||||
alerts.usage(
|
||||
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua",
|
||||
width=20,
|
||||
)
|
||||
captured = capsys.readouterr()
|
||||
assert "USAGE | Lorem ipsum dolor" in captured.out
|
||||
assert " | sit amet," in captured.out
|
||||
assert " | adipisicing elit," in captured.out
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert "USAGE | Lorem ipsum dolor" in captured
|
||||
assert " | sit amet," in captured
|
||||
assert " | adipisicing elit," in captured
|
||||
|
||||
|
||||
def test_info(capsys):
|
||||
"""Test info."""
|
||||
alerts.info("This prints in info")
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out == "INFO | This prints in info\n"
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert captured == "INFO | This prints in info\n"
|
||||
|
||||
|
||||
def test_dim(capsys):
|
||||
"""Test info."""
|
||||
alerts.dim("This prints in dim")
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out == "This prints in dim\n"
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert captured == "This prints in dim\n"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -106,74 +106,74 @@ def test_logging(capsys, tmp_path, verbosity, log_to_file) -> None:
|
||||
|
||||
if verbosity >= 3:
|
||||
assert logging.is_trace() is True
|
||||
captured = capsys.readouterr()
|
||||
assert not captured.out
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert not captured
|
||||
|
||||
assert logging.is_trace("trace text") is True
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out == "trace text\n"
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert captured == "trace text\n"
|
||||
|
||||
log.trace("This is Trace logging")
|
||||
captured = capsys.readouterr()
|
||||
assert captured.err == Regex(r"^TRACE \| This is Trace logging \([\w\._:]+:\d+\)$")
|
||||
cap_error = strip_ansi(capsys.readouterr().err)
|
||||
assert cap_error == Regex(r"^TRACE \| This is Trace logging \([\w\._:]+:\d+\)$")
|
||||
else:
|
||||
assert logging.is_trace("trace text") is False
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out != "trace text\n"
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert captured != "trace text\n"
|
||||
|
||||
log.trace("This is Trace logging")
|
||||
captured = capsys.readouterr()
|
||||
assert captured.err != Regex(r"^TRACE \| This is Trace logging \([\w\._:]+:\d+\)$")
|
||||
cap_error = strip_ansi(capsys.readouterr().err)
|
||||
assert cap_error != Regex(r"^TRACE \| This is Trace logging \([\w\._:]+:\d+\)$")
|
||||
|
||||
if verbosity >= 2:
|
||||
assert logging.is_debug() is True
|
||||
captured = capsys.readouterr()
|
||||
assert not captured.out
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert not captured
|
||||
|
||||
assert logging.is_debug("debug text") is True
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out == "debug text\n"
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert captured == "debug text\n"
|
||||
|
||||
log.debug("This is Debug logging")
|
||||
captured = capsys.readouterr()
|
||||
assert captured.err == Regex(r"^DEBUG \| This is Debug logging \([\w\._:]+:\d+\)$")
|
||||
captured = strip_ansi(capsys.readouterr().err)
|
||||
assert captured == Regex(r"^DEBUG \| This is Debug logging \([\w\._:]+:\d+\)$")
|
||||
else:
|
||||
assert logging.is_debug("debug text") is False
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out != "debug text\n"
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert captured != "debug text\n"
|
||||
|
||||
log.debug("This is Debug logging")
|
||||
captured = capsys.readouterr()
|
||||
assert captured.err != Regex(r"^DEBUG \| This is Debug logging \([\w\._:]+:\d+\)$")
|
||||
captured = strip_ansi(capsys.readouterr().err)
|
||||
assert captured != Regex(r"^DEBUG \| This is Debug logging \([\w\._:]+:\d+\)$")
|
||||
|
||||
if verbosity >= 1:
|
||||
assert logging.is_info() is True
|
||||
captured = capsys.readouterr()
|
||||
assert not captured.out
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert not captured
|
||||
|
||||
assert logging.is_info("info text") is True
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out == "info text\n"
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert captured == "info text\n"
|
||||
|
||||
log.info("This is Info logging")
|
||||
captured = capsys.readouterr()
|
||||
assert captured.err == "INFO | This is Info logging\n"
|
||||
captured = strip_ansi(capsys.readouterr().err)
|
||||
assert captured == "INFO | This is Info logging\n"
|
||||
else:
|
||||
assert logging.is_info("info text") is False
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out != "info text\n"
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert captured != "info text\n"
|
||||
|
||||
log.info("This is Info logging")
|
||||
captured = capsys.readouterr()
|
||||
assert not captured.out
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert not captured
|
||||
|
||||
assert logging.is_default() is True
|
||||
captured = capsys.readouterr()
|
||||
assert not captured.out
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert not captured
|
||||
|
||||
assert logging.is_default("default text") is True
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out == "default text\n"
|
||||
captured = strip_ansi(capsys.readouterr().out)
|
||||
assert captured == "default text\n"
|
||||
|
||||
if log_to_file:
|
||||
assert tmp_log.exists() is True
|
||||
|
||||
Reference in New Issue
Block a user