Files
TinyTorch/.github/scripts/validate_testing_patterns.py
Vijay Janapa Reddi 9c0042f08d Add release check workflow and clean up legacy dev files
This commit implements a comprehensive quality assurance system and removes
outdated backup files from the repository.

## Release Check Workflow

Added GitHub Actions workflow for systematic release validation:
- Manual-only workflow (workflow_dispatch) - no automatic PR triggers
- 6 sequential quality gates: educational, implementation, testing, package, documentation, systems
- 13 validation scripts (4 fully implemented, 9 stubs for future work)
- Comprehensive documentation in .github/workflows/README.md
- Release process guide in .github/RELEASE_PROCESS.md

Implemented validators:
- validate_time_estimates.py - Ensures consistency between LEARNING_PATH.md and ABOUT.md files
- validate_difficulty_ratings.py - Validates star rating consistency across modules
- validate_testing_patterns.py - Checks for test_unit_* and test_module() patterns
- check_checkpoints.py - Recommends checkpoint markers for long modules (8+ hours)

## Pedagogical Improvements

Added checkpoint markers to Module 05 (Autograd):
- Checkpoint 1: After computational graph construction (~40% progress)
- Checkpoint 2: After automatic differentiation implementation (~80% progress)
- Helps students track progress through the longest foundational module (8-10 hours)

## Codebase Cleanup

Removed 20 legacy *_dev.py files across all modules:
- Confirmed via export system analysis: only *.py files (without _dev suffix) are used
- Export system explicitly reads from {name}.py (see tito/commands/export.py line 461)
- All _dev.py files were outdated backups not used by the build/export pipeline
- Verified all active .py files contain current implementations with optimizations

This cleanup:
- Eliminates confusion about which files are source of truth
- Reduces repository size
- Makes development workflow clearer (work in modules/XX_name/name.py)

## Formatting Standards Documentation

Documents formatting and style standards discovered through systematic
review of all 20 TinyTorch modules.

### Key Findings

Overall Status: 9/10 (Excellent consistency)
- All 20 modules use correct test_module() naming
- 18/20 modules have proper if __name__ guards
- All modules use proper Jupytext format (no JSON leakage)
- Strong ASCII diagram quality
- All 20 modules missing 🧪 emoji in test_module() docstrings

### Standards Documented

1. Test Function Naming: test_unit_* for units, test_module() for integration
2. if __name__ Guards: Immediate guards after every test/analysis function
3. Emoji Protocol: 🔬 for unit tests, 🧪 for module tests, 📊 for analysis
4. Markdown Formatting: Jupytext format with proper section hierarchy
5. ASCII Diagrams: Box-drawing characters, labeled dimensions, data flow arrows
6. Module Structure: Standard template with 9 sections

### Quick Fixes Identified

- Add 🧪 emoji to test_module() in all 20 modules (~5 min)
- Fix Module 16 if __name__ guards (~15 min)
- Fix Module 08 guard (~5 min)

Total quick fixes: 25 minutes to achieve 10/10 consistency
2025-11-24 14:47:04 -05:00

96 lines
2.7 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Validate testing patterns in module development files.
Ensures:
- Unit tests use test_unit_* naming
- Module integration test is named test_module()
- Tests are protected with if __name__ == "__main__"
"""
import re
import sys
from pathlib import Path
def check_module_tests(module_file):
"""Check testing patterns in a module file"""
content = module_file.read_text()
issues = []
# Check for test_unit_* pattern
unit_tests = re.findall(r'def\s+(test_unit_\w+)\s*\(', content)
# Check for test_module() function
has_test_module = bool(re.search(r'def\s+test_module\s*\(', content))
# Check for if __name__ == "__main__" blocks
has_main_guard = bool(re.search(r'if\s+__name__\s*==\s*["\']__main__["\']', content))
# Check for improper test names (test_* but not test_unit_*)
improper_tests = [
name for name in re.findall(r'def\s+(test_\w+)\s*\(', content)
if not name.startswith('test_unit_') and name != 'test_module'
]
# Validate patterns
if not unit_tests and not has_test_module:
issues.append("No tests found (missing test_unit_* or test_module)")
if not has_test_module:
issues.append("Missing test_module() integration test")
if not has_main_guard:
issues.append("Missing if __name__ == '__main__' guard")
if improper_tests:
issues.append(f"Improper test names (should be test_unit_*): {', '.join(improper_tests)}")
return {
'unit_tests': len(unit_tests),
'has_test_module': has_test_module,
'has_main_guard': has_main_guard,
'issues': issues
}
def main():
"""Validate testing patterns across all modules"""
modules_dir = Path("modules")
errors = []
warnings = []
print("🧪 Validating Testing Patterns")
print("=" * 60)
# Find all module development files
module_files = sorted(modules_dir.glob("*/*_dev.py"))
for module_file in module_files:
module_name = module_file.parent.name
result = check_module_tests(module_file)
if result['issues']:
errors.append(f"{module_name}:")
for issue in result['issues']:
errors.append(f" - {issue}")
else:
print(f"{module_name}: {result['unit_tests']} unit tests + test_module()")
print("\n" + "=" * 60)
# Print errors
if errors:
print("\n❌ Testing Pattern Issues:")
for error in errors:
print(f" {error}")
print(f"\n{len([e for e in errors if '' in e])} modules with testing issues!")
sys.exit(1)
else:
print("\n✅ All modules follow correct testing patterns!")
sys.exit(0)
if __name__ == "__main__":
main()