|
1 |
| -from datetime import timezone |
| 1 | +from datetime import datetime, timezone |
2 | 2 |
|
3 | 3 | import pytest
|
4 | 4 | from fastapi import HTTPException
|
@@ -86,31 +86,49 @@ def test_parse_valid_str_to_datetime(test_input):
|
86 | 86 |
|
87 | 87 |
|
88 | 88 | @pytest.mark.parametrize("test_input", invalid_intervals)
|
89 |
| -def test_parse_invalid_interval_to_datetime(test_input): |
| 89 | +def test_str_to_interval_with_invalid_interval(test_input): |
90 | 90 | with pytest.raises(HTTPException) as exc_info:
|
91 | 91 | str_to_interval(test_input)
|
92 | 92 | assert (
|
93 | 93 | exc_info.value.status_code == 400
|
94 |
| - ), "Should return a 400 status code for invalid intervals" |
| 94 | + ), "str_to_interval should return a 400 status code for invalid interval" |
95 | 95 |
|
96 | 96 |
|
97 |
| -@pytest.mark.parametrize("test_input", valid_intervals) |
98 |
| -def test_parse_valid_interval_to_datetime(test_input): |
99 |
| - assert str_to_interval(test_input) |
| 97 | +@pytest.mark.parametrize("test_input", invalid_datetimes) |
| 98 | +def test_str_to_interval_with_invalid_datetime(test_input): |
| 99 | + with pytest.raises(HTTPException) as exc_info: |
| 100 | + str_to_interval(test_input) |
| 101 | + assert ( |
| 102 | + exc_info.value.status_code == 400 |
| 103 | + ), "str_to_interval should return a 400 status code for invalid datetime" |
100 | 104 |
|
101 | 105 |
|
102 |
| -def test_now_functions() -> None: |
103 |
| - now1 = now_in_utc() |
104 |
| - now2 = now_in_utc() |
| 106 | +@pytest.mark.parametrize("test_input", valid_intervals) |
| 107 | +def test_str_to_interval_with_valid_interval(test_input): |
| 108 | + assert isinstance( |
| 109 | + str_to_interval(test_input), tuple |
| 110 | + ), "str_to_interval should return tuple for multi-value input" |
105 | 111 |
|
106 |
| - assert now1 < now2 |
107 |
| - assert now1.tzinfo == timezone.utc |
108 | 112 |
|
109 |
| - rfc3339_str_to_datetime(now_to_rfc3339_str()) |
| 113 | +@pytest.mark.parametrize("test_input", valid_datetimes) |
| 114 | +def test_str_to_interval_with_valid_datetime(test_input): |
| 115 | + assert isinstance( |
| 116 | + str_to_interval(test_input), datetime |
| 117 | + ), "str_to_interval should return single datetime for single-value input" |
110 | 118 |
|
111 | 119 |
|
112 | 120 | def test_str_to_interval_with_none():
|
113 | 121 | """Test that str_to_interval returns None when provided with None."""
|
114 | 122 | assert (
|
115 | 123 | str_to_interval(None) is None
|
116 | 124 | ), "str_to_interval should return None when input is None"
|
| 125 | + |
| 126 | + |
| 127 | +def test_now_functions() -> None: |
| 128 | + now1 = now_in_utc() |
| 129 | + now2 = now_in_utc() |
| 130 | + |
| 131 | + assert now1 < now2 |
| 132 | + assert now1.tzinfo == timezone.utc |
| 133 | + |
| 134 | + rfc3339_str_to_datetime(now_to_rfc3339_str()) |
0 commit comments