STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_probes_on_lines.py
Go to the documentation of this file.
1"""A probe clipped to a line reads the line.
2
3pid-designer clips an RTD, a TC or a load cell to a tank, a valve *or a line*
4(its ``attach.ts``): on a line ``attachedTo`` is the line's id and
5``attachedAt`` the fraction of its drawn length from the source end. The twin
6resolved a clip only against symbols, so a probe on a line read nothing and was
7reported "not clipped to anything" -- and with the cart cut (``ignore_gse``)
8it was dropped from the vehicle without a word.
9"""
10
11from __future__ import annotations
12
13import copy
14import json
15from pathlib import Path
16from typing import Any
17
18import pytest
19
20from feedtwin.pid import build_network, read_diagram
21from feedtwin.pid.roles import vehicle_ids
22from feedtwin.session import assemble_model
23
24DRAWING = Path(__file__).resolve().parent / "fixtures" / "le4_rocket_and_gse.json"
25LINE = "node_38-node_36" # FM-R to the engine
26PROBE = "node_30" # OX-RTD-1, drawn on the LOX tank
27
28
29def _on_the_line(at: float | None) -> Any:
30 payload = copy.deepcopy(json.loads(DRAWING.read_text()))
31 for node in payload["nodes"]:
32 if node["id"] == PROBE:
33 node["data"]["attachedTo"] = LINE
34 node["data"].pop("attachedAt", None)
35 if at is not None:
36 node["data"]["attachedAt"] = at
37 return payload
38
39
40def _reads(built: Any) -> str | None:
41 return next((i.node for i in built.instruments if i.id == PROBE), None)
42
43
44@pytest.mark.parametrize(("at", "end"), [(0.2, "upstream"), (0.8, "downstream")])
46 at: float, end: str
47) -> None:
48 built = build_network(read_diagram(_on_the_line(at), name="LE4"))
49 line = built.network.branches[LINE]
50 assert _reads(built) == getattr(line, end)
51 assert not [w for w in built.warnings if "OX-RTD-1" in w], built.warnings
52
53
55 """Saved before ``attachedAt`` existed: drawn at the line's middle."""
56 built = build_network(read_diagram(_on_the_line(None), name="LE4"))
57 assert _reads(built) in {
58 built.network.branches[LINE].upstream,
59 built.network.branches[LINE].downstream,
60 }
61
62
64 diagram = read_diagram(_on_the_line(0.5), name="LE4")
65 vehicle = vehicle_ids(diagram)
66 assert vehicle is not None and PROBE in vehicle
67 model = assemble_model(diagram, diagram_id="le4", vehicle_only=True)
68 assert any(n.id == PROBE for n in model.diagram.nodes)
69 assert _reads(model.built) is not None
70 assert not [w for w in model.report.warnings if "OX-RTD-1" in w]
71
72
74 built = build_network(read_diagram(json.loads(DRAWING.read_text()), name="LE4"))
75 tank = built.tanks["node_22"]
76 assert _reads(built) in {tank.ullage, tank.outlet}
None test_a_probe_on_a_vehicle_line_stays_with_the_vehicle()
None test_a_probe_on_a_line_with_no_position_reads_it()
str|None _reads(Any built)
None test_a_probe_on_a_line_reads_the_end_it_is_clipped_nearer(float at, str end)
Any _on_the_line(float|None at)
None test_a_probe_on_a_symbol_reads_as_before()