Improved front and rear port validation (#3798)
* Update definitions_test.py Improved Front and rear port validation * Fixed device --------- Co-authored-by: Harry <harry@cadby.co.uk>
This commit is contained in:
@@ -15,7 +15,7 @@ comments: '[BX750MI-GR Datasheet by Kolyan](https://www.apc.com/kz/ru/product/BX
|
||||
front-ports:
|
||||
- name: IN
|
||||
type: 8p8c
|
||||
rear_port: '1'
|
||||
rear_port: OUT
|
||||
rear_port_position: 1
|
||||
rear-ports:
|
||||
- name: OUT
|
||||
|
||||
@@ -193,6 +193,29 @@ def test_definitions(file_path, schema, change_type):
|
||||
# A module
|
||||
this_device = ModuleType(definition, file_path, change_type)
|
||||
|
||||
# Validate that front-ports reference existing rear-ports
|
||||
if this_device.isDevice:
|
||||
rear_ports = definition.get("rear-ports", []) or []
|
||||
front_ports = definition.get("front-ports", []) or []
|
||||
|
||||
rear_port_names = {
|
||||
rp.get("name") for rp in rear_ports if isinstance(rp, dict)
|
||||
}
|
||||
|
||||
for fp in front_ports:
|
||||
if not isinstance(fp, dict):
|
||||
continue
|
||||
|
||||
rear_port_ref = fp.get("rear_port")
|
||||
|
||||
if rear_port_ref and rear_port_ref not in rear_port_names:
|
||||
pytest.fail(
|
||||
f"{file_path}: front-port '{fp.get('name')}' references "
|
||||
f"rear_port '{rear_port_ref}', but no such rear-port exists. "
|
||||
f"Defined rear-ports: {sorted(rear_port_names)}",
|
||||
pytrace=False,
|
||||
)
|
||||
|
||||
# Verify the slug is valid, only if the definition type is a Device
|
||||
if this_device.isDevice:
|
||||
assert this_device.verify_slug(KNOWN_SLUGS), pytest.fail(this_device.failureMessage, False)
|
||||
|
||||
Reference in New Issue
Block a user