mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-19 04:28:31 +02:00
PR feedback
make exception more informative update check_linewrap signature in src and test make check_linewrap a free function
This commit is contained in:
parent
e063fa9715
commit
502d47f223
4 changed files with 22 additions and 16 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -61,6 +61,3 @@ coverage.xml
|
|||
.coverage
|
||||
.vscode/tasks.json
|
||||
todo.txt
|
||||
|
||||
tags
|
||||
.vimrc
|
|
@ -33,8 +33,10 @@ class JrnlError(Exception):
|
|||
),
|
||||
"LineWrapTooSmallForDateFormat": textwrap.dedent(
|
||||
"""
|
||||
The provided linewrap value of {config_linewrap} is too small
|
||||
to display the timestamps in the configured time format.
|
||||
The provided linewrap value of {config_linewrap} is too small by {columns} columns
|
||||
to display the timestamps in the configured time format for journal {journal}.
|
||||
|
||||
You can avoid this error by specifying a linewrap value that is larger by at least {columns} in the configuration file or by using --config-override at the command line
|
||||
"""
|
||||
),
|
||||
}
|
||||
|
|
|
@ -41,7 +41,8 @@ class FancyExporter(TextExporter):
|
|||
card = [
|
||||
cls.border_a + cls.border_b * (initial_linewrap) + cls.border_c + date_str
|
||||
]
|
||||
cls.check_linewrap(linewrap, card)
|
||||
check_provided_linewrap_viability(linewrap, card, entry.journal)
|
||||
|
||||
w = TextWrapper(
|
||||
width=initial_linewrap,
|
||||
initial_indent=cls.border_g + " ",
|
||||
|
@ -75,14 +76,20 @@ class FancyExporter(TextExporter):
|
|||
card.append(cls.border_l + cls.border_b * body_linewrap + cls.border_m)
|
||||
return "\n".join(card)
|
||||
|
||||
@classmethod
|
||||
def check_linewrap(cls, linewrap, card):
|
||||
if len(card[0]) > linewrap:
|
||||
raise JrnlError("LineWrapTooSmallForDateFormat", config_linewrap=linewrap)
|
||||
else:
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def export_journal(cls, journal):
|
||||
"""Returns a unicode representation of an entire journal."""
|
||||
return "\n".join(cls.export_entry(entry) for entry in journal)
|
||||
|
||||
|
||||
def check_provided_linewrap_viability(linewrap, card, journal):
|
||||
if len(card[0]) > linewrap:
|
||||
width_violation = len(card[0]) - linewrap
|
||||
raise JrnlError(
|
||||
"LineWrapTooSmallForDateFormat",
|
||||
config_linewrap=linewrap,
|
||||
columns=width_violation,
|
||||
journal=journal,
|
||||
)
|
||||
else:
|
||||
pass
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
from jrnl.exception import JrnlError
|
||||
from jrnl.plugins.fancy_exporter import FancyExporter
|
||||
|
||||
from jrnl.plugins.fancy_exporter import check_provided_linewrap_viability
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -30,10 +29,11 @@ def build_card_header(datestr):
|
|||
class TestFancy:
|
||||
def test_too_small_linewrap(self, datestr):
|
||||
|
||||
journal = "test_journal"
|
||||
content = build_card_header(datestr)
|
||||
|
||||
total_linewrap = 12
|
||||
|
||||
with pytest.raises(JrnlError) as e:
|
||||
FancyExporter.check_linewrap(total_linewrap, [content])
|
||||
check_provided_linewrap_viability(total_linewrap, [content], journal)
|
||||
assert e.value.error_type == "LineWrapTooSmallForDateFormat"
|
||||
|
|
Loading…
Add table
Reference in a new issue