mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-17 11:38:32 +02:00
Fix unit test
This commit is contained in:
parent
39621a9e15
commit
49faca3432
1 changed files with 13 additions and 18 deletions
|
@ -1,14 +1,14 @@
|
||||||
# Copyright © 2012-2022 jrnl contributors
|
# Copyright © 2012-2022 jrnl contributors
|
||||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||||
|
|
||||||
from pathlib import Path
|
from unittest import mock
|
||||||
from tempfile import TemporaryDirectory
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from ruamel.yaml import YAML
|
|
||||||
|
|
||||||
from jrnl.exception import JrnlException
|
from jrnl.exception import JrnlException
|
||||||
from jrnl.Journal import PlainJournal
|
from jrnl.messages import Message
|
||||||
|
from jrnl.messages import MsgStyle
|
||||||
|
from jrnl.messages import MsgText
|
||||||
from jrnl.plugins.fancy_exporter import check_provided_linewrap_viability
|
from jrnl.plugins.fancy_exporter import check_provided_linewrap_viability
|
||||||
from jrnl.plugins.yaml_exporter import YAMLExporter
|
from jrnl.plugins.yaml_exporter import YAMLExporter
|
||||||
|
|
||||||
|
@ -18,14 +18,6 @@ def datestr():
|
||||||
yield "2020-10-20 16:59"
|
yield "2020-10-20 16:59"
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
|
||||||
def simple_journal():
|
|
||||||
with open("tests/data/configs/simple.yaml") as f:
|
|
||||||
yaml = YAML(typ="safe")
|
|
||||||
config = yaml.load(f)
|
|
||||||
return PlainJournal("simple_journal", **config).open()
|
|
||||||
|
|
||||||
|
|
||||||
def build_card_header(datestr):
|
def build_card_header(datestr):
|
||||||
top_left_corner = "┎─╮"
|
top_left_corner = "┎─╮"
|
||||||
content = top_left_corner + datestr
|
content = top_left_corner + datestr
|
||||||
|
@ -45,9 +37,12 @@ class TestFancy:
|
||||||
|
|
||||||
|
|
||||||
class TestYaml:
|
class TestYaml:
|
||||||
def test_export_to_nonexisting_folder(self, simple_journal):
|
@mock.patch("jrnl.plugins.yaml_exporter.YAMLExporter.export_journal")
|
||||||
with TemporaryDirectory() as tmpdir:
|
@mock.patch("builtins.open")
|
||||||
p = Path(tmpdir / "non_existing_folder")
|
def test_export_to_nonexisting_folder(self, mock_open, mock_export_journal):
|
||||||
with pytest.raises(JrnlException):
|
mock_export_journal.side_effect = JrnlException(
|
||||||
YAMLExporter.write_file(simple_journal, p)
|
Message(MsgText.YamlMustBeDirectory, MsgStyle.ERROR)
|
||||||
assert not p.exists()
|
)
|
||||||
|
with pytest.raises(JrnlException):
|
||||||
|
YAMLExporter.write_file("journal", "non-existing-path")
|
||||||
|
mock_open.assert_not_called()
|
||||||
|
|
Loading…
Add table
Reference in a new issue