- 
                Notifications
    You must be signed in to change notification settings 
- Fork 115
test(controller): Add test for controller documentation coverage #2035
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
      
      
    
  
     Merged
                    Changes from 5 commits
      Commits
    
    
            Show all changes
          
          
            12 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      dd66a04
              
                Add test for controller documentation coverage
              
              
                karangattu 07dd42f
              
                Update docs and tests for new controller classes
              
              
                karangattu f5c74d5
              
                Remove test for documented class name format
              
              
                karangattu c4c2b48
              
                Refactor controller documentation test logic
              
              
                karangattu 863ea54
              
                Add timeout handling for cell editing state checks
              
              
                karangattu 5191764
              
                Simplify cell editing logic in DataFrame output and test
              
              
                karangattu 5bbb4ed
              
                Remove unnecessary blank line in OutputDataFrame
              
              
                karangattu 4ae6a63
              
                Remove unused timeout argument in test
              
              
                karangattu a806e28
              
                Add comment clarifying edit mode test step
              
              
                karangattu 8f648b0
              
                Improve row selection validation in edit mode test
              
              
                karangattu e23962f
              
                cosmetic
              
              
                schloerke e6629a4
              
                cosmetic
              
              
                schloerke 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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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,98 @@ | ||
| import ast | ||
| from pathlib import Path | ||
| from typing import Set | ||
|  | ||
| import pytest | ||
| import yaml | ||
|  | ||
| CONTROLLER_DIR = Path("shiny/playwright/controller") | ||
| DOCS_CONFIG = Path("docs/_quartodoc-testing.yml") | ||
| SKIP_PATTERNS = {"Base", "Container", "Label", "StyleM"} | ||
| CONTROLLER_BASE_PATTERNS = { | ||
| "Base", | ||
| "Container", | ||
| "Label", | ||
| "StyleM", | ||
| "WidthLocM", | ||
| "InputActionButton", | ||
| "UiBase", | ||
| "UiWithLabel", | ||
| "UiWithContainer", | ||
| } | ||
|  | ||
|  | ||
| def _is_valid_controller_class(node: ast.ClassDef) -> bool: | ||
| class_name = node.name | ||
| base_names = {ast.unparse(base) for base in node.bases} | ||
|  | ||
| return ( | ||
| not class_name.startswith("_") | ||
| and not any(pattern in class_name for pattern in SKIP_PATTERNS) | ||
| and not any(base.endswith("P") for base in base_names if isinstance(base, str)) | ||
| and any( | ||
| base.startswith("_") or any(p in base for p in CONTROLLER_BASE_PATTERNS) | ||
| for base in base_names | ||
| ) | ||
| ) | ||
|  | ||
|  | ||
| def get_controller_classes() -> Set[str]: | ||
| classes: Set[str] = set() | ||
| for py_file in CONTROLLER_DIR.glob("*.py"): | ||
| if py_file.name == "__init__.py": | ||
| continue | ||
| try: | ||
| tree = ast.parse(py_file.read_text(encoding="utf-8")) | ||
| classes.update( | ||
| node.name | ||
| for node in ast.walk(tree) | ||
| if isinstance(node, ast.ClassDef) and _is_valid_controller_class(node) | ||
| ) | ||
| except Exception as e: | ||
| pytest.fail(f"Failed to parse {py_file}: {e}") | ||
| return classes | ||
|  | ||
|  | ||
| def get_documented_controllers() -> Set[str]: | ||
| try: | ||
| config = yaml.safe_load(DOCS_CONFIG.read_text(encoding="utf-8")) | ||
| except Exception as e: | ||
| pytest.fail(f"Failed to load or parse {DOCS_CONFIG}: {e}") | ||
|  | ||
| return { | ||
| content.split(".")[-1] | ||
| for section in config.get("quartodoc", {}).get("sections", []) | ||
| for content in section.get("contents", []) | ||
| if isinstance(content, str) and content.startswith("playwright.controller.") | ||
| } | ||
|  | ||
|  | ||
| def test_all_controllers_are_documented(): | ||
| controller_classes = get_controller_classes() | ||
| documented_controllers = get_documented_controllers() | ||
|  | ||
| missing_from_docs = controller_classes - documented_controllers | ||
| extra_in_docs = documented_controllers - controller_classes | ||
|  | ||
| from typing import List | ||
|  | ||
| error_messages: List[str] = [] | ||
| if missing_from_docs: | ||
| missing_list = "\n".join( | ||
| sorted(f" - playwright.controller.{c}" for c in missing_from_docs) | ||
| ) | ||
| error_messages.append( | ||
| f"Controllers missing from {DOCS_CONFIG}:\n{missing_list}" | ||
| ) | ||
|  | ||
| if extra_in_docs: | ||
| extra_list = "\n".join( | ||
| sorted(f" - playwright.controller.{c}" for c in extra_in_docs) | ||
| ) | ||
| error_messages.append(f"Extraneous classes in {DOCS_CONFIG}:\n{extra_list}") | ||
|  | ||
| if error_messages: | ||
| pytest.fail("\n\n".join(error_messages), pytrace=False) | ||
|  | ||
| assert controller_classes, "No controller classes were found." | ||
| assert documented_controllers, "No documented controllers were found." | 
      
      Oops, something went wrong.
        
    
  
  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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.