Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
6.8 KiB
6.8 KiB
Testing Guide
This document provides a comprehensive guide to testing in TheChart application.
Test Organization
Directory Structure
thechart/
├── tests/ # Unit tests (pytest)
│ ├── test_theme_manager.py
│ ├── test_data_manager.py
│ ├── test_ui_manager.py
│ ├── test_graph_manager.py
│ └── ...
├── scripts/ # Integration tests & demos
│ ├── integration_test.py
│ ├── test_menu_theming.py
│ ├── test_note_saving.py
│ └── ...
Test Categories
1. Unit Tests (/tests/)
Purpose: Test individual components in isolation
Framework: pytest
Location: /tests/ directory
Running Unit Tests
cd /home/will/Code/thechart
source .venv/bin/activate.fish
python -m pytest tests/
Available Unit Tests
test_theme_manager.py- Theme system and menu themingtest_data_manager.py- Data persistence and CSV operationstest_ui_manager.py- UI component functionalitytest_graph_manager.py- Graph generation and displaytest_constants.py- Application constantstest_logger.py- Logging systemtest_main.py- Main application logic
Writing Unit Tests
# Example unit test structure
import unittest
import sys
import os
# Add src to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))
from your_module import YourClass
class TestYourClass(unittest.TestCase):
def setUp(self):
"""Set up test fixtures."""
pass
def tearDown(self):
"""Clean up after tests."""
pass
def test_functionality(self):
"""Test specific functionality."""
pass
2. Integration Tests (/scripts/)
Purpose: Test complete workflows and system interactions
Framework: Custom test scripts
Location: /scripts/ directory
Available Integration Tests
integration_test.py
Comprehensive export system test:
- Tests JSON, XML, PDF export formats
- Validates data integrity
- Tests file creation and cleanup
- No GUI dependencies
.venv/bin/python scripts/integration_test.py
test_note_saving.py
Note persistence functionality:
- Tests note saving to CSV
- Validates special character handling
- Tests note retrieval
test_update_entry.py
Entry modification functionality:
- Tests data update operations
- Validates date handling
- Tests duplicate prevention
test_keyboard_shortcuts.py
Keyboard shortcut system:
- Tests key binding functionality
- Validates shortcut responses
- Tests keyboard event handling
3. Interactive Demonstrations (/scripts/)
Purpose: Visual and interactive testing of UI features Framework: tkinter-based demos
test_menu_theming.py
Interactive menu theming demonstration:
- Live theme switching
- Visual color display
- Real-time menu updates
.venv/bin/python scripts/test_menu_theming.py
Running Tests
Complete Test Suite
cd /home/will/Code/thechart
source .venv/bin/activate.fish
# Run unit tests
python -m pytest tests/ -v
# Run integration tests
python scripts/integration_test.py
# Run specific feature tests
python scripts/test_note_saving.py
python scripts/test_update_entry.py
Individual Test Categories
# Unit tests only
python -m pytest tests/
# Specific unit test file
python -m pytest tests/test_theme_manager.py -v
# Integration test
python scripts/integration_test.py
# Interactive demo
python scripts/test_menu_theming.py
Test Runner Script
# Use the main test runner
python scripts/run_tests.py
Test Environment Setup
Prerequisites
- Virtual Environment: Ensure
.venvis activated - Dependencies: All requirements installed via
uv - Test Data: Main
thechart_data.csvfile present
Environment Activation
# Fish shell
source .venv/bin/activate.fish
# Bash/Zsh
source .venv/bin/activate
Writing New Tests
Unit Test Guidelines
- Place in
/tests/directory - Use pytest framework
- Follow naming convention:
test_<module_name>.py - Include setup/teardown for fixtures
- Test edge cases and error conditions
Integration Test Guidelines
- Place in
/scripts/directory - Test complete workflows
- Include cleanup procedures
- Document expected behavior
- Handle GUI dependencies appropriately
Interactive Demo Guidelines
- Place in
/scripts/directory - Include clear instructions
- Provide visual feedback
- Allow easy theme/feature switching
- Include exit mechanisms
Test Data Management
Test File Creation
- Use
tempfilemodule for temporary files - Clean up created files in teardown
- Don't commit test data to repository
CSV Test Data
- Most tests use main
thechart_data.csv - Some tests create temporary CSV files
- Integration tests may create export directories
Continuous Integration
Local Testing Workflow
# 1. Run linting
python -m flake8 src/ tests/ scripts/
# 2. Run unit tests
python -m pytest tests/ -v
# 3. Run integration tests
python scripts/integration_test.py
# 4. Run specific feature tests as needed
python scripts/test_note_saving.py
Pre-commit Checklist
- All unit tests pass
- Integration tests pass
- New functionality has tests
- Documentation updated
- Code follows style guidelines
Troubleshooting
Common Issues
Import Errors
# Ensure src is in path
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))
GUI Test Issues
- Use
root.withdraw()to hide test windows - Ensure proper cleanup with
root.destroy() - Consider mocking GUI components for unit tests
File Permission Issues
- Ensure test has write permissions
- Use temporary directories for test files
- Clean up files in teardown methods
Debug Mode
# Run with debug logging
python -c "import logging; logging.basicConfig(level=logging.DEBUG)" scripts/test_script.py
Test Coverage
Current Coverage Areas
- ✅ Theme management and menu theming
- ✅ Data persistence and CSV operations
- ✅ Export functionality (JSON, XML, PDF)
- ✅ UI component initialization
- ✅ Graph generation
- ✅ Note saving and retrieval
- ✅ Entry update operations
- ✅ Keyboard shortcuts
Areas for Expansion
- Medicine and pathology management
- Settings persistence
- Error handling edge cases
- Performance testing
- UI interaction testing
Contributing Tests
When contributing new tests:
- Choose the right category: Unit vs Integration vs Demo
- Follow naming conventions: Clear, descriptive names
- Include documentation: Docstrings and comments
- Test edge cases: Not just happy path
- Clean up resources: Temporary files, windows, etc.
- Update documentation: Add to this guide and scripts/README.md