Download tests/test_ciegas_t4.py from Changetheblock/LicitaBench: direct link, hf CLI and curl.
- Browser
- Download file 3.96 kB
-
https://huggingface.co/datasets/Changetheblock/LicitaBench/resolve/main/tests/test_ciegas_t4.py
- Command line
-
hf download hf://datasets/Changetheblock/LicitaBench/tests/test_ciegas_t4.py
-
curl -L -o test_ciegas_t4.py https://huggingface.co/datasets/Changetheblock/LicitaBench/resolve/main/tests/test_ciegas_t4.py
3.96 kB
| import json | |
| import pytest | |
| from licitabench import ciegas, evaluate, verificar | |
| def _reg_t4(i, respuesta="si", pregunta="¿Puede presentarse una empresa con 100.000 € de volumen?"): | |
| return {"id_verificacion": f"T4-placsp-{i}", "tarea": "T4", "id": f"placsp-{i}", "titulo": "t", "documento": {"url": "u"}, | |
| "pregunta": pregunta, "respuesta_objetivo": respuesta, | |
| "etiquetas_propuestas": {"respuesta": respuesta, "justificacion": "RESPUESTA-SECRETA cláusula 7", "clausula": "7"}, | |
| "estado": "pendiente", "verificado_por": None, "fecha_verificacion": None, "etiquetas_verificadas": None, "notas": None} | |
| def cola(tmp_path, monkeypatch): | |
| pend, ver = tmp_path / "pendientes.jsonl", tmp_path / "verificados.jsonl" | |
| filas = [_reg_t4(str(2000 + k), "si" if k % 2 else "no") for k in range(6)] | |
| pend.write_text("".join(json.dumps(r) + "\n" for r in filas), encoding="utf-8") | |
| for mod in (evaluate, verificar, ciegas): | |
| monkeypatch.setattr(mod, "RUTA_PENDIENTES", pend, raising=False) | |
| monkeypatch.setattr(mod, "RUTA_VERIFICADOS", ver, raising=False) | |
| monkeypatch.setattr(ciegas, "RUTA_CODEX", tmp_path / "revision_codex.jsonl") | |
| monkeypatch.setattr(ciegas, "RUTA_MUESTRA", tmp_path / "muestra_ciega.json") | |
| monkeypatch.setattr(ciegas, "RUTA_CIEGAS", tmp_path / "ciegas.jsonl") | |
| monkeypatch.setattr(ciegas, "RUTA_ACUERDO", tmp_path / "acuerdo.md") | |
| return tmp_path | |
| def test_muestra_t4_en_su_fichero(cola): | |
| ids = ciegas.preparar("T4", 3, excluir=["2000"]) | |
| assert (cola / "muestra_ciega_T4.json").exists() and len(ids) == 3 and "T4-placsp-2000" not in ids | |
| assert ciegas.bloqueados_por_ciegas() == set(ids) | |
| def test_anotacion_guiada_t4(): | |
| respuestas = iter(["z", "a", "dos lecturas del lote", "s"]) | |
| assert ciegas.preguntar_t4(lambda _: next(respuestas)) == {"respuesta": "ambigua", "justificacion": "dos lecturas del lote"} | |
| respuestas = iter(["s", "", "s"]) | |
| assert ciegas.preguntar_t4(lambda _: next(respuestas)) == {"respuesta": "si", "justificacion": None} | |
| assert ciegas.preguntar_t4(lambda _: "x") is None | |
| def test_validar_y_limpiar_t4(): | |
| assert ciegas.validar_t4({"respuesta": "quizá"}) | |
| et = ciegas.limpiar_t4({"_ayuda": "x", "respuesta": " Sí ", "justificacion": " cláusula 7 "}) | |
| assert et == {"respuesta": "si", "justificacion": "cláusula 7"} and ciegas.validar_t4(et) is None | |
| def test_anotar_t4_ensena_la_pregunta_y_no_la_respuesta(cola, monkeypatch, capsys): | |
| ids = ciegas.preparar("T4", 1) | |
| teclas = iter(["a", "q"]) | |
| monkeypatch.setattr("builtins.input", lambda _="": next(teclas)) | |
| monkeypatch.setattr(ciegas, "preguntar_t4", lambda *a, **k: {"respuesta": "no", "justificacion": None}) | |
| ciegas.anotar("Persona Prueba", tarea="T4") | |
| salida = capsys.readouterr().out | |
| assert "PREGUNTA DE LA MESA" in salida and "100.000" in salida and "RESPUESTA-SECRETA" not in salida | |
| assert ciegas.anotadas()[ids[0]]["etiquetas"]["respuesta"] == "no" | |
| def test_comparar_t4_deja_fuera_las_ambiguas(cola): | |
| ids = ciegas.preparar("T4", 3) | |
| regs = {json.loads(l)["id_verificacion"]: json.loads(l) for l in (cola / "pendientes.jsonl").read_text().splitlines()} | |
| ciegas.guardar_anotacion(ids[0], "T4", "P", {"respuesta": regs[ids[0]]["etiquetas_propuestas"]["respuesta"], "justificacion": None}) | |
| otra = "no" if regs[ids[1]]["etiquetas_propuestas"]["respuesta"] == "si" else "si" | |
| ciegas.guardar_anotacion(ids[1], "T4", "P", {"respuesta": otra, "justificacion": None}) | |
| ciegas.guardar_anotacion(ids[2], "T4", "P", {"respuesta": "ambigua", "justificacion": "dos lecturas"}) | |
| res = ciegas.comparar(tarea="T4") | |
| assert res["claude"]["n"] == 2 and res["claude"]["exactitud"] == 0.5 | |
| assert res["ambiguas"] == [ids[2]] | |
| texto = (cola / "acuerdo_ciego_T4.md").read_text(encoding="utf-8") | |
| assert "Exactitud (sí/no)" in texto and "ambiguas (fuera del cálculo): 1" in texto | |