""" Unit tests for utility functions """ import pytest from datetime import datetime from drt.utils.timestamps import format_timestamp, format_duration from drt.utils.patterns import matches_pattern class TestTimestamps: """Test timestamp utilities""" def test_format_timestamp(self): """Test timestamp formatting""" dt = datetime(2024, 1, 15, 14, 30, 45) formatted = format_timestamp(dt) assert formatted == "20240115_143045" def test_format_timestamp_current(self): """Test formatting current timestamp""" formatted = format_timestamp() # Should be in YYYYMMDD_HHMMSS format assert len(formatted) == 15 assert formatted[8] == "_" def test_format_duration_seconds(self): """Test duration formatting for seconds""" duration = format_duration(45.5) assert duration == "45.50s" def test_format_duration_minutes(self): """Test duration formatting for minutes""" duration = format_duration(125.0) assert duration == "2m 5.00s" def test_format_duration_hours(self): """Test duration formatting for hours""" duration = format_duration(3725.0) assert duration == "1h 2m 5.00s" class TestPatterns: """Test pattern matching utilities""" def test_exact_match(self): """Test exact pattern matching""" assert matches_pattern("TestTable", "TestTable") is True assert matches_pattern("TestTable", "OtherTable") is False def test_wildcard_star(self): """Test wildcard * pattern""" assert matches_pattern("TestTable", "Test*") is True assert matches_pattern("TestTable", "*Table") is True assert matches_pattern("TestTable", "*est*") is True assert matches_pattern("TestTable", "Other*") is False def test_wildcard_question(self): """Test wildcard ? pattern""" assert matches_pattern("Test1", "Test?") is True assert matches_pattern("TestA", "Test?") is True assert matches_pattern("Test12", "Test?") is False assert matches_pattern("Test", "Test?") is False def test_combined_wildcards(self): """Test combined wildcard patterns""" assert matches_pattern("Test_Table_01", "Test_*_??") is True assert matches_pattern("Test_Table_1", "Test_*_??") is False def test_case_sensitivity(self): """Test case-sensitive matching""" assert matches_pattern("TestTable", "testtable") is False assert matches_pattern("TestTable", "TestTable") is True def test_empty_pattern(self): """Test empty pattern""" assert matches_pattern("TestTable", "") is False assert matches_pattern("", "") is True def test_special_characters(self): """Test patterns with special characters""" assert matches_pattern("Test.Table", "Test.Table") is True assert matches_pattern("Test_Table", "Test_*") is True assert matches_pattern("Test-Table", "Test-*") is True