jrnl/tests/unit/test_export.py
Jonathan Wren 8da6029624
Update copyright notices for 2023 (#1660)
* update copyright notice for 2023

* standardize whitespace after copyright notice
2023-01-07 13:39:07 -08:00

48 lines
1.4 KiB
Python

# Copyright © 2012-2023 jrnl contributors
# License: https://www.gnu.org/licenses/gpl-3.0.html
from unittest import mock
import pytest
from jrnl.exception import JrnlException
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.yaml_exporter import YAMLExporter
@pytest.fixture()
def datestr():
yield "2020-10-20 16:59"
def build_card_header(datestr):
top_left_corner = "┎─╮"
content = top_left_corner + datestr
return content
class TestFancy:
def test_too_small_linewrap(self, datestr):
journal = "test_journal"
content = build_card_header(datestr)
total_linewrap = 12
with pytest.raises(JrnlException):
check_provided_linewrap_viability(total_linewrap, [content], journal)
class TestYaml:
@mock.patch("jrnl.plugins.yaml_exporter.YAMLExporter.export_journal")
@mock.patch("builtins.open")
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):
YAMLExporter.write_file("journal", "non-existing-path")
mock_open.assert_not_called()