mirror of
https://github.com/natelandau/obsidian-metadata.git
synced 2025-11-17 09:23:40 -05:00
fix: add custom exceptions (#29)
* feat: add custom exceptions to metadata creation * refactor: utility function for finding inline metadata in content * fix: use InlineTagError for exceptions parsing inline tags * fix: improve error messages * build(deps): bump dependencies * fix: use BadParameter exception when appropriate
This commit is contained in:
@@ -8,6 +8,7 @@ import pytest
|
||||
import typer
|
||||
|
||||
from obsidian_metadata.models.enums import InsertLocation, MetadataType
|
||||
from obsidian_metadata.models.exceptions import InlineMetadataError, InlineTagError
|
||||
from obsidian_metadata.models.notes import Note
|
||||
from tests.helpers import Regex
|
||||
|
||||
@@ -88,6 +89,38 @@ def test_create_note_2() -> None:
|
||||
Note(note_path=broken_fm)
|
||||
|
||||
|
||||
def test_create_note_3(sample_note, mocker) -> None:
|
||||
"""Test creating a note object.
|
||||
|
||||
GIVEN a text file with invalid inline metadata
|
||||
WHEN the note is initialized
|
||||
THEN a typer exit is raised
|
||||
"""
|
||||
mocker.patch(
|
||||
"obsidian_metadata.models.notes.InlineMetadata",
|
||||
side_effect=InlineMetadataError("error message"),
|
||||
)
|
||||
|
||||
with pytest.raises(typer.Exit):
|
||||
Note(note_path=sample_note)
|
||||
|
||||
|
||||
def test_create_note_4(sample_note, mocker) -> None:
|
||||
"""Test creating a note object.
|
||||
|
||||
GIVEN a text file
|
||||
WHEN there is an error parsing the inline tags
|
||||
THEN a typer exit is raised
|
||||
"""
|
||||
mocker.patch(
|
||||
"obsidian_metadata.models.notes.InlineTags",
|
||||
side_effect=InlineTagError("error message"),
|
||||
)
|
||||
|
||||
with pytest.raises(typer.Exit):
|
||||
Note(note_path=sample_note)
|
||||
|
||||
|
||||
def test_add_metadata_method_1(short_notes):
|
||||
"""Test adding metadata.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user