[Python-modules-commits] [python-vertica] 01/04: Import python-vertica_0.7.1.orig.tar.gz

Jean Baptiste Favre jbfavre-guest at moszumanska.debian.org
Tue May 16 07:48:56 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 8a1cd3b55ec2c7acd314c271aacd37f880bad859
Author: Jean Baptiste Favre <debian at jbfavre.org>
Date:   Tue May 16 09:32:26 2017 +0200

    Import python-vertica_0.7.1.orig.tar.gz
---
 .gitignore                                         |   2 +-
 setup.py                                           |   2 +-
 tox.ini                                            |   3 +-
 vertica_python/__init__.py                         |  36 +-
 vertica_python/compat.py                           | 100 +++++
 vertica_python/datatypes.py                        |  25 +-
 vertica_python/errors.py                           |  17 +-
 vertica_python/tests/base.py                       | 103 +++++
 vertica_python/tests/basic_tests.py                | 423 ---------------------
 vertica_python/tests/column_tests.py               |  21 -
 vertica_python/tests/date_tests.py                 |  75 ----
 vertica_python/tests/error_tests.py                |  62 ---
 vertica_python/tests/test_column.py                |  18 +
 vertica_python/tests/test_commons.py               |  28 --
 vertica_python/tests/test_cursor.py                | 353 +++++++++++++++++
 vertica_python/tests/test_datatypes.py             |  25 ++
 vertica_python/tests/test_dates.py                 | 238 ++++++++++++
 vertica_python/tests/test_errors.py                |  31 ++
 vertica_python/tests/test_timezones.py             |  52 +++
 vertica_python/tests/test_unicode.py               |  65 ++++
 vertica_python/tests/timezone_tests.py             |  48 ---
 vertica_python/tests/type_tests.py                 |  31 --
 vertica_python/tests/unicode_tests.py              |  75 ----
 vertica_python/vertica/column.py                   | 136 +++----
 vertica_python/vertica/connection.py               | 132 +++----
 vertica_python/vertica/cursor.py                   | 311 +++++++++------
 vertica_python/vertica/messages/__init__.py        |  49 +--
 .../vertica/messages/backend_messages/__init__.py  |  25 ++
 .../messages/backend_messages/authentication.py    |   8 +-
 .../messages/backend_messages/backend_key_data.py  |   8 +-
 .../messages/backend_messages/bind_complete.py     |   8 +-
 .../messages/backend_messages/close_complete.py    |   8 +-
 .../messages/backend_messages/command_complete.py  |   9 +-
 .../messages/backend_messages/copy_in_response.py  |  10 +-
 .../vertica/messages/backend_messages/data_row.py  |  11 +-
 .../backend_messages/empty_query_response.py       |   9 +-
 .../messages/backend_messages/error_response.py    |   8 +-
 .../vertica/messages/backend_messages/no_data.py   |   8 +-
 .../messages/backend_messages/notice_response.py   |  24 +-
 .../backend_messages/parameter_description.py      |  10 +-
 .../messages/backend_messages/parameter_status.py  |   8 +-
 .../messages/backend_messages/parse_complete.py    |   8 +-
 .../messages/backend_messages/portal_suspended.py  |   8 +-
 .../messages/backend_messages/ready_for_query.py   |   8 +-
 .../messages/backend_messages/row_description.py   |  14 +-
 .../vertica/messages/backend_messages/unknown.py   |  12 +-
 .../vertica/messages/frontend_messages/__init__.py |  23 ++
 .../vertica/messages/frontend_messages/bind.py     |  27 +-
 .../messages/frontend_messages/cancel_request.py   |  20 +-
 .../vertica/messages/frontend_messages/close.py    |  26 +-
 .../messages/frontend_messages/copy_data.py        |  29 +-
 .../messages/frontend_messages/copy_done.py        |  10 +-
 .../messages/frontend_messages/copy_fail.py        |  18 +-
 .../messages/frontend_messages/copy_stream.py      |  36 +-
 .../messages/frontend_messages/crypt_windows.py    | 117 +++---
 .../vertica/messages/frontend_messages/describe.py |  27 +-
 .../vertica/messages/frontend_messages/execute.py  |  20 +-
 .../vertica/messages/frontend_messages/flush.py    |  11 +-
 .../vertica/messages/frontend_messages/parse.py    |  27 +-
 .../vertica/messages/frontend_messages/password.py |  59 +--
 .../vertica/messages/frontend_messages/query.py    |  22 +-
 .../messages/frontend_messages/ssl_request.py      |  16 +-
 .../vertica/messages/frontend_messages/startup.py  |  72 ++--
 .../vertica/messages/frontend_messages/sync.py     |  11 +-
 .../messages/frontend_messages/terminate.py        |  11 +-
 vertica_python/vertica/messages/message.py         |  85 +++--
 66 files changed, 1895 insertions(+), 1437 deletions(-)

