forked from snowflakedb/snowflake-connector-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_unit_converter.py
More file actions
72 lines (58 loc) · 1.9 KB
/
Copy pathtest_unit_converter.py
File metadata and controls
72 lines (58 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2012-2017 Snowflake Computing Inc. All right reserved.
#
from logging import getLogger
from snowflake.connector.compat import (PY_ISSUE_23517, TO_UNICODE)
from snowflake.connector.converter import SnowflakeConverter
from snowflake.connector.converter_issue23517 import (
SnowflakeConverterIssue23517)
from snowflake.connector.converter_snowsql import SnowflakeConverterSnowSQL
logger = getLogger(__name__)
Converter = SnowflakeConverter if not PY_ISSUE_23517 else \
SnowflakeConverterIssue23517
ConverterSnowSQL = SnowflakeConverterSnowSQL
def test_is_dst():
"""
SNOW-6020: Failed to convert to local time during DST is being
changed
"""
# DST to non-DST
conv = Converter()
conv.set_parameter('TIMEZONE', 'America/Los_Angeles')
col_meta = {
'name': 'CREATED_ON',
'type': 6,
'length': None,
'precision': None,
'scale': 3,
'nullable': True,
}
m = conv.to_python_method('TIMESTAMP_LTZ', col_meta)
ret = m('1414890189.000')
assert TO_UNICODE(ret) == u'2014-11-01 18:03:09-07:00', \
'Timestamp during from DST to non-DST'
# non-DST to DST
col_meta = {
'name': 'CREATED_ON',
'type': 6,
'length': None,
'precision': None,
'scale': 3,
'nullable': True,
}
m = conv.to_python_method('TIMESTAMP_LTZ', col_meta)
ret = m('1425780189.000')
assert TO_UNICODE(ret) == u'2015-03-07 18:03:09-08:00', \
'Timestamp during from non-DST to DST'
def test_more_timestamps():
col_meta_3 = {
'scale': 9
}
conv = ConverterSnowSQL()
conv.set_parameter('TIMESTAMP_NTZ_OUTPUT_FORMAT',
'YYYY-MM-DD HH24:MI:SS.FF9')
m = conv.to_python_method('TIMESTAMP_NTZ', col_meta_3)
ret = m('-2208943503.876543211')
assert ret == '1900-01-01 12:34:56.123456789'