-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_parser_project_pluto.py
More file actions
73 lines (51 loc) · 2.38 KB
/
Copy pathtest_parser_project_pluto.py
File metadata and controls
73 lines (51 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""Regression tests for the Project Pluto parser.
These tests do not call the internet. They read saved HTML responses from
Project Pluto and verify that neocp_explorer.py can still parse them.
Run from the repository root:
python test_parser_project_pluto.py
"""
from pathlib import Path
from neocp_explorer import split_project_pluto_output, parse_ephemeris_table_for_ui
DATA_DIR = Path("test_data")
def _load_fixture(filename: str) -> str:
path = DATA_DIR / filename
if not path.exists():
raise FileNotFoundError(
f"Missing fixture: {path}\n"
"Run: python fetch_project_pluto_test_data.py"
)
return path.read_text(encoding="utf-8")
def _assert_common_parse_ok(html: str, expected_name_hint: str) -> None:
elements, eph, obs, advanced = split_project_pluto_output(html, obs_code="X93")
rows = parse_ephemeris_table_for_ui(eph)
assert rows, "No ephemeris rows were parsed."
first = rows[0]
assert first.get("utc"), "UTC was not parsed."
assert first.get("ra"), "RA was not parsed."
assert first.get("dec"), "Dec was not parsed."
assert first.get("mag"), "Magnitude was not parsed."
assert first.get("elong"), "Elongation was not parsed."
# These columns were added after the Find_Orb-local migration.
assert "rate" in first, "Apparent motion rate column is missing."
assert "motion_pa" in first, "Motion PA column is missing."
combined_text = "\n".join([elements, eph, obs, advanced])
assert expected_name_hint in combined_text, f"Object name hint {expected_name_hint!r} not found."
# Basic sanity checks: values should be displayable and not blank.
for i, row in enumerate(rows[:3], start=1):
assert row.get("ra"), f"Row {i}: missing RA"
assert row.get("dec"), f"Row {i}: missing Dec"
assert row.get("mag"), f"Row {i}: missing mag"
def test_parse_neocp_fixture() -> None:
html = _load_fixture("project_pluto_A11D0Xd.html")
_assert_common_parse_ok(html, "A11D0Xd")
def test_parse_known_object_fixture() -> None:
html = _load_fixture("project_pluto_99942.html")
_assert_common_parse_ok(html, "99942")
def main() -> None:
test_parse_neocp_fixture()
print("OK: NEOCP fixture parsed")
test_parse_known_object_fixture()
print("OK: known-object fixture parsed")
print("All parser regression tests passed.")
if __name__ == "__main__":
main()