Skip to content

Commit 76ce14a

Browse files
committed
adding another test
1 parent 4ddc11f commit 76ce14a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/test_004_cursor.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8123,6 +8123,40 @@ def test_datetimeoffset_extreme_offsets(cursor, db_connection):
81238123
finally:
81248124
cursor.execute("IF OBJECT_ID('tempdb..#pytest_dto', 'U') IS NOT NULL DROP TABLE #pytest_dto;")
81258125
db_connection.commit()
8126+
8127+
def test_datetimeoffset_native_vs_string_simple(cursor, db_connection):
8128+
"""
8129+
Replicates the user's testing scenario: fetch DATETIMEOFFSET as native datetime
8130+
and as string using CONVERT(nvarchar(35), ..., 121).
8131+
"""
8132+
try:
8133+
cursor.execute("CREATE TABLE #pytest_dto_user_test (id INT PRIMARY KEY, Systime DATETIMEOFFSET);")
8134+
db_connection.commit()
8135+
8136+
# Insert rows similar to user's example
8137+
test_rows = [
8138+
(1, datetime(2025, 5, 14, 12, 35, 52, 501000, tzinfo=timezone(timedelta(hours=1)))),
8139+
(2, datetime(2025, 5, 14, 15, 20, 30, 123000, tzinfo=timezone(timedelta(hours=-5))))
8140+
]
8141+
8142+
for i, dt in test_rows:
8143+
cursor.execute("INSERT INTO #pytest_dto_user_test (id, Systime) VALUES (?, ?);", i, dt)
8144+
db_connection.commit()
8145+
8146+
# Native fetch (like the user's first execute)
8147+
cursor.execute("SELECT Systime FROM #pytest_dto_user_test WHERE id=1;")
8148+
dt_native = cursor.fetchone()[0]
8149+
assert dt_native.tzinfo is not None
8150+
assert dt_native == test_rows[0][1]
8151+
8152+
# String fetch (like the user's convert to nvarchar)
8153+
cursor.execute("SELECT CONVERT(nvarchar(35), Systime, 121) FROM #pytest_dto_user_test WHERE id=1;")
8154+
dt_str = cursor.fetchone()[0]
8155+
assert dt_str.endswith("+01:00") # original offset preserved
8156+
8157+
finally:
8158+
cursor.execute("DROP TABLE IF EXISTS #pytest_dto_user_test;")
8159+
db_connection.commit()
81268160

81278161
def test_lowercase_attribute(cursor, db_connection):
81288162
"""Test that the lowercase attribute properly converts column names to lowercase"""

0 commit comments

Comments
 (0)