Spaces:
Running
Running
Download tests/test_packaged_knowledge.py from BravoRobots/lexia: direct link, hf CLI and curl.
- Browser
- Download file 2.41 kB
-
https://huggingface.co/spaces/BravoRobots/lexia/resolve/main/tests/test_packaged_knowledge.py
- Command line
-
hf download hf://spaces/BravoRobots/lexia/tests/test_packaged_knowledge.py
-
curl -L -o test_packaged_knowledge.py https://huggingface.co/spaces/BravoRobots/lexia/resolve/main/tests/test_packaged_knowledge.py
2.41 kB
| import hashlib | |
| import json | |
| from pathlib import Path | |
| import lexia.legal as _legal | |
| from lexia.legal.corpus import CorpusManifest | |
| LEGAL = Path(_legal.__file__).resolve().parent | |
| def test_official_source_manifest_is_packaged() -> None: | |
| manifest = CorpusManifest.load(LEGAL / "data" / "corpus_sources.json") | |
| assert len(manifest.sources) >= 16 | |
| assert all(source.official_url.startswith("https://") for source in manifest.sources) | |
| def test_seed_corpus_matches_declared_hash() -> None: | |
| records = LEGAL / "seed" / "corpus" / "records.jsonl" | |
| snapshot = json.loads( | |
| (LEGAL / "seed" / "corpus" / "snapshot.json").read_text(encoding="utf-8") | |
| ) | |
| expected = snapshot["records_sha256"] | |
| assert hashlib.sha256(records.read_bytes()).hexdigest() == expected | |
| assert sum(1 for _ in records.open(encoding="utf-8")) == snapshot["record_count"] | |
| # -- cola de ampliación del corpus ------------------------------------------- | |
| def test_la_cola_de_ampliacion_es_valida_y_no_duplica_lo_que_ya_hay(): | |
| """Metadatos contrastados el 2026-09-15 contra EUR-Lex y el BOE.""" | |
| from lexia.legal.corpus import CorpusManifest | |
| datos = Path(__file__).resolve().parent.parent / "lexia" / "legal" / "data" | |
| cola = CorpusManifest.load(datos / "corpus_sources_ampliacion.json") | |
| principal = CorpusManifest.load(datos / "corpus_sources.json") | |
| ya = {fuente.source_id for fuente in principal.sources} | |
| for fuente in cola.sources: | |
| assert fuente.source_id not in ya, fuente.source_id | |
| assert fuente.official_url.startswith("https://") | |
| assert fuente.published_on.year >= 2002 | |
| def test_ninguna_fuente_de_la_cola_entra_en_el_corpus_sin_texto(): | |
| """Una fuente declarada y sin fragmentos sería una cita insostenible.""" | |
| import json | |
| datos = Path(__file__).resolve().parent.parent / "lexia" / "legal" / "data" | |
| declaradas = { | |
| fuente["id"] | |
| for fuente in json.loads( | |
| (datos / "corpus_sources.json").read_text(encoding="utf-8") | |
| )["sources"] | |
| } | |
| con_texto = set() | |
| semilla = Path(__file__).resolve().parent.parent / "lexia" / "legal" / "seed" / "corpus" | |
| for linea in (semilla / "records.jsonl").read_text(encoding="utf-8").splitlines(): | |
| if linea.strip(): | |
| con_texto.add(json.loads(linea)["source_id"]) | |
| assert declaradas == con_texto, declaradas.symmetric_difference(con_texto) | |