STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_two_vehicles.py
Go to the documentation of this file.
1"""One drawing, one vehicle.
2
3pid-designer's Duplicate page is offered for "another version of the same stand
4-- the hotfire and the launch configuration". It keeps every tag, and its
5duplicate-tag check is per page, so the copy passes there. The twin builds every
6page into one network: LE4 with its Rocket page duplicated built as two rockets
7sharing seven signals, no valve bound, and Fire sat at 0 N with no message.
8"""
9
10from __future__ import annotations
11
12import copy
13import json
14from pathlib import Path
15from typing import Any
16
17import pytest
18
19from feedtwin.pid import build_network, read_diagram
20from feedtwin.session import assemble_model
21from feedtwin.session.model import AssemblyError
22
23DRAWING = Path(__file__).resolve().parent / "fixtures" / "le4_rocket_and_gse.json"
24
25
26def _payload() -> Any:
27 return json.loads(DRAWING.read_text())
28
29
30def _duplicated(page: str = "Rocket", copy_name: str = "Rocket (copy)") -> Any:
31 """``page`` copied as duplicatePage does: fresh ids, tags kept, pairs and
32 clips inside the page remapped."""
33 payload = _payload()
34 on = {n["id"] for n in payload["nodes"] if n["data"].get("page") == page}
35 fresh = {i: f"{i}_copy" for i in on}
36 nodes, edges = [], []
37 for node in payload["nodes"]:
38 if node["id"] not in on:
39 continue
40 twin = copy.deepcopy(node)
41 twin["id"] = fresh[node["id"]]
42 twin["data"]["page"] = copy_name
43 options = twin["data"].get("options") or {}
44 if options.get("pairedWith") in fresh:
45 options["pairedWith"] = fresh[options["pairedWith"]]
46 if twin["data"].get("attachedTo") in fresh:
47 twin["data"]["attachedTo"] = fresh[twin["data"]["attachedTo"]]
48 nodes.append(twin)
49 for edge in payload["edges"]:
50 if edge["source"] in on and edge["target"] in on:
51 twin = copy.deepcopy(edge)
52 twin["id"] = f"{edge['id']}_copy"
53 twin["source"], twin["target"] = (
54 fresh[edge["source"]],
55 fresh[edge["target"]],
56 )
57 edges.append(twin)
58 payload["nodes"] += nodes
59 payload["edges"] += edges
60 return payload
61
62
63@pytest.mark.parametrize("cut", [False, True])
65 diagram = read_diagram(_duplicated(), name="LE4 (6)")
66 with pytest.raises(AssemblyError) as refused:
67 assemble_model(diagram, diagram_id="le4", vehicle_only=cut)
68 said = str(refused.value)
69 assert "2 separate vehicles" in said
70 assert "page Rocket" in said and "page Rocket (copy)" in said
71
72
74 built = build_network(read_diagram(_payload(), name="LE4 (6)"))
75 assert not [w for w in built.warnings if "is the tag of" in w]
76
77
79 """A copied cart page has one engine, so it builds -- and the solenoids it
80 copied answer one signal between them, which is worth a line."""
81 payload = _duplicated("GSE", "GSE (copy)")
82 built = build_network(read_diagram(payload, name="LE4 (6)"))
83 shared = [w for w in built.warnings if "is the tag of 2 valves" in w]
84 assert shared, built.warnings
85 assert any("GSE and GSE (copy)" in w for w in shared)
None test_two_versions_of_the_rocket_are_refused_and_the_pages_named(bool cut)
None test_the_drawing_with_one_rocket_builds()
Any _duplicated(str page="Rocket", str copy_name="Rocket (copy)")
None test_a_tag_two_driven_valves_share_is_said()