From 53a754a1d7b7bfdc8827175bc55d6ca5ddb4ad50 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 14 Nov 2026 20:26:59 +0100 Subject: [PATCH] =?UTF-8?q?Answer=20stability=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=202=20=F0=9F=9F=A1=20(0=20misread);=20parametrize?= =?UTF-8?q?=20the=20looped=20tests,=20split=20the=20heavy-slot=20test=20an?= =?UTF-8?q?d=20close=20its=20slot=20file=20on=20failure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/adf_codec/test_adf_codec.py | 41 ++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/bin/adf_codec/test_adf_codec.py b/bin/adf_codec/test_adf_codec.py index c1a78b36..6029f0ff 100644 --- a/bin/adf_codec/test_adf_codec.py +++ b/bin/adf_codec/test_adf_codec.py @@ -48,16 +48,16 @@ def test_a_refused_document_names_its_index(): assert refused == convert.Refused(1, Failure("adf-codec refused the input with not-an-adf-document: no type (at the document)")) -def test_a_refusal_naming_no_document_handed_in_becomes_a_failure(): +def test_a_refusal_whose_index_is_past_the_documents_becomes_a_failure(): refusal = {"index": 2, "error": {"code": "not-an-adf-document", "message": "no type", "path": []}} failure = convert.adfs_to_markdown([DOC, DOC], fake(2, json.dumps(refusal))) - assert failure == Failure("the adf-codec shim refused document 2 of the 2 handed to it, counting from 0") + assert failure == Failure("the adf-codec shim refused a document at index 2, past the 2 it was handed") -def test_texts_that_do_not_match_the_documents_become_a_failure(): - for out in ("not json", json.dumps(["Hi\n"]), json.dumps({"0": "Hi\n"}), json.dumps(["Hi\n", 7])): - failure = convert.adfs_to_markdown([DOC, DOC], fake(0, out)) - assert failure == Failure(f"the adf-codec shim printed output that is not a JSON array of 2 texts: {out}"), out +@pytest.mark.parametrize("out", ["not json", json.dumps(["Hi\n"]), json.dumps({"0": "Hi\n"}), json.dumps(["Hi\n", 7])]) +def test_texts_that_do_not_match_the_documents_become_a_failure(out): + failure = convert.adfs_to_markdown([DOC, DOC], fake(0, out)) + assert failure == Failure(f"the adf-codec shim printed output that is not a JSON array of 2 texts: {out}") def test_adf_to_markdown_returns_the_text_of_its_one_document(): @@ -221,25 +221,34 @@ def test_a_failed_build_becomes_a_failure_with_its_stderr(tmp_path): assert convert.ensure_image(tmp_path, run_docker, Slot(run_docker)) == Failure("building the adf-codec shim's image failed with exit 5: no network") -def test_a_failure_to_start_docker_passes_through_inspect_and_build(tmp_path): +DOWN, MISSING = Failure("docker is not installed"), convert.Ran(1, "", "") + + +@pytest.mark.parametrize("answers", [(DOWN,), (MISSING, DOWN), (MISSING, MISSING, DOWN)], ids=["first inspect", "second inspect", "build"]) +def test_a_failure_to_start_docker_passes_through_inspect_and_build(tmp_path, answers): shim_dir(tmp_path) - down, missing = Failure("docker is not installed"), convert.Ran(1, "", "") - for answers in ((down,), (missing, down), (missing, missing, down)): - run_docker = scripted(*answers) - assert convert.ensure_image(tmp_path, run_docker, Slot(run_docker)) == down, answers + run_docker = scripted(*answers) + assert convert.ensure_image(tmp_path, run_docker, Slot(run_docker)) == DOWN -def test_a_heavy_slot_is_held_until_the_block_ends_and_waits_for_none_under_run_heavy(tmp_path): - env = {"XDG_STATE_HOME": str(tmp_path)} - with convert.heavy_slot(env, 1) as held: +def test_a_heavy_slot_is_held_until_the_block_ends(tmp_path): + with convert.heavy_slot({"XDG_STATE_HOME": str(tmp_path)}, 1) as held: assert held is None assert slots.taken_slot(tmp_path / "run-heavy", 1) is None slot, fd = slots.taken_slot(tmp_path / "run-heavy", 1) - with convert.heavy_slot(env | {slots.HELD: "0"}, 1) as held: - assert held is None os.close(fd) +def test_a_process_under_run_heavy_takes_no_second_slot(tmp_path): + (tmp_path / "run-heavy").mkdir() + slot, fd = slots.taken_slot(tmp_path / "run-heavy", 1) + try: + with convert.heavy_slot({"XDG_STATE_HOME": str(tmp_path), slots.HELD: "0"}, 1) as held: + assert held is None + finally: + os.close(fd) + + def test_a_heavy_slot_folder_that_cannot_be_made_yields_a_failure(tmp_path): (tmp_path / "run-heavy").write_text("a file where the folder goes") with convert.heavy_slot({"XDG_STATE_HOME": str(tmp_path)}, 1) as held: