Fix unit test

This commit is contained in:
outa 2022-09-29 12:57:43 +02:00
parent 39621a9e15
commit 49faca3432

View file

@ -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):
mock_export_journal.side_effect = JrnlException(
Message(MsgText.YamlMustBeDirectory, MsgStyle.ERROR)
)
with pytest.raises(JrnlException): with pytest.raises(JrnlException):
YAMLExporter.write_file(simple_journal, p) YAMLExporter.write_file("journal", "non-existing-path")
assert not p.exists() mock_open.assert_not_called()