[Python-modules-commits] [python-vertica] 01/03: Import python-vertica_0.6.12.orig.tar.gz
Jean Baptiste Favre
jbfavre-guest at moszumanska.debian.org
Mon Feb 13 09:34:08 UTC 2017
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 5517996dbac343716de5587733d479ac2097b6c8
Author: Jean Baptiste Favre <debian at jbfavre.org>
Date: Mon Feb 13 09:59:22 2017 +0100
Import python-vertica_0.6.12.orig.tar.gz
---
README.md | 28 ++++++++++++++--------
setup.py | 2 +-
vertica_python/__init__.py | 2 +-
vertica_python/errors.py | 14 +++++++++--
vertica_python/tests/date_tests.py | 2 ++
vertica_python/tests/type_tests.py | 28 +++++++++++++++++-----
vertica_python/vertica/column.py | 7 +++---
.../vertica/messages/frontend_messages/startup.py | 13 ++++++++++
8 files changed, 73 insertions(+), 23 deletions(-)
diff --git a/README.md b/README.md
index dff7bf1..ce754df 100644
--- a/README.md
+++ b/README.md
@@ -24,6 +24,10 @@ If you're using pip >= 1.4 and you don't already have pytz installed:
pip install --pre pytz
+If you're using pip >= 1.4 and you don't already have python-dateutil installed:
+
+ pip install --pre python-dateutil
+
To install vertica-python with pip:
pip install vertica-python
@@ -40,20 +44,24 @@ Source code for vertica-python can be found at:
## Run unit tests
-To run the tests, you must have access to a Vertica database. You can
-spin one up with Vagrant that uses the default credentials using
-`vagrant up`. If you want to run it against an existing database
-instead; you can set the environment variables seen in
-`tests/test_commons.py`.
+To run the tests, you must have access to a Vertica database. Heres one way to go about it:
+
+Download docker kitematic:
+https://kitematic.com/
-Assuming you have [tox](http://tox.readthedocs.io/) installed, all you
-have to do is run `tox`. It will run the unit tests using both python 2 and 3.
+Spin up a vertica container (i use sumitchawla/vertica)
-If you run into an error like:
-```ERROR: InterpreterNotFound: python3.4```
+Edit the port number in `tests/test_commons.py` to match the container.
-Edit the envlist property of tox.ini to use the version of python you have installed (eg py35)
+Install tox:
+http://tox.readthedocs.io
+Edit `tox.ini` envlist property to list the version(s) of python you have installed
+
+Run tox:
+```bash
+tox
+```
## Usage
diff --git a/setup.py b/setup.py
index 233e874..04042a5 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.8',
+ version='0.6.12',
description='A native Python client for the Vertica database.',
author='Justin Berka, Alex Kim',
author_email='justin.berka at gmail.com, alex.kim at uber.com',
diff --git a/vertica_python/__init__.py b/vertica_python/__init__.py
index d805ea7..55b0e6f 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, 8)
+version_info = (0, 6, 12)
__version__ = '.'.join(map(str, version_info))
diff --git a/vertica_python/errors.py b/vertica_python/errors.py
index 666dcbe..8f31cd4 100644
--- a/vertica_python/errors.py
+++ b/vertica_python/errors.py
@@ -137,6 +137,14 @@ class DuplicateObject(QueryError):
pass
+class QueryCanceled(QueryError):
+ pass
+
+
+class ConnectionFailure(QueryError):
+ pass
+
+
QUERY_ERROR_CLASSES = {
b'55V03': LockFailure,
b'53000': InsufficientResources,
@@ -148,5 +156,7 @@ QUERY_ERROR_CLASSES = {
b'22V04': CopyRejected,
b'42501': PermissionDenied,
b'22007': InvalidDatetimeFormat,
- b'42710': DuplicateObject
-}
+ b'42710': DuplicateObject,
+ b'57014': QueryCanceled,
+ b'08006': ConnectionFailure
+}
\ No newline at end of file
diff --git a/vertica_python/tests/date_tests.py b/vertica_python/tests/date_tests.py
index 763fec0..af2a374 100644
--- a/vertica_python/tests/date_tests.py
+++ b/vertica_python/tests/date_tests.py
@@ -33,6 +33,7 @@ class DateParsingTestCase(VerticaTestCase):
self._assert_date('2000-01-01 AD', 'YYYY-MM-DD BC', date(2000, 1, 1))
self._assert_date('2000-01-01 AD', 'YYYY-MM-DD AD', date(2000, 1, 1))
self._assert_date('2000-01-01', 'YYYY-MM-DD', date(2000, 1, 1))
+ self._assert_date('10000-01-01', 'YYYY-MM-DD', date(9999, 1, 1))
def test_before_christ_bc_indicator(self):
try:
@@ -51,6 +52,7 @@ class DateParsingTestCase(VerticaTestCase):
pass
+
class TimestampParsingTestCase(VerticaTestCase):
"""Verify timestamp parsing works properly."""
diff --git a/vertica_python/tests/type_tests.py b/vertica_python/tests/type_tests.py
index 31900b4..25cbad3 100644
--- a/vertica_python/tests/type_tests.py
+++ b/vertica_python/tests/type_tests.py
@@ -1,15 +1,31 @@
+from decimal import Decimal
+
from .test_commons import conn_info, VerticaTestCase
from .. import connect
-from decimal import Decimal
class TypeTestCase(VerticaTestCase):
+ @staticmethod
+ def _execute_and_fetchone(query):
+ with connect(**conn_info) as conn:
+ cur = conn.cursor()
+ cur.execute(query)
+ return cur.fetchone()
+
def test_decimal_query(self):
value = Decimal(0.42)
query = "SELECT {}::numeric".format(value)
+ res = self._execute_and_fetchone(query)
+ self.assertAlmostEqual(res[0], value)
- with connect(**conn_info) as conn:
- cur = conn.cursor()
- cur.execute(query)
- res = cur.fetchone()
- self.assertAlmostEqual(res[0], value)
+ def test_boolean_query__true(self):
+ value = True
+ query = "SELECT {}::boolean".format(value)
+ res = self._execute_and_fetchone(query)
+ self.assertEqual(res[0], value)
+
+ def test_boolean_query__false(self):
+ value = False
+ query = "SELECT {}::boolean".format(value)
+ res = self._execute_and_fetchone(query)
+ self.assertEqual(res[0], value)
diff --git a/vertica_python/vertica/column.py b/vertica_python/vertica/column.py
index 50d787e..d6406b9 100644
--- a/vertica_python/vertica/column.py
+++ b/vertica_python/vertica/column.py
@@ -84,7 +84,8 @@ def date_parse(s):
if s.endswith(b' BC'):
raise errors.NotSupportedError('Dates Before Christ are not supported. Got: ' + str(s, 'utf-8'))
- return date(*map(lambda x: int(x), s.split(b'-')))
+ # Value error, year might be over 9999
+ return date(*map(lambda x: min(int(x), 9999), s.split(b'-')))
ColumnTuple = namedtuple(
'Column',
@@ -105,7 +106,7 @@ class Column(object):
('pos', None),
('record', None),
('unknown', None),
- ('bool', lambda s: s == 't'),
+ ('bool', lambda s: 't' == str(s, 'utf-8', unicode_error)),
('integer', lambda s: int(s)),
('float', lambda s: float(s)),
('char', lambda s: str(s, 'utf-8', unicode_error)),
@@ -122,7 +123,7 @@ class Column(object):
]
@property
- def data_types():
+ def data_types(self):
return map(lambda x: x[0], Column.data_type_conversions())
def __init__(self, col, unicode_error=None):
diff --git a/vertica_python/vertica/messages/frontend_messages/startup.py b/vertica_python/vertica/messages/frontend_messages/startup.py
index 767cdd6..e16d89f 100644
--- a/vertica_python/vertica/messages/frontend_messages/startup.py
+++ b/vertica_python/vertica/messages/frontend_messages/startup.py
@@ -3,6 +3,9 @@
from struct import pack
import vertica_python
+import platform
+import os
+import uuid
from vertica_python.vertica.messages.message import FrontendMessage
@@ -12,6 +15,11 @@ class Startup(FrontendMessage):
self.user = user
self.database = database
self.options = options
+ self.type = b'vertica-python'
+ self.version = vertica_python.__version__.encode('ascii')
+ self.platform = platform.platform().encode('ascii')
+ self.pid = '{0}'.format(os.getpid()).encode('ascii')
+ self.label = self.type+b'-'+self.version+b'-'+str(uuid.uuid1()).encode('ascii')
def to_bytes(self):
startstr = pack('!I', vertica_python.PROTOCOL_VERSION)
@@ -21,6 +29,11 @@ class Startup(FrontendMessage):
startstr = startstr + pack('8sx{0}sx'.format(len(self.database)), b'database', self.database)
if self.options is not None:
startstr = startstr + pack('7sx{0}sx'.format(len(self.options)), b'options', self.options)
+ startstr = startstr + pack('12sx{0}sx'.format(len(self.label)), b'client_label', self.label)
+ startstr = startstr + pack('11sx{0}sx'.format(len(self.type)), b'client_type', self.type)
+ startstr = startstr + pack('14sx{0}sx'.format(len(self.version)), b'client_version', self.version)
+ startstr = startstr + pack('9sx{0}sx'.format(len(self.platform)), b'client_os', self.platform)
+ startstr = startstr + pack('10sx{0}sx'.format(len(self.pid)), b'client_pid', self.pid)
startstr = startstr + pack('x')
return self.message_string(startstr)
--
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