|
1 | 1 | import pytest |
2 | 2 | import uuid |
3 | | -import warnings |
4 | 3 | from datetime import timedelta, datetime, timezone |
5 | 4 | from unittest.mock import AsyncMock, Mock, PropertyMock |
6 | 5 |
|
@@ -266,50 +265,28 @@ async def test_build_request_with_first_run_at_timezone_aware(self, mock_client) |
266 | 265 | tzinfo=None |
267 | 266 | ) # ToDatetime returns naive UTC |
268 | 267 |
|
269 | | - @pytest.mark.asyncio |
270 | | - async def test_build_request_with_first_run_at_naive(self, mock_client): |
271 | | - """Test building request with timezone-naive first_run_at.""" |
272 | | - client = Client(domain="test-domain", target="localhost:7933") |
273 | | - |
274 | | - first_run = datetime(2024, 6, 1, 12, 0, 0) # Naive datetime |
275 | | - |
276 | | - options = StartWorkflowOptions( |
277 | | - task_list="test-task-list", |
278 | | - execution_start_to_close_timeout=timedelta(minutes=10), |
279 | | - task_start_to_close_timeout=timedelta(seconds=30), |
280 | | - first_run_at=first_run, |
281 | | - ) |
282 | | - |
283 | | - request = client._build_start_workflow_request("TestWorkflow", (), options) |
284 | | - |
285 | | - assert request.HasField("first_run_at") |
286 | | - |
287 | | - def test_first_run_at_naive_datetime_warns(self): |
288 | | - """Test that timezone-naive first_run_at produces warning.""" |
| 268 | + def test_first_run_at_naive_datetime_raises_error(self): |
| 269 | + """Test that timezone-naive first_run_at raises ValueError.""" |
289 | 270 | options = StartWorkflowOptions( |
290 | 271 | task_list="test-task-list", |
291 | 272 | execution_start_to_close_timeout=timedelta(minutes=10), |
292 | 273 | first_run_at=datetime(2024, 1, 1, 12, 0, 0), # Naive |
293 | 274 | ) |
294 | | - with pytest.warns(UserWarning, match="timezone-naive"): |
| 275 | + with pytest.raises(ValueError, match="must be timezone-aware"): |
295 | 276 | _validate_and_apply_defaults(options) |
296 | 277 |
|
297 | | - def test_first_run_at_aware_datetime_no_warning(self): |
298 | | - """Test that timezone-aware first_run_at produces no warning.""" |
| 278 | + def test_first_run_at_aware_datetime_is_valid(self): |
| 279 | + """Test that timezone-aware first_run_at is valid.""" |
299 | 280 | options = StartWorkflowOptions( |
300 | 281 | task_list="test-task-list", |
301 | 282 | execution_start_to_close_timeout=timedelta(minutes=10), |
302 | 283 | first_run_at=datetime(2024, 1, 1, 12, 0, 0, tzinfo=timezone.utc), |
303 | 284 | ) |
304 | | - # Should not warn - use warnings.catch_warnings to verify |
305 | | - with warnings.catch_warnings(record=True) as w: |
306 | | - warnings.simplefilter("always") |
307 | | - _validate_and_apply_defaults(options) |
308 | | - # Filter for our specific warning |
309 | | - relevant_warnings = [ |
310 | | - warning for warning in w if "timezone-naive" in str(warning.message) |
311 | | - ] |
312 | | - assert len(relevant_warnings) == 0 |
| 285 | + # Should not raise |
| 286 | + validated = _validate_and_apply_defaults(options) |
| 287 | + assert validated["first_run_at"] == datetime( |
| 288 | + 2024, 1, 1, 12, 0, 0, tzinfo=timezone.utc |
| 289 | + ) |
313 | 290 |
|
314 | 291 | def test_first_run_at_before_epoch_raises_error(self): |
315 | 292 | """Test that first_run_at before Unix epoch raises ValueError.""" |
|
0 commit comments