forked from snowflakedb/snowflake-connector-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_unit_binaryformat.py
More file actions
38 lines (31 loc) · 1.19 KB
/
test_unit_binaryformat.py
File metadata and controls
38 lines (31 loc) · 1.19 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2012-2018 Snowflake Computing Inc. All right reserved.
#
from snowflake.connector.sfbinaryformat import (
SnowflakeBinaryFormat, binary_to_python, binary_to_snowflake)
def test_basic():
"""Test hex and base64 formatting."""
# Hex
fmt = SnowflakeBinaryFormat("heX")
assert fmt.format(b'') == ''
assert fmt.format(b'\x00') == '00'
assert fmt.format(b'\xAB\xCD\x12') == 'ABCD12'
assert fmt.format(b'\x00\xFF\x42\x01') == '00FF4201'
# Base64
fmt = SnowflakeBinaryFormat("BasE64")
assert fmt.format(b'') == ''
assert fmt.format(b'\x00') == 'AA=='
assert fmt.format(b'\xAB\xCD\x12') == 'q80S'
assert fmt.format(b'\x00\xFF\x42\x01') == 'AP9CAQ=='
def test_binary_to_python():
"""Test conversion to Python data type."""
assert binary_to_python('') == b''
assert binary_to_python('00') == b'\x00'
assert binary_to_python('ABCD12') == b'\xAB\xCD\x12'
def test_binary_to_snowflake():
"""Test conversion for passing to Snowflake."""
assert binary_to_snowflake(b'') == b''
assert binary_to_snowflake(b'\x00') == b'00'
assert binary_to_snowflake(b'\xAB\xCD\x12') == b'ABCD12'