Skip to content

Commit 1c008a4

Browse files
committed
test: force a non-UTC timezone for the naive datetime case
1 parent dac8de3 commit 1c008a4

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

‎tests/slack_sdk/oauth/installation_store/test_internals.py‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import os
12
import sys
3+
import time
24
import unittest
35
from datetime import datetime, timezone
6+
from unittest import mock
47

58
import pytest
69

@@ -25,7 +28,6 @@ def test_iso_format(self):
2528
[
2629
(1701209097, int, 1701209097),
2730
(datetime(2023, 11, 28, 22, 9, 7, tzinfo=timezone.utc), int, 1701209347),
28-
(datetime(2023, 11, 28, 22, 9, 7), int, 1701209347),
2931
("1701209605", int, 1701209605),
3032
("2023-11-28 22:11:19", int, 1701209479),
3133
(1701209998.3429494, float, 1701209998.3429494),
@@ -39,6 +41,16 @@ def test_timestamp_to_type(ts, target_type, expected_result):
3941
assert result == expected_result
4042

4143

44+
@pytest.mark.skipif(not hasattr(time, "tzset"), reason="time.tzset is not available on this platform")
45+
def test_timestamp_to_type_naive_datetime_is_utc():
46+
try:
47+
with mock.patch.dict(os.environ, {"TZ": "America/New_York"}):
48+
time.tzset()
49+
assert _timestamp_to_type(datetime(2023, 11, 28, 22, 9, 7), int) == 1701209347
50+
finally:
51+
time.tzset()
52+
53+
4254
def test_timestamp_to_type_invalid_str():
4355
match = "Invalid isoformat string"
4456
with pytest.raises(ValueError, match=match):

0 commit comments

Comments
 (0)