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:
Jonathan Wren 2020-02-29 14:44:42 -08:00
parent 9e5d160bbd
commit 302d353c4d
5 changed files with 13 additions and 78 deletions

View file

@ -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