diff --git a/.gitignore b/.gitignore
index 6edc000..26d4ffa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -40,7 +40,7 @@ nosetests.xml
 .vagrant
 
 # pycharm
-/.idea/
+.idea
 
 # default virtual environment
 /env/
diff --git a/setup.py b/setup.py
index d0b785a..4823d12 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.14',
+    version='0.7.1',
     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/tox.ini b/tox.ini
index c1d6e9b..aa39c39 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,7 +1,8 @@
 [tox]
-envlist = py27,py34
+envlist = py27,py34,py35,py36
 
 [testenv]
+passenv = *
 commands =
 	nosetests
 deps =
diff --git a/vertica_python/__init__.py b/vertica_python/__init__.py
index 0376d36..f90fcd0 100644
--- a/vertica_python/__init__.py
+++ b/vertica_python/__init__.py
@@ -1,30 +1,32 @@
+from __future__ import print_function, division, absolute_import
 
+from .vertica.connection import Connection, connect
 
-from vertica_python.vertica.connection import Connection
-
+# Importing exceptions for compatibility with dbapi 2.0.
+# See: PEP 249 - Python Database API 2.0
+#      https://www.python.org/dev/peps/pep-0249/#exceptions
+from . import errors
+from .errors import (
+    Error, Warning, DataError, DatabaseError, IntegrityError, InterfaceError,
+    InternalError, NotSupportedError, OperationalError, ProgrammingError)
 
 # Main module for this library.
-
-# The version number of this library.
-version_info = (0, 6, 14)
-
-__version__ = '.'.join(map(str, version_info))
-
 __author__ = 'Uber Technologies, Inc'
 __copyright__ = 'Copyright 2013, Uber Technologies, Inc.'
 __license__ = 'MIT'
 
+__all__ = ['Connection', 'PROTOCOL_VERSION', 'version_info', 'apilevel', 'threadsafety',
+           'paramstyle', 'connect', 'Error', 'Warning', 'DataError', 'DatabaseError',
+           'IntegrityError', 'InterfaceError', 'InternalError', 'NotSupportedError',
+           'OperationalError', 'ProgrammingError']
+
+# The version number of this library.
+version_info = (0, 7, 1)
+__version__ = '.'.join(map(str, version_info))
+
 # The protocol version (3.0.0) implemented in this library.
 PROTOCOL_VERSION = 3 << 16
 
-
 apilevel = 2.0
-
-# Threads may share the module, but not connections!
-threadsafety = 1
+threadsafety = 1  # Threads may share the module, but not connections!
 paramstyle = 'named'  # WHERE name=:name
