Feat: add export functionality with GUI for data and graphs
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
- Implemented ExportWindow class for exporting data and graphs in various formats (JSON, XML, PDF). - Integrated ExportManager to handle export logic. - Added export option in the main application menu. - Enhanced user interface with data summary and export options. - Included error handling and success messages for export operations. - Updated dependencies in the lock file to include reportlab and lxml for PDF generation.
This commit is contained in:
61
scripts/README.md
Normal file
61
scripts/README.md
Normal file
@@ -0,0 +1,61 @@
|
||||
# TheChart Scripts Directory
|
||||
|
||||
This directory contains testing and utility scripts for TheChart application.
|
||||
|
||||
## Scripts Overview
|
||||
|
||||
### Testing Scripts
|
||||
|
||||
#### `run_tests.py`
|
||||
Main test runner for the application.
|
||||
```bash
|
||||
cd /home/will/Code/thechart
|
||||
.venv/bin/python scripts/run_tests.py
|
||||
```
|
||||
|
||||
#### `integration_test.py`
|
||||
Comprehensive integration test for the export system.
|
||||
- Tests all export formats (JSON, XML, PDF)
|
||||
- Validates data integrity and file creation
|
||||
- No GUI dependencies - safe for automated testing
|
||||
|
||||
```bash
|
||||
cd /home/will/Code/thechart
|
||||
.venv/bin/python scripts/integration_test.py
|
||||
```
|
||||
|
||||
### Feature Testing Scripts
|
||||
|
||||
#### `test_note_saving.py`
|
||||
Tests note saving and retrieval functionality.
|
||||
- Validates note persistence in CSV files
|
||||
- Tests special characters and formatting
|
||||
|
||||
#### `test_update_entry.py`
|
||||
Tests entry update functionality.
|
||||
- Validates data modification operations
|
||||
- Tests date validation and duplicate handling
|
||||
|
||||
## Usage
|
||||
|
||||
All scripts should be run from the project root directory:
|
||||
|
||||
```bash
|
||||
cd /home/will/Code/thechart
|
||||
.venv/bin/python scripts/<script_name>.py
|
||||
```
|
||||
|
||||
## Test Data
|
||||
|
||||
- Integration tests create temporary export files in `integration_test_exports/` (auto-cleaned)
|
||||
- Test scripts use the main `thechart_data.csv` file unless specified otherwise
|
||||
- No test data is committed to the repository
|
||||
|
||||
## Development
|
||||
|
||||
When adding new scripts:
|
||||
1. Place them in this directory
|
||||
2. Use the standard shebang: `#!/usr/bin/env python3`
|
||||
3. Add proper docstrings and error handling
|
||||
4. Update this README with script documentation
|
||||
5. Follow the project's linting and formatting standards
|
||||
128
scripts/integration_test.py
Normal file
128
scripts/integration_test.py
Normal file
@@ -0,0 +1,128 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Integration test for TheChart export system
|
||||
Tests the complete export workflow without GUI dependencies
|
||||
"""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add src to path
|
||||
sys.path.insert(0, "src")
|
||||
|
||||
from data_manager import DataManager
|
||||
from export_manager import ExportManager
|
||||
from init import logger
|
||||
from medicine_manager import MedicineManager
|
||||
from pathology_manager import PathologyManager
|
||||
|
||||
|
||||
class MockGraphManager:
|
||||
"""Mock graph manager for testing."""
|
||||
|
||||
def __init__(self):
|
||||
self.fig = None
|
||||
|
||||
|
||||
def test_integration():
|
||||
"""Test complete export system integration."""
|
||||
print("TheChart Export System Integration Test")
|
||||
print("=" * 45)
|
||||
|
||||
# 1. Initialize all managers
|
||||
print("\n1. Initializing managers...")
|
||||
try:
|
||||
medicine_manager = MedicineManager(logger=logger)
|
||||
pathology_manager = PathologyManager(logger=logger)
|
||||
data_manager = DataManager(
|
||||
"thechart_data.csv", logger, medicine_manager, pathology_manager
|
||||
)
|
||||
|
||||
# Mock graph manager (no GUI dependencies)
|
||||
graph_manager = MockGraphManager()
|
||||
|
||||
export_manager = ExportManager(
|
||||
data_manager, graph_manager, medicine_manager, pathology_manager, logger
|
||||
)
|
||||
print(" ✓ All managers initialized successfully")
|
||||
except Exception as e:
|
||||
print(f" ✗ Manager initialization failed: {e}")
|
||||
return False
|
||||
|
||||
# 2. Check data availability
|
||||
print("\n2. Checking data availability...")
|
||||
try:
|
||||
export_info = export_manager.get_export_info()
|
||||
print(f" Total entries: {export_info['total_entries']}")
|
||||
print(f" Has data: {export_info['has_data']}")
|
||||
|
||||
if not export_info["has_data"]:
|
||||
print(" ✗ No data available for export")
|
||||
return False
|
||||
|
||||
print(
|
||||
f" Date range: {export_info['date_range']['start']} "
|
||||
f"to {export_info['date_range']['end']}"
|
||||
)
|
||||
print(f" Pathologies: {len(export_info['pathologies'])}")
|
||||
print(f" Medicines: {len(export_info['medicines'])}")
|
||||
print(" ✓ Data is available for export")
|
||||
except Exception as e:
|
||||
print(f" ✗ Data check failed: {e}")
|
||||
return False
|
||||
|
||||
# 3. Test all export formats
|
||||
export_dir = Path("integration_test_exports")
|
||||
export_dir.mkdir(exist_ok=True)
|
||||
|
||||
formats_to_test = [
|
||||
("JSON", "integration_test.json", export_manager.export_data_to_json),
|
||||
("XML", "integration_test.xml", export_manager.export_data_to_xml),
|
||||
(
|
||||
"PDF",
|
||||
"integration_test.pdf",
|
||||
lambda path: export_manager.export_to_pdf(path, include_graph=False),
|
||||
),
|
||||
]
|
||||
|
||||
results = []
|
||||
|
||||
for format_name, filename, export_func in formats_to_test:
|
||||
print(f"\n3.{len(results) + 1}. Testing {format_name} export...")
|
||||
try:
|
||||
file_path = export_dir / filename
|
||||
success = export_func(str(file_path))
|
||||
|
||||
if success and file_path.exists():
|
||||
file_size = file_path.stat().st_size
|
||||
print(
|
||||
f" ✓ {format_name} export successful: {filename} "
|
||||
f"({file_size} bytes)"
|
||||
)
|
||||
results.append(True)
|
||||
else:
|
||||
print(f" ✗ {format_name} export failed")
|
||||
results.append(False)
|
||||
|
||||
except Exception as e:
|
||||
print(f" ✗ {format_name} export error: {e}")
|
||||
results.append(False)
|
||||
|
||||
# 4. Summary
|
||||
print("\n4. Test Summary")
|
||||
print(f" Total tests: {len(results)}")
|
||||
print(f" Passed: {sum(results)}")
|
||||
print(f" Failed: {len(results) - sum(results)}")
|
||||
|
||||
if all(results):
|
||||
print(" ✓ All export formats working correctly!")
|
||||
print(f" Check '{export_dir}' directory for exported files.")
|
||||
return True
|
||||
else:
|
||||
print(" ✗ Some export formats failed")
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = test_integration()
|
||||
sys.exit(0 if success else 1)
|
||||
Reference in New Issue
Block a user