[Python-modules-commits] [python-vertica] 07/10: Import python-vertica_0.6.3.orig.tar.gz

Jean Baptiste Favre jbfavre-guest at moszumanska.debian.org
Mon May 23 19:39:10 UTC 2016


This is an automated email from the git hooks/post-receive script.

jbfavre-guest pushed a commit to branch master
in repository python-vertica.

commit 4ba63164525537d6b083ba3c20ba09a6d0029224
Author: Jean Baptiste Favre <debian at jbfavre.org>
Date:   Mon May 23 20:52:21 2016 +0200

    Import python-vertica_0.6.3.orig.tar.gz
---
 README.md                              |  2 +-
 setup.py                               |  2 +-
 vertica_python/__init__.py             |  2 +-
 vertica_python/tests/column_tests.py   | 21 +++++++++++++++
 vertica_python/tests/date_tests.py     | 10 ++++---
 vertica_python/tests/timezone_tests.py | 48 ++++++++++++++++++++++++++++++++++
 vertica_python/vertica/column.py       |  8 +++---
 7 files changed, 83 insertions(+), 10 deletions(-)

diff --git a/README.md b/README.md
index b2dddaf..5ceb51b 100644
--- a/README.md
+++ b/README.md
@@ -240,7 +240,7 @@ cur.nextset()
 
 ## UTF-8 encoding issues
 
