Convert ADF to markdown and back through adf-codec's lossless pair
CI / tests (pull_request) Successful in 1m47s
CI / tests (pull_request) Successful in 1m47s
This commit is contained in:
@@ -66,6 +66,36 @@ def test_adf_to_markdown_returns_the_text_of_its_one_document():
|
||||
assert run.calls == [("to-markdown", json.dumps([DOC]))]
|
||||
|
||||
|
||||
def test_markdown_to_adf_lossless_runs_the_lossless_mode():
|
||||
run = fake(0, json.dumps(DOC))
|
||||
assert convert.markdown_to_adf_lossless("Hi\n", run) == DOC
|
||||
assert run.calls == [("to-adf-lossless", "Hi\n")]
|
||||
|
||||
|
||||
def test_adfs_to_markdown_lossless_sends_every_document_in_one_lossless_run():
|
||||
run = fake(0, json.dumps(["a\n", "b\n"]))
|
||||
assert convert.adfs_to_markdown_lossless([DOC, DOC], run) == ["a\n", "b\n"]
|
||||
assert run.calls == [("to-markdown-lossless", json.dumps([DOC, DOC]))]
|
||||
|
||||
|
||||
def test_adf_to_markdown_lossless_returns_the_text_of_its_one_document():
|
||||
run = fake(0, json.dumps(["a\n"]))
|
||||
assert convert.adf_to_markdown_lossless(DOC, run) == "a\n"
|
||||
assert run.calls == [("to-markdown-lossless", json.dumps([DOC]))]
|
||||
|
||||
|
||||
def test_adfs_to_markdown_lossless_names_a_refused_documents_index():
|
||||
refusal = {"index": 1, "error": {"code": "not-an-adf-document", "message": "no type", "path": []}}
|
||||
refused = convert.adfs_to_markdown_lossless([DOC, DOC], fake(2, json.dumps(refusal)))
|
||||
assert refused == convert.Refused(1, Failure("adf-codec refused the input with not-an-adf-document: no type (at the document)"))
|
||||
|
||||
|
||||
def test_adfs_to_markdown_lossless_of_no_documents_runs_no_container():
|
||||
run = fake(1)
|
||||
assert convert.adfs_to_markdown_lossless([], run) == []
|
||||
assert run.calls == []
|
||||
|
||||
|
||||
def test_a_refusal_becomes_a_failure_with_adf_codecs_code_and_message():
|
||||
refusal = {"error": {"code": "malformed-pipe-table", "message": "row has too many cells", "path": [], "position": {"line": 3, "offset": 9}}}
|
||||
failure = convert.markdown_to_adf("| a |\n", fake(2, json.dumps(refusal)))
|
||||
@@ -279,3 +309,28 @@ def test_round_trip_through_the_real_container():
|
||||
assert isinstance(second, convert.Refused) and second.index == 1 and "not-an-adf-document" in second.failure.reason
|
||||
crashed = convert.answer("to-markdown", "not json", convert.container_run)
|
||||
assert isinstance(crashed, Failure) and crashed.reason.startswith("the adf-codec shim failed with exit 1: ")
|
||||
|
||||
|
||||
# A Jira description as Jira stores it: every block carries a localId, and an empty paragraph spaces two blocks.
|
||||
JIRA_DESCRIPTION = {
|
||||
"type": "doc", "version": 1, "content": [
|
||||
{"type": "heading", "attrs": {"level": 2, "localId": "h-1"}, "content": [{"type": "text", "text": "Goal"}]},
|
||||
{"type": "paragraph", "attrs": {"localId": "p-1"}, "content": [{"type": "text", "text": "Keep "}, {"type": "text", "text": "this", "marks": [{"type": "strong"}]}]},
|
||||
{"type": "paragraph", "attrs": {"localId": "p-2"}},
|
||||
{"type": "bulletList", "attrs": {"localId": "l-1"}, "content": [
|
||||
{"type": "listItem", "attrs": {"localId": "i-1"}, "content": [{"type": "paragraph", "attrs": {"localId": "p-3"}, "content": [{"type": "text", "text": "one"}]}]},
|
||||
]},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.skipif(shutil.which("docker") is None or subprocess.run(["docker", "info"], capture_output=True, timeout=20).returncode != 0, reason="needs a docker daemon")
|
||||
def test_the_lossless_pair_gives_back_a_jira_description_identical_and_the_portable_pair_does_not():
|
||||
markdown = convert.adf_to_markdown_lossless(JIRA_DESCRIPTION)
|
||||
assert isinstance(markdown, str)
|
||||
assert convert.markdown_to_adf_lossless(markdown) == JIRA_DESCRIPTION
|
||||
assert convert.adfs_to_markdown_lossless([JIRA_DESCRIPTION, JIRA_DESCRIPTION]) == [markdown, markdown]
|
||||
portable = convert.markdown_to_adf(convert.adf_to_markdown(JIRA_DESCRIPTION))
|
||||
assert portable != JIRA_DESCRIPTION
|
||||
second = convert.adfs_to_markdown_lossless([JIRA_DESCRIPTION, {"type": "nope"}])
|
||||
assert isinstance(second, convert.Refused) and second.index == 1
|
||||
|
||||
Reference in New Issue
Block a user