Download tests/test_ciegas_t3.py from Changetheblock/LicitaBench: direct link, hf CLI and curl.
- Browser
- Download file 4.5 kB
-
https://huggingface.co/datasets/Changetheblock/LicitaBench/resolve/main/tests/test_ciegas_t3.py
- Command line
-
hf download hf://datasets/Changetheblock/LicitaBench/tests/test_ciegas_t3.py
-
curl -L -o test_ciegas_t3.py https://huggingface.co/datasets/Changetheblock/LicitaBench/resolve/main/tests/test_ciegas_t3.py
4.5 kB
| import json | |
| import pytest | |
| from licitabench import ciegas, evaluate, verificar | |
| from test_ciegas import _reg | |
| def _reg_t3(i, umbral=100000.0, ens="MEDIO"): | |
| return {"id_verificacion": f"T3-placsp-{i}", "tarea": "T3", "id": f"placsp-{i}", "titulo": "t", "documento": {"url": "u"}, | |
| "etiquetas_propuestas": { | |
| "solvencia_economica": {"exigida": True, "umbral_importe": umbral, "descripcion": None}, | |
| "solvencia_tecnica": {"exigida": True, "descripcion": None}, | |
| "certificaciones": [{"nombre": "ENS", "nivel": ens, "obligatoria": True, "detalle": None}], | |
| "habilitacion_empresarial": {"exigida": False, "descripcion": None}}, | |
| "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(f"x{k}") for k in range(3)] + [_reg_t3(str(1000 + k)) 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_t3_en_su_fichero_con_excluidos_y_bloquea(cola): | |
| t2 = ciegas.preparar("T2", 2) | |
| t3 = ciegas.preparar("T3", 3, excluir=["1000", "placsp-1001", "T3-placsp-1002"]) | |
| assert (cola / "muestra_ciega_T3.json").exists() | |
| assert not {"T3-placsp-1000", "T3-placsp-1001", "T3-placsp-1002"} & set(t3) and len(t3) == 3 | |
| datos = json.loads((cola / "muestra_ciega_T3.json").read_text(encoding="utf-8")) | |
| assert datos["excluidos_por_contenido_conocido"] == ["T3-placsp-1000", "T3-placsp-1001", "T3-placsp-1002"] | |
| assert ciegas.muestra(tarea="T2") == t2 and ciegas.muestra(tarea="T3") == t3 | |
| assert ciegas.bloqueados_por_ciegas() == set(t2) | set(t3) | |
| def test_anotacion_guiada_t3(): | |
| respuestas = iter(["s", "107.750,00", "volumen 1,5 veces", "s", "", "1", "a", "s", "", "3", "n", "", | |
| "8", "Gold", "s", "partner UiPath", "", "n", "s"]) | |
| et = ciegas.preguntar_t3(lambda _: next(respuestas)) | |
| assert et["solvencia_economica"] == {"exigida": True, "umbral_importe": 107750, "descripcion": "volumen 1,5 veces"} | |
| assert et["certificaciones"][0] == {"nombre": "ENS", "nivel": "ALTO", "obligatoria": True, "detalle": None} | |
| assert et["certificaciones"][1]["nombre"] == "ISO 9001" and et["certificaciones"][1]["obligatoria"] is False | |
| assert et["certificaciones"][2] == {"nombre": "otra", "nivel": "Gold", "obligatoria": True, "detalle": "partner UiPath"} | |
| assert et["habilitacion_empresarial"]["exigida"] is False | |
| assert ciegas.validar_t3(et) is None | |
| def test_validar_t3_rechaza_ens_sin_nivel_y_umbral_texto(): | |
| et = ciegas.limpiar_t3(dict(ciegas.PLANTILLA_T3)) | |
| assert ciegas.validar_t3(et) is None | |
| et["certificaciones"] = [{"nombre": "ENS", "obligatoria": True}] | |
| assert "nivel" in ciegas.validar_t3(ciegas.limpiar_t3(et)) | |
| et["certificaciones"] = [] | |
| et["solvencia_economica"] = {"exigida": True, "umbral_importe": "mucho"} | |
| assert "umbral" in ciegas.validar_t3(et) | |
| def test_comparar_t3(cola): | |
| ids = ciegas.preparar("T3", 2, semilla=3) | |
| regs = {r["id_verificacion"]: r for r in map(json.loads, (cola / "pendientes.jsonl").read_text().splitlines())} | |
| ciegas.guardar_anotacion(ids[0], "T3", "Ana", regs[ids[0]]["etiquetas_propuestas"]) | |
| otra = json.loads(json.dumps(regs[ids[1]]["etiquetas_propuestas"])) | |
| otra["solvencia_economica"]["umbral_importe"] = 50000 | |
| ciegas.guardar_anotacion(ids[1], "T3", "Ana", otra) | |
| res = ciegas.comparar(tarea="T3") | |
| assert res["claude"]["n"] == 2 and res["claude"]["exactitud_umbral_solvencia_economica"] == 0.5 | |
| assert res["claude"]["f1_certificaciones"] == 1.0 | |
| assert (cola / "acuerdo_ciego_T3.md").read_text(encoding="utf-8").startswith("# Acuerdo de la anotación a ciegas (T3)") | |
| assert ciegas.comparar(escribir=False)["claude"]["n"] == 0 # T2 no tiene muestra: no mezcla tareas | |