Files
ETPlot/tests/test_focused_coverage.py
T
2025-09-08 10:52:58 +02:00

135 lines
4.2 KiB
Python

"""
Focused coverage test - tests actual functions without container dependencies
"""
import unittest
import tempfile
import os
import sys
from pathlib import Path
# Add project root to path
sys.path.insert(0, str(Path(__file__).parent.parent))
class TestActualFunctions(unittest.TestCase):
"""Test actual functions for coverage analysis."""
def setUp(self):
"""Set up test environment."""
self.test_dir = tempfile.mkdtemp()
def tearDown(self):
"""Clean up test environment."""
import shutil
shutil.rmtree(self.test_dir, ignore_errors=True)
def test_config_loading(self):
"""Test configuration loading."""
from orchestration.config import Config
# Create a test config file
config_content = """
title: "Test Gallery"
description: "Test gallery for coverage"
output_dir: "output"
"""
config_file = os.path.join(self.test_dir, "test_config.yaml")
with open(config_file, 'w') as f:
f.write(config_content)
# Test loading
config = Config.from_yaml(config_file)
self.assertEqual(config.title, "Test Gallery")
self.assertEqual(config.description, "Test gallery for coverage")
def test_metadata_functions(self):
"""Test metadata functions."""
from orchestration.metadata import load_metadata_file, merge_metadata
# Create test metadata
metadata_content = """
title: "Test Plot"
author: "Test Author"
date: "2025-01-01"
"""
metadata_file = os.path.join(self.test_dir, "metadata.yaml")
with open(metadata_file, 'w') as f:
f.write(metadata_content)
# Test loading
metadata = load_metadata_file(metadata_file)
self.assertEqual(metadata['title'], "Test Plot")
self.assertEqual(metadata['author'], "Test Author")
# Test merging
base_meta = {'title': 'Base', 'type': 'plot'}
override_meta = {'title': 'Override', 'new_field': 'value'}
merged = merge_metadata(base_meta, override_meta)
self.assertEqual(merged['title'], 'Override') # Override wins
self.assertEqual(merged['type'], 'plot') # Base preserved
self.assertEqual(merged['new_field'], 'value') # New field added
def test_logger_creation(self):
"""Test logger creation."""
from orchestration.logger import create_logger, GalleryLogger
# Test creating a logger
logger = create_logger("test_logger")
self.assertIsNotNone(logger)
# Test GalleryLogger
gallery_logger = GalleryLogger("test_gallery")
self.assertIsNotNone(gallery_logger)
def test_file_operations(self):
"""Test file operation utilities."""
# Create test files
old_file = os.path.join(self.test_dir, "old.txt")
new_file = os.path.join(self.test_dir, "new.txt")
# Create old file first
with open(old_file, 'w') as f:
f.write("old content")
# Wait a moment then create new file
import time
time.sleep(0.1)
with open(new_file, 'w') as f:
f.write("new content")
# Test file modification times
old_stat = os.stat(old_file)
new_stat = os.stat(new_file)
self.assertLess(old_stat.st_mtime, new_stat.st_mtime)
def test_path_operations(self):
"""Test path and directory operations."""
test_path = Path(self.test_dir)
# Test path exists
self.assertTrue(test_path.exists())
self.assertTrue(test_path.is_dir())
# Create subdirectory
subdir = test_path / "subdir"
subdir.mkdir()
self.assertTrue(subdir.exists())
self.assertTrue(subdir.is_dir())
# Create file in subdir
test_file = subdir / "test.txt"
test_file.write_text("test content")
self.assertTrue(test_file.exists())
self.assertTrue(test_file.is_file())
self.assertEqual(test_file.read_text(), "test content")
if __name__ == '__main__':
unittest.main()