mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 08:38:32 +02:00
Fix up tests and related issues
Upgrade poetry if already installed Get rid of test function that was causing windows problems
This commit is contained in:
parent
9e5d160bbd
commit
302d353c4d
5 changed files with 13 additions and 78 deletions
|
@ -13,7 +13,7 @@ before_install:
|
|||
- date
|
||||
|
||||
install:
|
||||
- pip install poetry
|
||||
- pip install --upgrade poetry
|
||||
- poetry install
|
||||
- poetry run python --version
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ Feature: Contains
|
|||
Given we use the config "tags.yaml"
|
||||
When we run "jrnl @idea -contains software"
|
||||
Then we should get no error
|
||||
and the output should contain "software"
|
||||
And the output should contain "software"
|
||||
|
||||
Scenario: Searching for a string within AND tag results
|
||||
Given we use the config "tags.yaml"
|
||||
|
|
|
@ -36,12 +36,12 @@ Feature: Basic reading and writing to a journal
|
|||
@skip_win
|
||||
Scenario: Writing an empty entry from the editor
|
||||
Given we use the config "editor.yaml"
|
||||
When we open the editor and enter ""
|
||||
When we open the editor and enter nothing
|
||||
Then we should see the message "[Nothing saved to file]"
|
||||
|
||||
Scenario: Writing an empty entry from the command line
|
||||
Given we use the config "basic.yaml"
|
||||
When we run "jrnl" and enter ""
|
||||
When we run "jrnl" and enter nothing
|
||||
Then the output should be
|
||||
"""
|
||||
|
||||
|
|
|
@ -82,18 +82,15 @@ def set_config(context, config_file):
|
|||
cf.write("version: {}".format(__version__))
|
||||
|
||||
|
||||
@when('we open the editor and enter ""')
|
||||
@when('we open the editor and enter "{text}"')
|
||||
@when("we open the editor and enter nothing")
|
||||
def open_editor_and_enter(context, text=""):
|
||||
text = text or context.text
|
||||
text = text or context.text or ""
|
||||
|
||||
def _mock_editor_function(command):
|
||||
tmpfile = command[-1]
|
||||
with open(tmpfile, "w+") as f:
|
||||
if text is not None:
|
||||
f.write(text)
|
||||
else:
|
||||
f.write("")
|
||||
f.write(text)
|
||||
|
||||
return tmpfile
|
||||
|
||||
|
@ -119,7 +116,7 @@ def _mock_input(inputs):
|
|||
|
||||
|
||||
@when('we run "{command}" and enter')
|
||||
@when('we run "{command}" and enter ""')
|
||||
@when('we run "{command}" and enter nothing')
|
||||
@when('we run "{command}" and enter "{inputs}"')
|
||||
def run_with_input(context, command, inputs=""):
|
||||
# create an iterator through all inputs. These inputs will be fed one by one
|
||||
|
@ -186,69 +183,11 @@ def no_error(context):
|
|||
assert context.exit_status == 0, context.exit_status
|
||||
|
||||
|
||||
@then("the output should be parsable as json")
|
||||
def check_output_json(context):
|
||||
out = context.stdout_capture.getvalue()
|
||||
assert json.loads(out), out
|
||||
|
||||
|
||||
@then('"{field}" in the json output should have {number:d} elements')
|
||||
@then('"{field}" in the json output should have 1 element')
|
||||
def check_output_field(context, field, number=1):
|
||||
out = context.stdout_capture.getvalue()
|
||||
out_json = json.loads(out)
|
||||
assert field in out_json, [field, out_json]
|
||||
assert len(out_json[field]) == number, len(out_json[field])
|
||||
|
||||
|
||||
@then('"{field}" in the json output should not contain "{key}"')
|
||||
def check_output_field_not_key(context, field, key):
|
||||
out = context.stdout_capture.getvalue()
|
||||
out_json = json.loads(out)
|
||||
assert field in out_json
|
||||
assert key not in out_json[field]
|
||||
|
||||
|
||||
@then('"{field}" in the json output should contain "{key}"')
|
||||
def check_output_field_key(context, field, key):
|
||||
out = context.stdout_capture.getvalue()
|
||||
out_json = json.loads(out)
|
||||
assert field in out_json
|
||||
assert key in out_json[field]
|
||||
|
||||
|
||||
@then('the json output should contain {path} = "{value}"')
|
||||
def check_json_output_path(context, path, value):
|
||||
""" E.g.
|
||||
the json output should contain entries.0.title = "hello"
|
||||
"""
|
||||
out = context.stdout_capture.getvalue()
|
||||
struct = json.loads(out)
|
||||
|
||||
for node in path.split("."):
|
||||
try:
|
||||
struct = struct[int(node)]
|
||||
except ValueError:
|
||||
struct = struct[node]
|
||||
assert struct == value, struct
|
||||
|
||||
|
||||
def process_ANSI_escapes(text):
|
||||
"""Escapes and 'unescapes' a string with ANSI escapes so that behave stdout
|
||||
comparisons work properly. This will render colors, and works with unicode
|
||||
characters. https://stackoverflow.com/a/57192592
|
||||
:param str text: The text to be escaped and unescaped
|
||||
:return: Colorized / escaped text
|
||||
:rtype: str
|
||||
"""
|
||||
return decode(encode(text, "latin-1", "backslashreplace"), "unicode-escape")
|
||||
|
||||
|
||||
@then("the output should be")
|
||||
@then('the output should be "{text}"')
|
||||
def check_output(context, text=None):
|
||||
text = (text or context.text).strip().splitlines()
|
||||
out = process_ANSI_escapes(context.stdout_capture.getvalue().strip()).splitlines()
|
||||
out = context.stdout_capture.getvalue().strip().splitlines()
|
||||
assert len(text) == len(out), "Output has {} lines (expected: {})".format(
|
||||
len(out), len(text)
|
||||
)
|
||||
|
@ -261,7 +200,7 @@ def check_output(context, text=None):
|
|||
|
||||
@then('the output should contain "{text}" in the local time')
|
||||
def check_output_time_inline(context, text):
|
||||
out = process_ANSI_escapes(context.stdout_capture.getvalue())
|
||||
out = context.stdout_capture.getvalue()
|
||||
local_tz = tzlocal.get_localzone()
|
||||
date, flag = CALENDAR.parse(text)
|
||||
output_date = time.strftime("%Y-%m-%d %H:%M", date)
|
||||
|
@ -273,7 +212,7 @@ def check_output_time_inline(context, text):
|
|||
@then('the output should contain "{text}" or "{text2}"')
|
||||
def check_output_inline(context, text=None, text2=None):
|
||||
text = text or context.text
|
||||
out = process_ANSI_escapes(context.stdout_capture.getvalue())
|
||||
out = context.stdout_capture.getvalue()
|
||||
assert text in out or text2 in out, text or text2
|
||||
|
||||
|
||||
|
|
|
@ -226,13 +226,9 @@ def highlight_tags_with_background_color(entry, text, color, is_title=False):
|
|||
if config["highlight"]: # highlight tags
|
||||
if entry.journal.search_tags:
|
||||
text_fragments = []
|
||||
for tag in entry.search_tags:
|
||||
for tag in entry.journal.search_tags:
|
||||
text_fragments.extend(
|
||||
re.split(
|
||||
re.compile(re.escape(tag), re.IGNORECASE),
|
||||
text,
|
||||
flags=re.UNICODE,
|
||||
)
|
||||
re.split(re.compile(re.escape(tag), re.IGNORECASE), text)
|
||||
)
|
||||
else:
|
||||
text_fragments = re.split(entry.tag_regex(config["tagsymbols"]), text)
|
||||
|
|
Loading…
Add table
Reference in a new issue