Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚙️ Added is_instance to branch attributes #399

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/vss_tools/vspec/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
resolve_datatype,
)

EXPORT_EXCLUDE_ATTRIBUTES = ["delete", "instantiate", "fqn", "arraysize", "aggregate"]
EXPORT_EXCLUDE_ATTRIBUTES = ["delete", "instantiate", "fqn", "arraysize", "aggregate", "is_instance"]


class ModelException(Exception):
Expand Down Expand Up @@ -117,6 +117,7 @@ def check_const_uid_format(cls, v: str) -> str:
class VSSDataBranch(VSSData):
instances: Any = None
aggregate: bool = False
is_instance: bool = False

@field_validator("instances")
@classmethod
Expand Down
2 changes: 2 additions & 0 deletions src/vss_tools/vspec/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ def expand_instance(
node = template.copy()
node.name = name
node.data.instances = [] # type: ignore
if isinstance(node.data, VSSDataBranch):
node.data.is_instance = True
node.parent = root
nodes.append(node)
node.children = []
Expand Down
13 changes: 13 additions & 0 deletions tests/vspec/test_isinstance/test.vspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Vehicle:
description: Vehicle
type: branch

Vehicle.Door:
description: Door
type: branch
instances:
- Row[1,2]

Vehicle.Door.Row1.Special:
description: Special
type: branch
26 changes: 26 additions & 0 deletions tests/vspec/test_isinstance/test_isinstance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (c) 2022 Contributors to COVESA
#
# This program and the accompanying materials are made available under the
# terms of the Mozilla Public License 2.0 which is available at
# https://www.mozilla.org/en-US/MPL/2.0/
#
# SPDX-License-Identifier: MPL-2.0

from pathlib import Path

from vss_tools.vspec.main import get_trees

HERE = Path(__file__).resolve().parent


def test_exporters():
tree, _ = get_trees(
vspec=HERE / "test.vspec",
)
door = tree.children[0]
row1 = door.children[0]
assert row1.data.is_instance
door.children[1]
assert row1.data.is_instance
special = row1.children[0]
assert not special.data.is_instance