- 
                Notifications
    
You must be signed in to change notification settings  - Fork 35
 
Fix array based conversion of display labels for obsolete format #7434
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
          
     Merged
      
      
            ogenstad
  merged 1 commit into
  release-1.5
from
pog-array-based-conversion-display-labels
  
      
      
   
  Oct 31, 2025 
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
  
    
      
          
            103 changes: 103 additions & 0 deletions
          
          103 
        
  backend/tests/unit/core/schema/schema_branch/test_schema_convert_display_labels.py
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| from dataclasses import dataclass | ||
| 
     | 
||
| import pytest | ||
| 
     | 
||
| from infrahub.core.schema import AttributeSchema, NodeSchema, SchemaRoot | ||
| from infrahub.core.schema.schema_branch import SchemaBranch | ||
| 
     | 
||
| 
     | 
||
| @dataclass | ||
| class DisplayLabelTestCase: | ||
| name: str | ||
| schema_root: SchemaRoot | ||
| display_label: str | ||
| 
     | 
||
| 
     | 
||
| DISPLAY_LABEL_TEST_CASES: list[DisplayLabelTestCase] = [ | ||
| DisplayLabelTestCase( | ||
| name="single_attribute_label_no_value", | ||
| schema_root=SchemaRoot( | ||
| nodes=[ | ||
| NodeSchema( | ||
| name="Widget", | ||
| namespace="Test", | ||
| attributes=[AttributeSchema(name="name", kind="Text"), AttributeSchema(name="status", kind="Text")], | ||
| display_labels=["name"], | ||
| ) | ||
| ] | ||
| ), | ||
| display_label="name__value", | ||
| ), | ||
| DisplayLabelTestCase( | ||
| name="single_attribute_label_with_value", | ||
| schema_root=SchemaRoot( | ||
| nodes=[ | ||
| NodeSchema( | ||
| name="Widget", | ||
| namespace="Test", | ||
| attributes=[AttributeSchema(name="name", kind="Text"), AttributeSchema(name="status", kind="Text")], | ||
| display_labels=["name__value"], | ||
| ) | ||
| ] | ||
| ), | ||
| display_label="name__value", | ||
| ), | ||
| DisplayLabelTestCase( | ||
| name="dual_attribute_label_no_value", | ||
| schema_root=SchemaRoot( | ||
| nodes=[ | ||
| NodeSchema( | ||
| name="Widget", | ||
| namespace="Test", | ||
| attributes=[AttributeSchema(name="name", kind="Text"), AttributeSchema(name="status", kind="Text")], | ||
| display_labels=["name", "status"], | ||
| ) | ||
| ] | ||
| ), | ||
| display_label="{{ name__value }} {{ status__value }}", | ||
| ), | ||
| DisplayLabelTestCase( | ||
| name="dual_attribute_label_mixed_value", | ||
| schema_root=SchemaRoot( | ||
| nodes=[ | ||
| NodeSchema( | ||
| name="Widget", | ||
| namespace="Test", | ||
| attributes=[AttributeSchema(name="name", kind="Text"), AttributeSchema(name="status", kind="Text")], | ||
| display_labels=["name__value", "status"], | ||
| ) | ||
| ] | ||
| ), | ||
| display_label="{{ name__value }} {{ status__value }}", | ||
| ), | ||
| DisplayLabelTestCase( | ||
| name="defined_display_label", | ||
| schema_root=SchemaRoot( | ||
| nodes=[ | ||
| NodeSchema( | ||
| name="Widget", | ||
| namespace="Test", | ||
| attributes=[AttributeSchema(name="name", kind="Text"), AttributeSchema(name="status", kind="Text")], | ||
| display_labels=["name__value", "status"], | ||
| display_label="{{ name__value|upper }}: {{ status__value|lower }}", | ||
| ) | ||
| ] | ||
| ), | ||
| display_label="{{ name__value|upper }}: {{ status__value|lower }}", | ||
| ), | ||
| ] | ||
| 
     | 
||
| 
     | 
||
| @pytest.mark.parametrize( | ||
| "test_case", | ||
| [pytest.param(tc, id=tc.name) for tc in DISPLAY_LABEL_TEST_CASES], | ||
| ) | ||
| async def test_expected_final_display_label( | ||
| test_case: DisplayLabelTestCase, | ||
| ) -> None: | ||
| """Test that the final computed display label matches the expected value.""" | ||
| schema_branch = SchemaBranch(cache={}, name="test") | ||
| schema_branch.load_schema(schema=test_case.schema_root) | ||
| schema_branch.process() | ||
| node = schema_branch.get_node(name="TestWidget", duplicate=False) | ||
| assert node.display_label == test_case.display_label | ||
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good pattern. easy to read
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree we have it in a few places and I think we should do more of it. Especially for pytest.params with multiple variables.