-
-
-def connect(**kwargs):
-    """Opens a new connection to a Vertica database."""
-    return Connection(kwargs)
diff --git a/vertica_python/compat.py b/vertica_python/compat.py
new file mode 100644
index 0000000..db8a437
--- /dev/null
+++ b/vertica_python/compat.py
@@ -0,0 +1,100 @@
+# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==============================================================================
+
+"""Functions for Python 2 vs. 3 compatibility.
+## Conversion routines
+In addition to the functions below, `as_str` converts an object to a `str`.
+@@as_bytes
+@@as_text
+@@as_str_any
+## Types
+The compatibility module also provides the following types:
+* `bytes_or_text_types`
+* `complex_types`
+* `integral_types`
+* `real_types`
+"""
+
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+
+import six as _six
+
+
+def as_bytes(bytes_or_text, encoding='utf-8'):
+    """Converts either bytes or unicode to `bytes`, using utf-8 encoding for text.
+    Args:
+      bytes_or_text: A `bytes`, `str`, or `unicode` object.
+      encoding: A string indicating the charset for encoding unicode.
+    Returns:
+      A `bytes` object.
+    Raises:
+      TypeError: If `bytes_or_text` is not a binary or unicode string.
+    """
+    if isinstance(bytes_or_text, _six.text_type):
+        return bytes_or_text.encode(encoding)
+    elif isinstance(bytes_or_text, bytes):
+        return bytes_or_text
+    else:
+        raise TypeError('Expected binary or unicode string, got %r' %
+                        (bytes_or_text,))
+
+
+def as_text(bytes_or_text, encoding='utf-8'):
+    """Returns the given argument as a unicode string.
+    Args:
+      bytes_or_text: A `bytes`, `str, or `unicode` object.
+      encoding: A string indicating the charset for decoding unicode.
+    Returns:
+      A `unicode` (Python 2) or `str` (Python 3) object.
+    Raises:
+      TypeError: If `bytes_or_text` is not a binary or unicode string.
+    """
+    if isinstance(bytes_or_text, _six.text_type):
+        return bytes_or_text
+    elif isinstance(bytes_or_text, bytes):
+        return bytes_or_text.decode(encoding)
+    else:
+        raise TypeError('Expected binary or unicode string, got %r' % bytes_or_text)
+
+
+# Convert an object to a `str` in both Python 2 and 3.
+if _six.PY2:
+    as_str = as_bytes
+else:
+    as_str = as_text
+
+
+def as_str_any(value):
+    """Converts to `str` as `str(value)`, but use `as_str` for `bytes`.
+    Args:
+      value: A object that can be converted to `str`.
+    Returns:
+      A `str` object.
+    """
+    if isinstance(value, bytes):
+        return as_str(value)
+    else:
+        return str(value)
+
+
+# Either bytes or text.
+bytes_or_text_types = (bytes, _six.text_type)
+
+_allowed_symbols = [
+    'as_str',
+    'bytes_or_text_types',
+]
diff --git a/vertica_python/datatypes.py b/vertica_python/datatypes.py
index 89fe296..5c9bd89 100644
--- a/vertica_python/datatypes.py
+++ b/vertica_python/datatypes.py
@@ -1,33 +1,38 @@
+from __future__ import print_function, division, absolute_import
 
-
-from datetime import datetime
-from datetime import timedelta
+from datetime import date, datetime, time
 
 
+# noinspection PyPep8Naming
 def Date(year, month, day):
-    return datetime.date(year, month, day)
+    return date(year, month, day)
 
 
+# noinspection PyPep8Naming
 def Time(hour, minute, second):
-    return datetime.time(hour, minute, second)
+    return time(hour, minute, second)
 
 
+# noinspection PyPep8Naming
 def Timestamp(year, month, day, hour, minute, second):
-    return datetime.datetime(year, month, day, hour, minute, second)
+    return datetime(year, month, day, hour, minute, second)
 
 
+# noinspection PyPep8Naming
 def DateFromTicks(ticks):
-    d = datetime(1970, 1, 1) + timedelta(seconds=ticks)
+    d = datetime.utcfromtimestamp(ticks)
     return d.date()
 
 
+# noinspection PyPep8Naming
 def TimeFromTicks(ticks):
-    d = datetime(1970, 1, 1) + timedelta(seconds=ticks)
+    d = datetime.utcfromtimestamp(ticks)
     return d.time()
 
 
+# noinspection PyPep8Naming
 def TimestampFromTicks(ticks):
-    d = datetime(1970, 1, 1) + timedelta(seconds=ticks)
+    d = datetime.utcfromtimestamp(ticks)
     return d.time()
 
 
@@ -35,9 +40,11 @@ class Bytea(str):
     pass
 
 
+# noinspection PyPep8Naming
 def Binary(string):
     return Bytea(string)
 
+
 # vertica doesnt have a binary or row_id type i think
 STRING = 9
 BINARY = 10000
diff --git a/vertica_python/errors.py b/vertica_python/errors.py
index 8f31cd4..b54e074 100644
--- a/vertica_python/errors.py
+++ b/vertica_python/errors.py
@@ -1,15 +1,16 @@
+from __future__ import print_function, division, absolute_import
 
-
-import sys
-if sys.version_info < (3,):
-    import exceptions
 import re
 
 
+#############################################
+# dbapi errors
+#############################################
 class Error(Exception):
     pass
 
 
