Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
- Introduced `quick_test.py` for running specific test categories (unit, integration, theme, all). - Updated `run_tests.py` to improve test execution and reporting, including coverage. - Removed outdated test scripts for keyboard shortcuts, menu theming, note saving, and entry updating. - Added new test script `test_theme_changing.py` to verify theme changing functionality. - Consolidated integration tests into `test_integration.py` for comprehensive testing of TheChart application. - Updated theme manager to ensure color retrieval works correctly. - Modified test constants to import from the correct module path.
372 lines
10 KiB
Python
372 lines
10 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test migration script - consolidates old standalone test scripts.
|
|
This script helps migrate from the old testing structure to the new consolidated one.
|
|
"""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
|
|
def create_deprecated_notice():
|
|
"""Create a notice file about the test migration."""
|
|
notice = """# Test Scripts Migration Notice
|
|
|
|
## ⚠️ Important: Test Structure Changed
|
|
|
|
The individual test scripts in this directory have been **consolidated** into a unified
|
|
test suite.
|
|
|
|
### Old Structure (Deprecated)
|
|
- `test_note_saving.py`
|
|
- `test_update_entry.py`
|
|
- `test_keyboard_shortcuts.py`
|
|
- `test_theme_changing.py`
|
|
- `test_menu_theming.py`
|
|
|
|
### New Structure (Current)
|
|
All functionality is now in:
|
|
- `tests/test_integration.py` - Comprehensive integration tests
|
|
- `tests/test_*.py` - Unit tests for specific modules
|
|
- `scripts/run_tests.py` - Main test runner
|
|
- `scripts/quick_test.py` - Quick test runner for specific categories
|
|
|
|
### How to Run Tests
|
|
|
|
#### Run All Tests
|
|
```bash
|
|
cd /home/will/Code/thechart
|
|
.venv/bin/python scripts/run_tests.py
|
|
```
|
|
|
|
#### Run Specific Test Categories
|
|
```bash
|
|
# Unit tests only
|
|
.venv/bin/python scripts/quick_test.py unit
|
|
|
|
# Integration tests only
|
|
.venv/bin/python scripts/quick_test.py integration
|
|
|
|
# Theme-related tests only
|
|
.venv/bin/python scripts/quick_test.py theme
|
|
```
|
|
|
|
#### Run Individual Test Classes
|
|
```bash
|
|
# Run specific integration test
|
|
.venv/bin/python -m pytest tests/test_integration.py::TestIntegrationSuite::
|
|
test_theme_changing_functionality -v
|
|
|
|
# Run all theme manager tests
|
|
.venv/bin/python -m pytest tests/test_theme_manager.py -v
|
|
```
|
|
|
|
### Migration Benefits
|
|
1. **Unified Structure**: All tests use the same pytest framework
|
|
2. **Better Organization**: Related tests grouped together
|
|
3. **Improved Coverage**: Integrated coverage reporting
|
|
4. **Faster Execution**: Optimized test setup and teardown
|
|
5. **Better CI/CD**: Easier to integrate with automated testing
|
|
|
|
### Backwards Compatibility
|
|
The old `integration_test.py` script is still available and called by the new test
|
|
runner for backwards compatibility.
|
|
"""
|
|
|
|
notice_path = Path(__file__).parent / "TESTING_MIGRATION.md"
|
|
with open(notice_path, "w") as f:
|
|
f.write(notice)
|
|
|
|
print(f"Created migration notice: {notice_path}")
|
|
|
|
|
|
def rename_old_scripts():
|
|
"""Rename old test scripts to indicate they're deprecated."""
|
|
old_scripts = [
|
|
"test_note_saving.py",
|
|
"test_update_entry.py",
|
|
"test_keyboard_shortcuts.py",
|
|
"test_menu_theming.py",
|
|
]
|
|
|
|
scripts_dir = Path(__file__).parent
|
|
|
|
for script in old_scripts:
|
|
old_path = scripts_dir / script
|
|
if old_path.exists():
|
|
new_path = scripts_dir / f"deprecated_{script}"
|
|
old_path.rename(new_path)
|
|
print(f"Renamed {script} -> deprecated_{script}")
|
|
|
|
# Add deprecation notice to the file
|
|
with open(new_path) as f:
|
|
_content = f.read()
|
|
|
|
deprecation_notice = '''#!/usr/bin/env python3
|
|
"""
|
|
⚠️ DEPRECATED SCRIPT ⚠️
|
|
|
|
This script has been consolidated into the new unified test suite.
|
|
Please use the new testing structure instead:
|
|
|
|
For theme testing:
|
|
.venv/bin/python scripts/quick_test.py theme
|
|
|
|
For integration testing:
|
|
.venv/bin/python scripts/quick_test.py integration
|
|
|
|
For all tests:
|
|
.venv/bin/python scripts/run_tests.py
|
|
|
|
See TESTING_MIGRATION.md for full details.
|
|
"""
|
|
|
|
import sys
|
|
print("⚠️ This script is deprecated. Please use the new test structure.")
|
|
print("See TESTING_MIGRATION.md for migration instructions.")
|
|
sys.exit(1)
|
|
|
|
# Original script content below (preserved for reference):
|
|
# """ + content[content.find('"""'):] if '"""' in content else content + """
|
|
"""
|
|
|
|
'''
|
|
|
|
with open(new_path, "w") as f:
|
|
f.write(deprecation_notice)
|
|
|
|
|
|
def update_readme():
|
|
"""Update the scripts README to reflect the new structure."""
|
|
readme_path = Path(__file__).parent / "README.md"
|
|
|
|
if readme_path.exists():
|
|
# Backup original
|
|
backup_path = Path(__file__).parent / "README.md.backup"
|
|
readme_path.rename(backup_path)
|
|
print(f"Backed up original README to {backup_path}")
|
|
|
|
new_readme = """# TheChart Scripts Directory
|
|
|
|
This directory contains utility scripts and the **new consolidated test suite** for
|
|
TheChart application.
|
|
|
|
## 🚀 Quick Start
|
|
|
|
### Run All Tests
|
|
```bash
|
|
cd /home/will/Code/thechart
|
|
.venv/bin/python scripts/run_tests.py
|
|
```
|
|
|
|
### Run Specific Test Categories
|
|
```bash
|
|
# Unit tests only
|
|
.venv/bin/python scripts/quick_test.py unit
|
|
|
|
# Integration tests only
|
|
.venv/bin/python scripts/quick_test.py integration
|
|
|
|
# Theme-related tests only
|
|
.venv/bin/python scripts/quick_test.py theme
|
|
```
|
|
|
|
## 📁 Current Structure
|
|
|
|
### Active Scripts
|
|
|
|
#### `run_tests.py` 🎯
|
|
**Main test runner** - executes the complete test suite with coverage reporting.
|
|
- Runs unit tests with coverage
|
|
- Runs integration tests
|
|
- Runs legacy integration tests for backwards compatibility
|
|
- Provides comprehensive test summary
|
|
|
|
#### `quick_test.py` ⚡
|
|
**Quick test runner** - for specific test categories during development.
|
|
- `unit` - Fast unit tests only
|
|
- `integration` - Integration tests only
|
|
- `theme` - Theme-related functionality tests
|
|
- `all` - Complete test suite
|
|
|
|
#### `integration_test.py` 🔄
|
|
**Legacy integration test** - maintained for backwards compatibility.
|
|
- Tests export system functionality
|
|
- No GUI dependencies
|
|
- Called automatically by the main test runner
|
|
|
|
### Test Organization
|
|
|
|
#### Unit Tests (`/tests/`)
|
|
- `test_*.py` - Individual module tests
|
|
- Uses pytest framework
|
|
- Fast execution, isolated tests
|
|
- Coverage reporting enabled
|
|
|
|
#### Integration Tests (`tests/test_integration.py`)
|
|
- **Consolidated integration test suite**
|
|
- Tests complete workflows and interactions
|
|
- Includes functionality from old standalone scripts:
|
|
- Note saving and retrieval
|
|
- Entry updates and validation
|
|
- Theme changing functionality
|
|
- Keyboard shortcuts binding
|
|
- Menu theming integration
|
|
- Export system testing
|
|
- Data validation and error handling
|
|
|
|
## 🔄 Migration from Old Structure
|
|
|
|
The old individual test scripts have been **consolidated** into the unified test suite:
|
|
|
|
| Old Script | New Location | How to Run |
|
|
|------------|--------------|------------|
|
|
| `test_note_saving.py` | `tests/test_integration.py::test_note_saving_functionality` |
|
|
`quick_test.py integration` |
|
|
| `test_update_entry.py` | `tests/test_integration.py::test_entry_update_functionality`
|
|
| `quick_test.py integration` |
|
|
| `test_keyboard_shortcuts.py` | `tests/test_integration.py::
|
|
test_keyboard_shortcuts_binding` | `quick_test.py integration` |
|
|
| `test_theme_changing.py` | `tests/test_integration.py::
|
|
test_theme_changing_functionality` | `quick_test.py theme` |
|
|
| `test_menu_theming.py` | `tests/test_integration.py::test_menu_theming_integration` |
|
|
`quick_test.py theme` |
|
|
|
|
### Benefits of New Structure
|
|
1. **Unified Framework**: All tests use pytest
|
|
2. **Better Organization**: Related tests grouped logically
|
|
3. **Improved Performance**: Optimized setup/teardown
|
|
4. **Coverage Reporting**: Integrated coverage analysis
|
|
5. **CI/CD Ready**: Easier automation and integration
|
|
|
|
## 🛠️ Development Workflow
|
|
|
|
### During Development
|
|
```bash
|
|
# Quick unit tests (fastest feedback)
|
|
.venv/bin/python scripts/quick_test.py unit
|
|
|
|
# Test specific functionality
|
|
.venv/bin/python scripts/quick_test.py theme
|
|
```
|
|
|
|
### Before Commits
|
|
```bash
|
|
# Full test suite with coverage
|
|
.venv/bin/python scripts/run_tests.py
|
|
```
|
|
|
|
### Individual Test Debugging
|
|
```bash
|
|
# Run specific test with output
|
|
.venv/bin/python -m pytest tests/test_integration.py::TestIntegrationSuite::
|
|
test_theme_changing_functionality -v -s
|
|
|
|
# Run with debugger
|
|
.venv/bin/python -m pytest tests/test_integration.py::TestIntegrationSuite::
|
|
test_note_saving_functionality -v -s --pdb
|
|
```
|
|
|
|
## 📋 Available Test Categories
|
|
|
|
### Unit Tests
|
|
- Fast, isolated component tests
|
|
- Mock external dependencies
|
|
- Test individual functions and classes
|
|
|
|
### Integration Tests
|
|
- Test component interactions
|
|
- Test complete workflows
|
|
- Validate data persistence
|
|
- Test UI functionality (without GUI display)
|
|
|
|
### Theme Tests
|
|
- Theme switching functionality
|
|
- Color scheme validation
|
|
- Menu theming consistency
|
|
- Error handling in theme system
|
|
|
|
### System Health Checks
|
|
- Configuration file validation
|
|
- Manager initialization tests
|
|
- Logging system verification
|
|
|
|
## 🏃♂️ Performance Tips
|
|
|
|
- Use `quick_test.py unit` for fastest feedback during development
|
|
- Use `quick_test.py integration` to test workflow changes
|
|
- Use `quick_test.py theme` when working on UI/theming
|
|
- Use `run_tests.py` for comprehensive testing before commits
|
|
|
|
## 🔧 Debugging Tests
|
|
|
|
### Common Commands
|
|
```bash
|
|
# Run with verbose output
|
|
.venv/bin/python -m pytest tests/ -v
|
|
|
|
# Stop on first failure
|
|
.venv/bin/python -m pytest tests/ -x
|
|
|
|
# Show local variables on failure
|
|
.venv/bin/python -m pytest tests/ -l
|
|
|
|
# Run with debugger on failure
|
|
.venv/bin/python -m pytest tests/ --pdb
|
|
```
|
|
|
|
### Debugging Specific Issues
|
|
```bash
|
|
# Debug theme issues
|
|
.venv/bin/python -m pytest tests/test_integration.py::TestIntegrationSuite::
|
|
test_theme_changing_functionality -v -s
|
|
|
|
# Debug data management
|
|
.venv/bin/python -m pytest tests/test_data_manager.py -v -s
|
|
|
|
# Debug export functionality
|
|
.venv/bin/python scripts/integration_test.py
|
|
```
|
|
|
|
---
|
|
|
|
📖 **See Also**: `TESTING_MIGRATION.md` for detailed migration information.
|
|
"""
|
|
|
|
with open(readme_path, "w") as f:
|
|
f.write(new_readme)
|
|
|
|
print("Updated README.md with new test structure documentation")
|
|
|
|
|
|
def main():
|
|
"""Main migration function."""
|
|
print("TheChart Test Migration Script")
|
|
print("=" * 30)
|
|
|
|
# Change to scripts directory
|
|
scripts_dir = Path(__file__).parent
|
|
os.chdir(scripts_dir)
|
|
|
|
print("1. Creating migration notice...")
|
|
create_deprecated_notice()
|
|
|
|
print("2. Renaming old test scripts...")
|
|
rename_old_scripts()
|
|
|
|
print("3. Updating README...")
|
|
update_readme()
|
|
|
|
print("\n✅ Migration completed!")
|
|
print("\n📋 Summary:")
|
|
print(" • Created TESTING_MIGRATION.md with detailed instructions")
|
|
print(" • Renamed old test scripts to deprecated_*")
|
|
print(" • Updated README.md with new test structure")
|
|
print("\n🚀 Next steps:")
|
|
print(" • Run: .venv/bin/python scripts/run_tests.py")
|
|
print(" • Check: .venv/bin/python scripts/quick_test.py unit")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|