SPlit up
Some checks failed
CI / Check (push) Failing after 1m58s
Build and publish Docker image / build-and-push (push) Failing after 1m5s

This commit is contained in:
Andras Schmelczer 2026-06-12 21:51:37 +01:00
parent cf39ad754e
commit f59d01227b
91 changed files with 10370 additions and 7562 deletions

View file

@ -0,0 +1,54 @@
import csv
import io
import zipfile
from pipeline.download.gias import _CSV_COLUMNS, transform
def _zip_with_rows(rows: list[dict[str, str]]) -> bytes:
text = io.StringIO()
writer = csv.DictWriter(text, fieldnames=_CSV_COLUMNS)
writer.writeheader()
for row in rows:
writer.writerow({col: row.get(col, "") for col in _CSV_COLUMNS})
buffer = io.BytesIO()
with zipfile.ZipFile(buffer, "w") as archive:
archive.writestr(
"edubasealldata20260611.csv",
text.getvalue().encode("cp1252"),
)
return buffer.getvalue()
def _school(name: str, status: str) -> dict[str, str]:
return {
"URN": "100000",
"EstablishmentName": name,
"TypeOfEstablishment (name)": "Community school",
"EstablishmentTypeGroup (name)": "Local authority maintained schools",
"EstablishmentStatus (name)": status,
"PhaseOfEducation (name)": "Primary",
"StatutoryLowAge": "4",
"StatutoryHighAge": "11",
"Easting": "530000",
"Northing": "180000",
"Postcode": "SW1A 1AA",
"Street": "1 School Lane",
"Town": "London",
"LA (name)": "Westminster",
}
def test_transform_keeps_open_but_proposed_to_close_schools() -> None:
# "Open, but proposed to close" establishments are operating schools (GIAS
# can keep the status for years); only closed and proposed-to-open rows are
# out of scope for the map.
rows = [
_school("Open School", "Open"),
_school("Closing School", "Open, but proposed to close"),
_school("Closed School", "Closed"),
_school("Future School", "Proposed to open"),
]
result = transform(_zip_with_rows(rows))
assert sorted(result["name"].to_list()) == ["Closing School", "Open School"]