|
1 | 1 | import datetime as dt
|
2 |
| -import struct |
3 | 2 | import json
|
4 | 3 | from unittest import mock
|
5 | 4 |
|
|
8 | 7 |
|
9 | 8 | from dbt.adapters.sqlserver.sql_server_connection_manager import (
|
10 | 9 | bool_to_connection_string_arg,
|
| 10 | + byte_array_to_datetime, |
11 | 11 | get_pyodbc_attrs_before,
|
12 |
| - byte_array_to_datetime |
13 | 12 | )
|
14 | 13 | from dbt.adapters.sqlserver.sql_server_credentials import SQLServerCredentials
|
15 | 14 |
|
@@ -79,35 +78,52 @@ def test_get_pyodbc_attrs_before_contains_access_token_key_for_cli_authenticatio
|
79 | 78 | def test_bool_to_connection_string_arg(key: str, value: bool, expected: str) -> None:
|
80 | 79 | assert bool_to_connection_string_arg(key, value) == expected
|
81 | 80 |
|
| 81 | + |
82 | 82 | @pytest.mark.parametrize(
|
83 |
| - "value, expected_datetime, expected_str", [ |
| 83 | + "value, expected_datetime, expected_str", |
| 84 | + [ |
84 | 85 | (
|
85 |
| - bytes([ |
86 |
| - 0xE5, 0x07, # 2022 year unsigned short |
87 |
| - 0x0C, 0x00, # 12 month unsigned short |
88 |
| - 0x11, 0x00, # 17 day unsigned short |
89 |
| - 0x16, 0x00, # 17 hour unsigned short |
90 |
| - 0x16, 0x00, # 52 minute unsigned short |
91 |
| - 0x12, 0x00, # 18 second unsigned short |
92 |
| - 0xBC, 0xCC, 0x5B, 0x07, # 123456700 10⁻⁷ second unsigned long |
93 |
| - 0xFE, 0xFF, # -2 offset hour signed short |
94 |
| - 0xE2, 0xFF # -30 offset minute signed short |
95 |
| - ]), |
| 86 | + bytes( |
| 87 | + [ |
| 88 | + 0xE5, |
| 89 | + 0x07, # 2022 year unsigned short |
| 90 | + 0x0C, |
| 91 | + 0x00, # 12 month unsigned short |
| 92 | + 0x11, |
| 93 | + 0x00, # 17 day unsigned short |
| 94 | + 0x16, |
| 95 | + 0x00, # 17 hour unsigned short |
| 96 | + 0x16, |
| 97 | + 0x00, # 52 minute unsigned short |
| 98 | + 0x12, |
| 99 | + 0x00, # 18 second unsigned short |
| 100 | + 0xBC, |
| 101 | + 0xCC, |
| 102 | + 0x5B, |
| 103 | + 0x07, # 123456700 10⁻⁷ second unsigned long |
| 104 | + 0xFE, |
| 105 | + 0xFF, # -2 offset hour signed short |
| 106 | + 0xE2, |
| 107 | + 0xFF, # -30 offset minute signed short |
| 108 | + ] |
| 109 | + ), |
96 | 110 | dt.datetime(
|
97 | 111 | year=2022,
|
98 | 112 | month=12,
|
99 | 113 | day=17,
|
100 | 114 | hour=17,
|
101 | 115 | minute=52,
|
102 | 116 | second=18,
|
103 |
| - microsecond=123456700 // 1000, # 10⁻⁶ second |
104 |
| - tzinfo=dt.timezone(dt.timedelta(hours=-2, minutes=-30)) |
| 117 | + microsecond=123456700 // 1000, # 10⁻⁶ second |
| 118 | + tzinfo=dt.timezone(dt.timedelta(hours=-2, minutes=-30)), |
105 | 119 | ),
|
106 |
| - "2021-12-17 17:52:18.123456-02:30" |
| 120 | + "2021-12-17 17:52:18.123456-02:30", |
107 | 121 | )
|
108 |
| - ] |
| 122 | + ], |
109 | 123 | )
|
110 |
| -def test_byte_array_to_datetime(value: bytes, expected_datetime: dt.datetime, expected_str: str) -> None: |
| 124 | +def test_byte_array_to_datetime( |
| 125 | + value: bytes, expected_datetime: dt.datetime, expected_str: str |
| 126 | +) -> None: |
111 | 127 | """
|
112 | 128 | Assert SQL_SS_TIMESTAMPOFFSET_STRUCT bytes are converted to datetime and str
|
113 | 129 | https://learn.microsoft.com/sql/relational-databases/native-client-odbc-date-time/data-type-support-for-odbc-date-and-time-improvements#sql_ss_timestampoffset_struct
|
|
0 commit comments