"""volve_dia.ddr.xml on the Volve DDR XML files (skipped without the data).""" import pytest from volve_dia import paths from volve_dia.ddr.xml import parse_dir, parse_file XML = paths.ddr_xml_dir() pytestmark = [pytest.mark.data, pytest.mark.skipif(not XML.is_dir(), reason="missing the DDR XML folder")] def test_parse_file(): p = parse_file(XML / "15_9_F_12_2008_01_01.xml") r = p.report assert (r["report_id"], r["wellbore"], r["file_wellbore"], r["file_date"]) == ( "15_9_F_12_2008_01_01", "15/9-F-12", "15/9-F-12", "2008-01-01") assert r["nameWellbore"] == "NO 15/9-F-12" and r["dTimStart"] == "2007-12-31T00:00:00+01:00" assert (r["reportNo"], r["daysAhead"], r["tightWell"], r["waterDepth"]) == (98, 110.6, 0, 91.0) assert r["distDrill"] is None and p.sentinels[("reports", "distDrill")] == 1 # -999.99 in the file assert p.units[("reports", "waterDepth")] == ("m", "") assert {k: len(v) for k, v in p.sections.items()} == {"fluids": 1, "pore_pressure": 1, "activities": 19} a = p.sections["activities"][0] assert (a["act_id"], a["code_main"], a["code_sub"], a["state"], a["md"]) == ( "15_9_F_12_2008_01_01:000", "drilling", "bop/wellhead equipment", "ok", 0.0) def test_parse_dir_counts(): t = parse_dir(XML) r, a = t["reports"], t["activities"] assert len(r) == 1759 and r["wellbore"].nunique() == 26 and r["stem_ok"].all() assert len(a) == 23447 and (a["state"] == "fail").sum() == 480 assert (a["stateDetailActivity"] == "equipment failure").sum() == 1975 assert (a["duration_h"] > 0).all() and a["act_id"].is_unique assert t["units"].groupby(["table", "column"]).size().max() == 1