mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Implement tag tests in JSON
Co-authored-by: Jonathan Wren <jonathan@nowandwren.com>
This commit is contained in:
parent
3cc3e387c5
commit
48c9d9fa16
2 changed files with 25 additions and 13 deletions
|
@ -6,11 +6,13 @@ Feature: Custom formats
|
||||||
When we run "jrnl --format json"
|
When we run "jrnl --format json"
|
||||||
Then we should get no error
|
Then we should get no error
|
||||||
And the output should be valid JSON
|
And the output should be valid JSON
|
||||||
And "entries" in the json output should have 3 elements
|
Given we parse the output as JSON
|
||||||
And "tags" in the json output should contain "@ipsum"
|
Then "entries" node in the parsed output should have 3 elements
|
||||||
And "tags" in the json output should contain "@tagone"
|
And "tags" in the parsed output should be
|
||||||
And "tags" in the json output should contain "@tagthree"
|
@ipsum
|
||||||
And "tags" in the json output should contain "@tagtwo"
|
@tagone
|
||||||
|
@tagtwo
|
||||||
|
@tagthree
|
||||||
And entry 1 should have an array "tags" with 3 elements
|
And entry 1 should have an array "tags" with 3 elements
|
||||||
And entry 2 should have an array "tags" with 1 elements
|
And entry 2 should have an array "tags" with 1 elements
|
||||||
And entry 3 should have an array "tags" with 2 elements
|
And entry 3 should have an array "tags" with 2 elements
|
||||||
|
|
|
@ -499,23 +499,33 @@ def assert_parsed_output_item_count(node_name, number, parsed_output):
|
||||||
else:
|
else:
|
||||||
assert False, f"Language name {lang} not recognized"
|
assert False, f"Language name {lang} not recognized"
|
||||||
|
|
||||||
|
@then(parse('"{field_name}" in the parsed output should be\n{expected_keys}'))
|
||||||
@then(parse('"tags" in the parsed output should be\n{expected_tags}'))
|
def assert_xml_output_tags(field_name, expected_keys, cli_run, parsed_output):
|
||||||
def assert_xml_output_tags(expected_tags, cli_run, parsed_output):
|
|
||||||
lang = parsed_output["lang"]
|
lang = parsed_output["lang"]
|
||||||
obj = parsed_output["obj"]
|
obj = parsed_output["obj"]
|
||||||
expected_tags = expected_tags.split("\n")
|
expected_keys = expected_keys.split("\n")
|
||||||
|
|
||||||
if lang == "XML":
|
if lang == "XML":
|
||||||
xml_node_names = (node.tag for node in obj)
|
xml_node_names = (node.tag for node in obj)
|
||||||
assert "tags" in xml_node_names, str(list(xml_node_names))
|
assert field_name in xml_node_names, str(list(xml_node_names))
|
||||||
|
|
||||||
actual_tags = set(t.attrib["name"] for t in obj.find("tags"))
|
if field_name == "tags":
|
||||||
assert actual_tags == set(expected_tags), [actual_tags, set(expected_tags)]
|
actual_tags = set(t.attrib["name"] for t in obj.find("tags"))
|
||||||
|
assert set(actual_tags) == set(expected_keys), [actual_tags, set(expected_keys)]
|
||||||
|
else:
|
||||||
|
assert False, "This test only works for tags in XML"
|
||||||
|
|
||||||
elif lang == "JSON":
|
elif lang == "JSON":
|
||||||
assert False, "JSON not implemented in this step"
|
my_obj = obj
|
||||||
|
|
||||||
|
for node in field_name.split("."):
|
||||||
|
try:
|
||||||
|
my_obj = my_obj[int(node)]
|
||||||
|
except ValueError:
|
||||||
|
assert field_name in my_obj
|
||||||
|
my_obj = my_obj[node]
|
||||||
|
|
||||||
|
assert set(expected_keys) == set(my_obj)
|
||||||
else:
|
else:
|
||||||
assert False, f"Language name {lang} not recognized"
|
assert False, f"Language name {lang} not recognized"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue