""" Tests for owilix.core.manager.logging module Tests for DBLog transaction logging system. """ import tempfile import pytest class TestDBLog: """Tests for DBLog transaction logging system.""" @pytest.fixture def temp_log_dir(self): """Create temporary directory for test logs.""" with tempfile.TemporaryDirectory() as tmpdir: yield tmpdir def test_dblog_initialization(self, temp_log_dir): """Test DBLog can be initialized.""" from owilix.core.manager.logging import DBLog dblog = DBLog("test_job", temp_log_dir) assert dblog is not None assert dblog.job_name == "test_job" def test_dblog_register_dataset(self, temp_log_dir): """Test registering a dataset.""" from owilix.core.manager.logging import DBLog dblog = DBLog("test_job", temp_log_dir) dataset_id = dblog.register_dataset("/path/to/dataset") assert dataset_id is not None assert isinstance(dataset_id, str) assert len(dataset_id) == 16 # SHA256 truncated to 16 chars def test_dblog_register_files(self, temp_log_dir): """Test registering files for processing.""" from owilix.core.manager.logging import DBLog dblog = DBLog("test_job", temp_log_dir) # API expects (file_path, dataset_path) tuples files = [ ("/path/to/file1.parquet", "/path/to/dataset"), ("/path/to/file2.parquet", "/path/to/dataset"), ] dblog.register_files(files) stats = dblog.get_statistics() assert stats["file_status_counts"].get("pending", 0) == 2 def test_dblog_mark_success(self, temp_log_dir): """Test marking files as successfully processed.""" from owilix.core.manager.logging import DBLog dblog = DBLog("test_job", temp_log_dir) files = [("/path/to/file1.parquet", "/path/to/dataset")] dblog.register_files(files) dblog.mark_files_success(["/path/to/file1.parquet"]) processed = dblog.get_processed_files() assert "/path/to/file1.parquet" in processed def test_dblog_mark_error(self, temp_log_dir): """Test marking files as failed.""" from owilix.core.manager.logging import DBLog dblog = DBLog("test_job", temp_log_dir) files = [("/path/to/file1.parquet", "/path/to/dataset")] dblog.register_files(files) error = ValueError("Test error") dblog.mark_files_error(["/path/to/file1.parquet"], error) stats = dblog.get_statistics() assert stats["file_status_counts"].get("error", 0) == 1 def test_dblog_get_statistics(self, temp_log_dir): """Test getting processing statistics.""" from owilix.core.manager.logging import DBLog dblog = DBLog("test_job", temp_log_dir) stats = dblog.get_statistics() assert "file_status_counts" in stats assert "dataset_statistics" in stats assert "error_type_counts" in stats class TestDBLogImport: """Test DBLog can be imported from manager package.""" def test_import_from_manager_logging(self): """Test import from manager.logging.""" from owilix.core.manager.logging import DBLog assert DBLog is not None