Skip to content

Added label feature for the techui.yaml#216

Open
adedamola-sode wants to merge 1 commit intomainfrom
use-labels
Open

Added label feature for the techui.yaml#216
adedamola-sode wants to merge 1 commit intomainfrom
use-labels

Conversation

@adedamola-sode
Copy link
Copy Markdown
Collaborator

The changes include adding fields labels and child labels to techui.yaml components, which get passed as into the component models and entities. Then from entities, we get generated screens that take into consideration the child labels for the names of the screens, and also the main label instead of a key of components in the yaml file. After the screens are generated, the generate_json_map uses a new function _get_labels to fetch the labels from the techui.yaml, and places them where needed, taking precedence before what is already in the screens.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2026

Codecov Report

❌ Patch coverage is 95.74468% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.76%. Comparing base (663300c) to head (4fdc247).

Files with missing lines Patch % Lines
src/techui_builder/builder.py 92.85% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #216      +/-   ##
==========================================
+ Coverage   94.66%   94.76%   +0.09%     
==========================================
  Files          10       10              
  Lines         825      859      +34     
==========================================
+ Hits          781      814      +33     
- Misses         44       45       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@adedamola-sode adedamola-sode marked this pull request as ready for review May 5, 2026 10:36
@adedamola-sode adedamola-sode requested a review from OCopping May 5, 2026 14:00
suffix = ""
suffix_label = ""

# Try to get name from child labels if they exist,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small gripe, but the indentation here is wrong 😅

Comment on lines +181 to +185
if (
name.removeprefix(":").removesuffix(":")
in component.child_labels.keys()
):
name = component.child_labels[name.removeprefix(":").removesuffix(":")]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is reused, it would be tidier to put it in a temporary variable, e.g.

Suggested change
if (
name.removeprefix(":").removesuffix(":")
in component.child_labels.keys()
):
name = component.child_labels[name.removeprefix(":").removesuffix(":")]
clean_name = name.removeprefix(":").removesuffix(":")
if raw_name in component.child_labels.keys():
name = component.child_labels[clean_name]

height, width = self._get_group_dimensions(self.widgets)

if (
screen_name in self.components
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
screen_name in self.components
screen_name in self.components.keys()

Comment thread tests/conftest.py

@pytest.fixture
def generator():
def generator(builder: Builder):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer we didn't pass the Builder fixture into the Generator fixture. Can you make a mock components dict instead? Or even make a fixture that returns a mock components list as I think this is used elsewhere too

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I am trying to use the test-services techui-yaml, is it fine if I have the components fixture take in builder instead? Since that's how it's also done in the actual codebase?

Comment thread tests/test_builder.py

test_json_map = builder_with_test_files._generate_json_map(
screen_path.absolute(), dest_path
screen_path.absolute(), dest_path, builder_with_test_files.conf.components
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread tests/test_builder.py
Comment on lines +488 to +517
def test_get_labels(builder_with_test_files):
display_name = _get_labels(
"motor",
builder_with_test_files.conf.components,
None,
None,
)
assert display_name == "Motor Stage"


def test_get_labels_child_labels(builder_with_test_files):
display_name = _get_labels(
"X",
builder_with_test_files.conf.components,
current_component_name="motor",
display_name="X",
)
assert display_name == "X1"


def test_get_labels_child_labels_with_name_already_pregenerated(
builder_with_test_files,
):
display_name = _get_labels(
"X1",
builder_with_test_files.conf.components,
current_component_name="motor",
display_name="X",
)
assert display_name == "X1"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread tests/test_generate.py
Comment on lines +374 to +375
generator._get_group_dimensions = Mock(return_value=(600, 400))
generator.build_groups(screen_name)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor tidiness adjustment 😅

Suggested change
generator._get_group_dimensions = Mock(return_value=(600, 400))
generator.build_groups(screen_name)
generator._get_group_dimensions = Mock(return_value=(600, 400))
generator.build_groups(screen_name)

Comment thread tests/test_generate.py
Comment on lines +392 to +393
generator._get_group_dimensions = Mock(return_value=(600, 400))
generator.build_groups(screen_name)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
generator._get_group_dimensions = Mock(return_value=(600, 400))
generator.build_groups(screen_name)
generator._get_group_dimensions = Mock(return_value=(600, 400))
generator.build_groups(screen_name)

or existing display_name if name_elem is None.
"""
if name_elem is not None:
if name_elem in component.keys() and component[name_elem].label is not None:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write a test for if name_elem exists but it isn't in component.keys()?

if name_elem is not None:
if name_elem in component.keys() and component[name_elem].label is not None:
display_name = component[name_elem].label
elif current_component_name is not None and (
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the indentation here is wrong maybe? Also can you write a test for if current_component_name isn't None but it isn't in the component dict?

reverting an unnecessary change

modified generate_tests for coverage

generate_test coverage

Removed unneeded prints and logs
continue
self.widgets.append(new_widget)

def build_groups(self, screen_name: str):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of creating a new class var for self.components, why not do a similar thing to build_wdiegst() where screen_components is passed in from builder?
You would need to rework the logic below to work for a list, or would have to refactor the code in create_screens() in builder.py to be a dict

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants