Initial import of DxDesigner part replacement tool (r21)
This commit is contained in:
commit
ffe066cb1e
151 files changed
+58745
No files matched your search
@@ -0,0 +1,75 @@
|
||||
from dataclasses import FrozenInstanceError
|
||||
from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
|
||||
from dx_productivity.part_replace.models import (
|
||||
ComponentSnapshot,
|
||||
DesignSnapshot,
|
||||
Issue,
|
||||
MappingRule,
|
||||
PinSnapshot,
|
||||
ProjectState,
|
||||
Scope,
|
||||
UnitSnapshot,
|
||||
)
|
||||
|
||||
|
||||
def test_snapshot_model_is_immutable_and_decimal_exact() -> None:
|
||||
pin = PinSnapshot(number="1", name="A", x=Decimal("10.25"), y=Decimal("20"), net="N$1")
|
||||
unit = UnitSnapshot(
|
||||
unit_id="u1", sheet="/MAIN", symbol="res.1",
|
||||
origin_x=Decimal("0"), origin_y=Decimal("0"), x=Decimal("0"),
|
||||
y=Decimal("0"), rotation=0, mirrored=False, pins=(pin,),
|
||||
)
|
||||
component = ComponentSnapshot(logical_key="/MAIN|R1", refdes="R1",
|
||||
part_number="OLD-1", units=(unit,), attributes=())
|
||||
snapshot = DesignSnapshot(format_version=2, project_id="p1", project_path="C:/P/a.prj",
|
||||
fingerprint="abc", components=(component,))
|
||||
with pytest.raises(FrozenInstanceError):
|
||||
snapshot.project_id = "p2" # type: ignore[misc]
|
||||
assert snapshot.components[0].units[0].pins[0].x == Decimal("10.25")
|
||||
|
||||
|
||||
def test_unit_keeps_origin_coordinates_distinct_from_position() -> None:
|
||||
# Catches collapsing the symbol origin into the placed x/y coordinates.
|
||||
unit = UnitSnapshot(
|
||||
unit_id="u1",
|
||||
sheet="/MAIN",
|
||||
symbol="res.1",
|
||||
origin_x=Decimal("1.25"),
|
||||
origin_y=Decimal("2.5"),
|
||||
x=Decimal("100"),
|
||||
y=Decimal("200"),
|
||||
rotation=0,
|
||||
mirrored=False,
|
||||
)
|
||||
|
||||
assert (unit.origin_x, unit.origin_y, unit.x, unit.y) == (
|
||||
Decimal("1.25"),
|
||||
Decimal("2.5"),
|
||||
Decimal("100"),
|
||||
Decimal("200"),
|
||||
)
|
||||
|
||||
|
||||
def test_state_and_scope_values_are_protocol_stable() -> None:
|
||||
assert Scope.FULL_PROJECT.value == "full_project"
|
||||
assert ProjectState.AWAITING_SAVE_CONFIRMATION.value == "awaiting_save_confirmation"
|
||||
assert MappingRule("OLD", "NEW").old_part_number == "OLD"
|
||||
|
||||
|
||||
def test_nested_records_are_normalized_to_immutable_sorted_tuples() -> None:
|
||||
snapshot = ComponentSnapshot(
|
||||
logical_key="k", refdes="R1", part_number="P",
|
||||
units=[], attributes={"z": "2", "a": "1"},
|
||||
)
|
||||
assert snapshot.units == ()
|
||||
assert snapshot.attributes == (("a", "1"), ("z", "2"))
|
||||
|
||||
|
||||
def test_issue_details_do_not_retain_mutable_inner_entries() -> None:
|
||||
issue = Issue("bad", "blocking", "Invalid data", [["field", "value"]]) # type: ignore[arg-type]
|
||||
assert issue.details == (("field", "value"),)
|
||||
with pytest.raises(TypeError):
|
||||
issue.details[0][0] = "changed" # type: ignore[index]
|
||||
Reference in new issue
Block a user