+# noinspection PyShadowingBuiltins
 class Warning(Exception):
     pass
 
@@ -75,9 +76,9 @@ class QueryError(ProgrammingError):
     def __init__(self, error_response, sql):
         self.error_response = error_response
         self.sql = sql
-        super(QueryError, self).__init__("{0}, SQL: {1}".format(
-            error_response.error_message(), repr(self.one_line_sql()))
-        )
+        ProgrammingError.__init__(self,
+                                  "{0}, SQL: {1}".format(error_response.error_message(),
+                                                         repr(self.one_line_sql())))
 
     def one_line_sql(self):
         if self.sql:
@@ -159,4 +160,4 @@ QUERY_ERROR_CLASSES = {
     b'42710': DuplicateObject,
     b'57014': QueryCanceled,
     b'08006': ConnectionFailure
-}
\ No newline at end of file
+}
diff --git a/vertica_python/tests/base.py b/vertica_python/tests/base.py
new file mode 100644
index 0000000..7902cb2
--- /dev/null
+++ b/vertica_python/tests/base.py
@@ -0,0 +1,103 @@
+from __future__ import print_function, division, absolute_import
+
+import os
+import unittest
+
+from six import string_types
+
+from .. import *
+from ..compat import as_text, as_str, as_bytes
+
+DEFAULT_VP_TEST_HOST = '127.0.0.1'
+DEFAULT_VP_TEST_PORT = 5433
+DEFAULT_VP_TEST_USER = 'dbadmin'
+DEFAULT_VP_TEST_PASSWD = ''
+DEFAULT_VP_TEST_DB = 'docker'
+DEFAULT_VP_TEST_TABLE = 'vertica_python_unit_test'
+
+
+class VerticaPythonTestCase(unittest.TestCase):
+    """Base class for tests that query Vertica."""
+
+    @classmethod
+    def setUpClass(cls):
+        cls._host = os.getenv('VP_TEST_HOST', DEFAULT_VP_TEST_HOST)
+        cls._port = int(os.getenv('VP_TEST_PORT', DEFAULT_VP_TEST_PORT))
+        cls._user = os.getenv('VP_TEST_USER', DEFAULT_VP_TEST_USER)
+        cls._password = os.getenv('VP_TEST_PASSWD', DEFAULT_VP_TEST_PASSWD)
+        cls._database = os.getenv('VP_TEST_DB', DEFAULT_VP_TEST_DB)
+        cls._table = os.getenv('VP_TEST_TABLE', DEFAULT_VP_TEST_TABLE)
+
+        cls._conn_info = {
+            'host': cls._host,
+            'port': cls._port,
+            'database': cls._database,
+            'user': cls._user,
+            'password': cls._password,
+        }
+
+    @classmethod
+    def tearDownClass(cls):
+        with cls._connect() as conn:
+            cur = conn.cursor()
+            cur.execute("DROP TABLE IF EXISTS {0}".format(cls._table))
+
+    @classmethod
+    def _connect(cls):
+        """Connects to vertica.
+        
+        :return: a connection to vertica.
+        """
+        return connect(**cls._conn_info)
+
+    def _query_and_fetchall(self, query):
+        """Creates a new connection, executes a query and fetches all the results.
+        
+        :param query: query to execute
+        :return: all fetched results as returned by cursor.fetchall()
+        """
+        with self._connect() as conn:
+            cur = conn.cursor()
+            cur.execute(query)
+            results = cur.fetchall()
+
+        return results
+
+    def _query_and_fetchone(self, query):
+        """Creates a new connection, executes a query and fetches one result.
+        
+        :param query: query to execute
+        :return: the first result fetched by cursor.fetchone()
+        """
+        with self._connect() as conn:
+            cur = conn.cursor()
+            cur.execute(query)
+            result = cur.fetchone()
+
+        return result
+
+    def assertTextEqual(self, first, second, msg=None):
+        first_text = as_text(first)
+        second_text = as_text(second)
+        self.assertEqual(first=first_text, second=second_text, msg=msg)
+
+    def assertStrEqual(self, first, second, msg=None):
+        first_str = as_str(first)
+        second_str = as_str(second)
+        self.assertEqual(first=first_str, second=second_str, msg=msg)
+
+    def assertBytesEqual(self, first, second, msg=None):
+        first_bytes = as_bytes(first)
+        second_bytes = as_bytes(second)
+        self.assertEqual(first=first_bytes, second=second_bytes, msg=msg)
+
+    def assertResultEqual(self, value, result, msg=None):
+        if isinstance(value, string_types):
+            self.assertTextEqual(first=value, second=result, msg=msg)
+        else:
+            self.assertEqual(first=value, second=result, msg=msg)
+
+    def assertListOfListsEqual(self, list1, list2, msg=None):
+        self.assertEqual(len(list1), len(list2), msg=msg)
+        for l1, l2 in zip(list1, list2):
+            self.assertListEqual(l1, l2, msg=msg)
diff --git a/vertica_python/tests/basic_tests.py b/vertica_python/tests/basic_tests.py
deleted file mode 100644
index 916b90c..0000000
--- a/vertica_python/tests/basic_tests.py
+++ /dev/null
@@ -1,423 +0,0 @@
-import unittest
-import logging
-import tempfile
-
-from .test_commons import conn_info
-
-import vertica_python
-from vertica_python import errors
-
-logger = logging.getLogger('vertica')
-
-
-def init_table(cur):
-    # clean old table
-    cur.execute('DROP TABLE IF EXISTS vertica_python_unit_test;')
-    
-    # create test table
-    cur.execute("""CREATE TABLE vertica_python_unit_test (
-                    a int,
-                    b varchar(32)
-                    ) ;
-                """)
-
-
-class TestVerticaPython(unittest.TestCase):
-
-    def test_inline_commit(self):
-
-        conn = vertica_python.connect(**conn_info)
-        cur = conn.cursor()
-        init_table(cur)
-        
-        cur.execute(""" INSERT INTO vertica_python_unit_test (a, b) VALUES (1, 'aa'); commit; """)
-        cur.execute("SELECT a, b from vertica_python_unit_test WHERE a = 1")
-
-        # unknown rowcount
-        assert cur.rowcount == -1
-
-        res = cur.fetchall()
-        assert 1 == len(res)
-        assert 1 == res[0][0]
-        assert 'aa' == res[0][1]
-        assert cur.rowcount == 1
-
-    def test_multi_inserts_and_transaction(self):
-
-        conn = vertica_python.connect(**conn_info)
-        cur = conn.cursor()
-        init_table(cur)
-    
-        conn2 = vertica_python.connect(**conn_info)
-        cur2 = conn2.cursor()
-    
-        # insert data without a commit
-        cur.execute(""" INSERT INTO vertica_python_unit_test (a, b) VALUES (2, 'bb') """)
-    
-        # verify we can see it from this cursor
-        cur.execute("SELECT a, b from vertica_python_unit_test WHERE a = 2")
-        res = cur.fetchall()
-        assert 1 == len(res)
-        assert 2 == res[0][0]
-        assert 'bb' == res[0][1]
-        
-        # verify we cant see it from other cursor
-        cur2.execute("SELECT a, b from vertica_python_unit_test WHERE a = 2")
-        res = cur2.fetchall()
-        assert 0 == len(res)
-    
-        # insert more data then commit
-        cur.execute(""" INSERT INTO vertica_python_unit_test (a, b) VALUES (3, 'cc') """)
-        cur.execute(""" commit; """)
-        
-        # verify we can see it from this cursor
-        cur.execute("SELECT a, b from vertica_python_unit_test WHERE a = 2 or a = 3")
-        res = cur.fetchall()
-        assert 2 == len(res)
-    
-        # verify we can see it from other cursor
-        cur2.execute("SELECT a, b from vertica_python_unit_test WHERE a = 2 or a = 3")
-        res = cur2.fetchall()
-        assert 2 == len(res)
-
-    def test_conn_commit(self):
-
-        conn = vertica_python.connect(**conn_info)
-        cur = conn.cursor()
-        init_table(cur)
-    
-        cur.execute(""" INSERT INTO vertica_python_unit_test (a, b) VALUES (5, 'cc') """)
-        conn.commit()
-        cur.execute("SELECT a, b from vertica_python_unit_test WHERE a = 5")
-        res = cur.fetchall()
-        assert 1 == len(res)
-
-
-    def test_delete(self):
-
-        conn = vertica_python.connect(**conn_info)
-        cur = conn.cursor()
-        init_table(cur)
-
-        cur.execute(""" INSERT INTO vertica_python_unit_test (a, b) VALUES (5, 'cc') """)
-        conn.commit()
-
-        cur.execute(""" DELETE from vertica_python_unit_test WHERE a = 5 """)
-
-        # validate delete count
-        assert cur.rowcount == -1
-        res = cur.fetchone()
-        assert 1 == len(res)
-        assert 1 == res[0]
-
-        conn.commit()
-
-        cur.execute("SELECT a, b from vertica_python_unit_test WHERE a = 5")
-        res = cur.fetchall()
-        assert 0 == len(res)
-
-
-    def test_update(self):
-
-        conn = vertica_python.connect(**conn_info)
-        cur = conn.cursor()
-        init_table(cur)
-    
-        cur.execute(""" INSERT INTO vertica_python_unit_test (a, b) VALUES (5, 'cc') """)
-
-        # validate insert count
-        res = cur.fetchone()
-        assert 1 == len(res)
-        assert 1 == res[0]
-
-        conn.commit()
-    
-        cur.execute(""" UPDATE vertica_python_unit_test SET b = 'ff' WHERE a = 5 """)
-
-        # validate update count
-        assert cur.rowcount == -1
-        res = cur.fetchone()
-        assert 1 == len(res)
-        assert 1 == res[0]
-
-        conn.commit()
-    
-        cur.execute("SELECT a, b from vertica_python_unit_test WHERE a = 5")
-        res = cur.fetchall()
-        assert 1 == len(res)
-        assert 5 == res[0][0]
-        assert 'ff' == res[0][1]
-
-    def test_copy_with_string(self):
-
-        conn = vertica_python.connect(**conn_info)
-        cur = conn.cursor()
-        init_table(cur)
-    
-        conn2 = vertica_python.connect(**conn_info)
-        cur2 = conn.cursor()
-    
-        cur.copy(""" COPY vertica_python_unit_test (a, b) from stdin DELIMITER ',' """,  "1,foo\n2,bar")
-        # no commit necessary for copy
-    
-        # verify this cursor can see copy data
-        cur.execute("SELECT a, b from vertica_python_unit_test WHERE a = 1")
-        res = cur.fetchall()
-        assert 1 == len(res)
-        assert 1 == res[0][0]
-        assert 'foo' == res[0][1]
-    
-        # verify other cursor can see copy data
-        cur2.execute("SELECT a, b from vertica_python_unit_test WHERE a = 2")
-        res = cur2.fetchall()
-        assert 1 == len(res)
-        assert 2 == res[0][0]
-        assert 'bar' == res[0][1]
-
-    def test_copy_with_file(self):
-
-        conn = vertica_python.connect(**conn_info)
-        cur = conn.cursor()
-        init_table(cur)
-    
-        conn2 = vertica_python.connect(**conn_info)
-        cur2 = conn.cursor()
-    
-        f = tempfile.TemporaryFile()
-        f.write(b"1,foo\n2,bar")
-        # move rw pointer to top of file
-        f.seek(0)
-        cur.copy(""" COPY vertica_python_unit_test (a, b) from stdin DELIMITER ',' """,  f)
-        f.close()
-    
-        # verify this cursor can see copy data
-        cur.execute("SELECT a, b from vertica_python_unit_test WHERE a = 1")
-        res = cur.fetchall()
-        assert 1 == len(res)
-        assert 1 == res[0][0]
-        assert 'foo' == res[0][1]
-    
-        # verify other cursor can see copy data
-        cur2.execute("SELECT a, b from vertica_python_unit_test WHERE a = 2")
-        res = cur2.fetchall()
-        assert 1 == len(res)
-        assert 2 == res[0][0]
-        assert 'bar' == res[0][1]
-
-    def test_with_conn(self):
-
-        with vertica_python.connect(**conn_info) as conn:
-            cur = conn.cursor()
-            init_table(cur)
-        
-            cur.execute(""" INSERT INTO vertica_python_unit_test (a, b) VALUES (1, 'aa'); commit; """)
-            cur.execute("SELECT a, b from vertica_python_unit_test WHERE a = 1")
-            res = cur.fetchall()
-            assert 1 == len(res)
-
-    def test_iterator(self):
-
-        with vertica_python.connect(**conn_info) as conn:
-            cur = conn.cursor()
-            init_table(cur)
-        
-            cur.execute(""" INSERT INTO vertica_python_unit_test (a, b) VALUES (1, 'aa') """)
-            cur.execute(""" INSERT INTO vertica_python_unit_test (a, b) VALUES (2, 'bb') """)
-            cur.execute(""" INSERT INTO vertica_python_unit_test (a, b) VALUES (3, 'cc') """)
-            conn.commit()
-        
-            cur.execute("SELECT a, b from vertica_python_unit_test ORDER BY a ASC")
-        
-            i = 0;
-            for row in cur.iterate():
-                if i == 0:
-                    assert 1 == row[0]
-                    assert 'aa' == row[1]
-                if i == 1:
-                    assert 2 == row[0]
-                    assert 'bb' == row[1]
-                if i == 2:
-                    assert 3 == row[0]
-                    assert 'cc' == row[1]
-                i = i + 1
-
-
-    def test_mid_iterator_execution(self):
-
-        with vertica_python.connect(**conn_info) as conn:
-            cur = conn.cursor()
-            init_table(cur)
-        
-            cur.execute(""" INSERT INTO vertica_python_unit_test (a, b) VALUES (1, 'aa') """)
-            cur.execute(""" INSERT INTO vertica_python_unit_test (a, b) VALUES (2, 'bb') """)
-            cur.execute(""" INSERT INTO vertica_python_unit_test (a, b) VALUES (3, 'cc') """)
-            conn.commit()
-        
-            cur.execute("SELECT a, b from vertica_python_unit_test ORDER BY a ASC")
-        
-            # don't finish iterating
-            for row in cur.iterate():
-                break;
-
-            # make new query and verify result
-            cur.execute(""" SELECT COUNT(*) FROM vertica_python_unit_test """)
-            res = cur.fetchall()
-            assert 1 == len(res)
-            assert 3 == res[0][0]
-
-
-    def test_query_errors(self):
-        conn = vertica_python.connect(**conn_info)
-        cur = conn.cursor()
-        init_table(cur)
-        
-        failed = False;
-        # create table syntax error
-        try:
-            failed = False;
-            cur.execute("""CREATE TABLE vertica_python_unit_test_fail (
-                            a int,
-                            b varchar(32),,,
-                            ) ;
-                        """)
-        except errors.VerticaSyntaxError:
-            failed = True;
-        assert True == failed
-    
-        # select table not found error
-        try:
-            failed = False;
-            cur.execute(""" INSERT INTO vertica_python_unit_test (a, b) VALUES (1, 'aa') """)
-            cur.execute(""" SELECT * from vertica_python_unit_test_fail  """)
-            #conn.commit()
-        except errors.QueryError:
-            failed = True;
-        assert True == failed
-
-        # verify cursor still useable after errors
-        cur.execute("SELECT a, b from vertica_python_unit_test WHERE a = 1")
-        res = cur.fetchall()
-        assert 1 == len(res)
-        assert 1 == res[0][0]
-        assert 'aa' == res[0][1]
-
-    def test_cursor_close_and_reuse(self):
-
-        conn = vertica_python.connect(**conn_info)
-        cur = conn.cursor()
-        init_table(cur)
-
-        # insert data
-        cur.execute(""" INSERT INTO vertica_python_unit_test (a, b) VALUES (2, 'bb'); commit; """)
-        #conn.commit()
-
-        # query
-        cur.execute("SELECT a, b from vertica_python_unit_test WHERE a = 2")
-        res = cur.fetchall()
-        assert 1 == len(res)
-
-        # close and reopen cursor
-        cur.close()
-        cur = conn.cursor()
-
-        cur.execute("SELECT a, b from vertica_python_unit_test")
-        res = cur.fetchall()
-        assert 1 == len(res)
-
-    # unit test for #78
-    def test_copy_with_data_in_buffer(self):
-
-        conn = vertica_python.connect(**conn_info)
-        cur = conn.cursor()
-        init_table(cur)
-
-        cur.execute("select 1;")
-        cur.fetchall()
-
-        # Current status: CommandComplete
-
-        copy_sql = """COPY vertica_python_unit_test (a, b)
-                     FROM STDIN
-                     DELIMITER '|'
-                     NULL AS 'None'"""
-
-        data = """1|name1
-        2|name2"""
-
-        cur.copy(copy_sql, data)
-        cur.execute("select 1;") # will raise QueryError here
-
-        conn.close()
-
-    # unit test for #74
-    def test_nextset(self):
-
-        conn = vertica_python.connect(**conn_info)
-        cur = conn.cursor()
-        init_table(cur)
-
-        cur.execute("select 1; select 2;")
-        res = cur.fetchall()
-
-        assert 1 == len(res)
-        assert 1 == res[0][0]
-        assert cur.fetchone() is None
-
-        assert cur.nextset() == True
-
-        res = cur.fetchall()
-        assert 1 == len(res)
-        assert 2 == res[0][0]
-        assert cur.fetchone() is None
-
-        assert cur.nextset() is None
-
-    # unit test for #74
-    def test_nextset_with_delete(self):
-
-        conn = vertica_python.connect(**conn_info)
-        cur = conn.cursor()
-        init_table(cur)
-
-        # insert data
-        cur.execute(""" INSERT INTO vertica_python_unit_test (a, b) VALUES (1, 'aa') """)
-        cur.execute(""" INSERT INTO vertica_python_unit_test (a, b) VALUES (2, 'bb') """)
-        conn.commit()
-
-        cur.execute("""select * from vertica_python_unit_test;
-                    delete from vertica_python_unit_test;
-                    select * from vertica_python_unit_test;
-                    """)
-
-        # check first select results
-        res = cur.fetchall()
-        assert 2 == len(res)
-        assert cur.fetchone() is None
-
-        # check delete results
-        assert cur.nextset() == True
-        res = cur.fetchall()
-        assert 1 == len(res)
-        assert 2 == res[0][0]
-        assert cur.fetchone() is None
-
-        # check second select results
-        assert cur.nextset() == True
-        res = cur.fetchall()
-        assert 0 == len(res)
-        assert cur.fetchone() is None
-
-        # no more data sets
-        assert cur.nextset() is None
-
-    # unit test for #144
-    def test_empty_query(self):
-
-        conn = vertica_python.connect(**conn_info)
-        cur = conn.cursor()
-        init_table(cur)
-
-        cur.execute("")
-        res = cur.fetchall()
-
-        assert 0 == len(res)
diff --git a/vertica_python/tests/column_tests.py b/vertica_python/tests/column_tests.py
deleted file mode 100644
index f1d889d..0000000
--- a/vertica_python/tests/column_tests.py
+++ /dev/null
@@ -1,21 +0,0 @@
-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
deleted file mode 100644
index af2a374..0000000
--- a/vertica_python/tests/date_tests.py
+++ /dev/null
@@ -1,75 +0,0 @@
-from datetime import date, datetime
-from .test_commons import *
-from vertica_python import errors
-from vertica_python.vertica.column import timestamp_parse
-
-
-class DateParsingTestCase(VerticaTestCase):
-    """
-    Testing DATE type parsing with focus on AD/BC and lack of support for dates Before Christ.
-
-    Note: the 'BC' or 'AD' era indicators in Vertica's date format seem to make Vertica behave as follows:
-
-     - Both 'BC' and 'AD' are simply a flags that tell Vertica: include era indicator if the date is Before
-       Christ
-     - Dates in AD will never include era indicator
-    """
-    def _query_to_date(self, expression, pattern):
-        return self.query_and_fetchall("SELECT TO_DATE('%(expression)s', '%(pattern)s')" % locals())
-
-    def _assert_date(self, expression, pattern, expected):
-        res = self._query_to_date(expression, pattern)
-
-        if len(res) == 0:
-            self.fail("Expected that query '%(query)s' would return one row with one column. Got nothing." % locals())
-
-        elif len(res[0]) == 0:
-            self.fail("Expected that query '%(query)s' would return one row and one column. Got one row and no column."
-                      % locals())
-
-        self.assertEqual(expected, res[0][0], "Expected date '%s' but got: '%s'" % (str(expected), str(res[0][0])))
-
-    def test_after_christ(self):
-        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:
-            res = self._query_to_date('2000-01-01 BC', 'YYYY-MM-DD BC')
-
-            self.fail("Expected to see NotSupportedError when Before Christ date is encountered. Got: " + str(res))
-        except errors.NotSupportedError:
-            pass
-
-    def test_before_christ_ad_indicator(self):
... 3671 lines suppressed ...

-- 
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