-While Vertica expects varchars stored to be UTF-8 encoded, sometimes invalid stirngs get intot the database. You can specify how to handle reading these characters using the unicode_error conneciton option. This uses the same values as the unicode type (https://docs.python.org/2/library/functions.html#unicode)
+While Vertica expects varchars stored to be UTF-8 encoded, sometimes invalid strings get into the database. You can specify how to handle reading these characters using the unicode_error connection option. This uses the same values as the unicode type (https://docs.python.org/2/library/functions.html#unicode)
 
 ```python
 cur = vertica_python.Connection({..., 'unicode_error': 'strict'}).cursor()
diff --git a/setup.py b/setup.py
index 78c1730..e93311e 100644
--- a/setup.py
+++ b/setup.py
@@ -10,7 +10,7 @@ opts = ReqOpts(None, 'git')
 # version should use the format 'x.x.x' (instead of 'vx.x.x')
 setup(
     name='vertica-python',
-    version='0.6.2',
+    version='0.6.3',
     description='A native Python client for the Vertica database.',
     author='Justin Berka, Alex Kim, Kenneth Tran',
     author_email='justin.berka at gmail.com, alex.kim at uber.com, tran at uber.com',
diff --git a/vertica_python/__init__.py b/vertica_python/__init__.py
index a5fac1d..b8a48b8 100644
--- a/vertica_python/__init__.py
+++ b/vertica_python/__init__.py
@@ -6,7 +6,7 @@ from vertica_python.vertica.connection import Connection
 # Main module for this library.
 
 # The version number of this library.
-version_info = (0, 6, 2)
+version_info = (0, 6, 3)
 
 __version__ = '.'.join(map(str, version_info))
 
diff --git a/vertica_python/tests/column_tests.py b/vertica_python/tests/column_tests.py
new file mode 100644
index 0000000..f1d889d
--- /dev/null
+++ b/vertica_python/tests/column_tests.py
@@ -0,0 +1,21 @@
+from .test_commons import conn_info, VerticaTestCase
+from .. import connect
+
+
+class ColumnTestCase(VerticaTestCase):
+    def test_column_names_query(self):
+        column_0 = 'isocode'
+        column_1 = 'name'
+        query = """
+        select 'US' as {column_0}, 'United States' as {column_1}
+        union all
+        select 'CA', 'Canada'
+        union all
+        select 'MX', 'Mexico'
+        """.format(column_0=column_0, column_1=column_1)
+        with connect(**conn_info) as conn:
+            cur = conn.cursor()
+            cur.execute(query)
+            description = cur.description
+            assert description[0].name == column_0
+            assert description[1].name == column_1
diff --git a/vertica_python/tests/date_tests.py b/vertica_python/tests/date_tests.py
index 4477165..2b69ed8 100644
--- a/vertica_python/tests/date_tests.py
+++ b/vertica_python/tests/date_tests.py
@@ -54,18 +54,20 @@ class DateParsingTestCase(VerticaTestCase):
 class TimestampParsingTestCase(VerticaTestCase):
     """Verify timestamp parsing works properly."""
 
-
     def test_timestamp_parser(self):
-        parsed_timestamp = timestamp_parse('1841-05-05 22:07:58')
+        test_timestamp = '1841-05-05 22:07:58'.encode(encoding='utf-8', errors='strict')
+        parsed_timestamp = timestamp_parse(test_timestamp)
         # Assert parser default to strptime
         self.assertEqual(datetime(year=1841, month=5, day=5, hour=22, minute=7, second=58), parsed_timestamp)
 
     def test_timestamp_with_year_over_9999(self):
-        parsed_timestamp = timestamp_parse('44841-05-05 22:07:58')
+        test_timestamp = '44841-05-05 22:07:58'.encode(encoding='utf-8', errors='strict')
+        parsed_timestamp = timestamp_parse(test_timestamp)
         # Assert year was truncated properly
         self.assertEqual(datetime(year=4841, month=5, day=5, hour=22, minute=7, second=58), parsed_timestamp)
 
     def test_timestamp_with_year_over_9999_and_ms(self):
-        parsed_timestamp = timestamp_parse('124841-05-05 22:07:58.000003')
+        test_timestamp = '124841-05-05 22:07:58.000003'.encode(encoding='utf-8', errors='strict')
+        parsed_timestamp = timestamp_parse(test_timestamp)
         # Assert year was truncated properly
         self.assertEqual(datetime(year=4841, month=5, day=5, hour=22, minute=7, second=58, microsecond=3), parsed_timestamp)
diff --git a/vertica_python/tests/timezone_tests.py b/vertica_python/tests/timezone_tests.py
new file mode 100644
index 0000000..b495eb4
--- /dev/null
+++ b/vertica_python/tests/timezone_tests.py
@@ -0,0 +1,48 @@
+from datetime import date, datetime
+import pytz
+from .test_commons import conn_info, VerticaTestCase
+from .. import connect
+
+class TimeZoneTestCase(VerticaTestCase):
+
+    def test_simple_ts_query(self):
+        query = """
+        select
+          to_timestamp('2016-05-15 13:15:17.789', 'YYYY-MM-DD HH:MI:SS.MS')
+        ;
+        """
+        value = datetime(year=2016, month=5, day=15, hour=13, minute=15, second=17, microsecond=789000)
+
+        with connect(**conn_info) as conn:
+            cur = conn.cursor()
+            cur.execute(query)
+            res = cur.fetchall()
+            assert res[0][0] == value
+
+    def test_simple_ts_with_tz_query(self):
+        query = """
+        select
+          to_timestamp_tz('2016-05-15 13:15:17.789 UTC', 'YYYY-MM-DD HH:MI:SS.MS TZ')
+        ;
+        """
+        value = datetime(year=2016, month=5, day=15, hour=13, minute=15, second=17, microsecond=789000, tzinfo=pytz.utc)
+
+        with connect(**conn_info) as conn:
+            cur = conn.cursor()
+            cur.execute(query)
+            res = cur.fetchall()
+            assert res[0][0] == value
+
+    def test_simple_ts_with_offset_query(self):
+        query = """
+        select
+          timestamp '2016-05-15 13:15:17.789+00'
+        ;
+        """
+        value = datetime(year=2016, month=5, day=15, hour=13, minute=15, second=17, microsecond=789000, tzinfo=pytz.utc)
+
+        with connect(**conn_info) as conn:
+            cur = conn.cursor()
+            cur.execute(query)
+            res = cur.fetchall()
+            assert res[0][0] == value
diff --git a/vertica_python/vertica/column.py b/vertica_python/vertica/column.py
index 91c41dd..010dbec 100644
--- a/vertica_python/vertica/column.py
+++ b/vertica_python/vertica/column.py
@@ -34,6 +34,7 @@ years_re = re.compile(r'^([0-9]+)-')
 # timestamptz type stores: 2013-01-01 05:00:00.01+00
 #       select t AT TIMEZONE 'America/New_York' returns: 2012-12-31 19:00:00.01
 def timestamp_parse(s):
+    s = str(s, 'utf-8')
     try:
         dt = _timestamp_parse(s)
     except ValueError:
@@ -62,10 +63,11 @@ def _timestamp_parse_without_year(s):
 
 
 def timestamp_tz_parse(s):
+    s = str(s, 'utf-8')
     # if timezome is simply UTC...
     if s.endswith('+00'):
         # remove time zone
-        ts = timestamp_parse(s[:-3])
+        ts = timestamp_parse(s[:-3].encode(encoding='utf-8', errors='strict'))
         ts = ts.replace(tzinfo=pytz.UTC)
         return ts
     # other wise do a real parse (slower)
@@ -124,7 +126,7 @@ class Column(object):
         return map(lambda x: x[0], Column.data_type_conversions())
 
     def __init__(self, col, unicode_error=None):
-        self.name = col['name']
+        self.name = col['name'].decode()
         self.type_code = col['data_type_oid']
         self.display_size = None
         self.internal_size = col['data_type_size']
@@ -143,7 +145,7 @@ class Column(object):
             self.type_code = 0
 
         #self.props = ColumnTuple(col['name'], col['data_type_oid'], None, col['data_type_size'], None, None, None)
-        self.props = ColumnTuple(col['name'], self.type_code, None, col['data_type_size'], None, None, None)
+        self.props = ColumnTuple(self.name, self.type_code, None, col['data_type_size'], None, None, None)
 
         #self.converter = self.data_type_conversions[col['data_type_oid']][1]
         self.converter = self.data_type_conversions[self.type_code][1]

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-vertica.git



More information about the Python-modules-commits mailing list