Skip to content
Snippets Groups Projects
Commit 5b1530d6 authored by Gavin M. Roy's avatar Gavin M. Roy
Browse files

Constants and imports cleanup

parent 600ed357
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -28,10 +28,7 @@ try:
from queries.tornado_session import TornadoSession
except ImportError: # pragma: nocover
TornadoSession = None
from queries.utils import uri, PYPY
__version__ = '2.0.0'
version = __version__
from queries.utils import uri
 
# For ease of access to different cursor types
from psycopg2.extras import DictCursor
Loading
Loading
@@ -54,5 +51,8 @@ from psycopg2 import ProgrammingError
from psycopg2.extensions import QueryCanceledError
from psycopg2.extensions import TransactionRollbackError
 
__version__ = '2.0.0'
version = __version__
# Add a Null logging handler to prevent logging output when un-configured
logging.getLogger('queries').addHandler(logging.NullHandler())
Loading
Loading
@@ -30,11 +30,11 @@ import psycopg2
from psycopg2 import extensions, extras
 
from queries import pool, results, utils
from queries.utils import DEFAULT_URI, PYPY
 
LOGGER = logging.getLogger(__name__)
 
DEFAULT_ENCODING = 'UTF8'
DEFAULT_URI = 'postgresql://localhost:5432'
 
 
class Session(object):
Loading
Loading
@@ -297,7 +297,7 @@ class Session(object):
# Added in because psycopg2ct connects and leaves the connection in
# a weird state: consts.STATUS_DATESTYLE, returning from
# Connection._setup without setting the state as const.STATUS_OK
if PYPY:
if utils.PYPY:
connection.reset()
 
# Register the custom data types
Loading
Loading
Loading
Loading
@@ -31,7 +31,6 @@ from psycopg2 import extras, extensions
import psycopg2
 
from queries import pool, results, session, utils
from queries.utils import DEFAULT_URI, PYPY
 
LOGGER = logging.getLogger(__name__)
 
Loading
Loading
@@ -137,7 +136,7 @@ class TornadoSession(session.Session):
:param int pool_max_size: The maximum size of the pool to use
 
"""
def __init__(self, uri=DEFAULT_URI,
def __init__(self, uri=session.DEFAULT_URI,
cursor_factory=extras.RealDictCursor,
pool_idle_ttl=pool.DEFAULT_IDLE_TTL,
pool_max_size=DEFAULT_MAX_POOL_SIZE,
Loading
Loading
@@ -317,7 +316,7 @@ class TornadoSession(session.Session):
# connection in a weird state: consts.STATUS_DATESTYLE,
# returning from Connection._setup without setting the state
# as const.STATUS_OK
if PYPY:
if utils.PYPY:
connection.status = extensions.STATUS_READY
 
# Register the custom data types
Loading
Loading
Loading
Loading
@@ -26,8 +26,6 @@ except ImportError:
 
LOGGER = logging.getLogger(__name__)
 
DEFAULT_URI = 'postgresql://localhost:5432'
PARSED = collections.namedtuple('Parsed',
'scheme,netloc,path,params,query,fragment,'
'username,password,hostname,port')
Loading
Loading
Loading
Loading
@@ -4,10 +4,11 @@ Tests for functionality in the session module
"""
import hashlib
import mock
import platform
import unittest
 
# Out of order import to ensure psycopg2cffi is registered
from queries import pool, results, session, PYPY
from queries import pool, results, session, utils
 
from psycopg2 import extras
import psycopg2
Loading
Loading
@@ -135,7 +136,8 @@ class SessionTestCase(unittest.TestCase):
self.obj.set_encoding('UTF-8')
self.assertFalse(set_client_encoding.called)
 
@unittest.skipIf(PYPY, 'PYPY does not invoke object.__del__ synchronously')
@unittest.skipIf(utils.PYPY,
'PYPY does not invoke object.__del__ synchronously')
def test_del_invokes_cleanup(self):
cleanup = mock.Mock()
with mock.patch.multiple('queries.session.Session',
Loading
Loading
@@ -219,6 +221,6 @@ class SessionTestCase(unittest.TestCase):
result = self.obj._get_cursor(self.obj._conn, 'test2')
self.assertTrue(result.withhhold)
 
@unittest.skipUnless(PYPY, 'connection.reset is PYPY only behavior')
@unittest.skipUnless(utils.PYPY, 'connection.reset is PYPY only behavior')
def test_connection_reset_in_pypy(self):
self.conn.reset.assert_called_once_with()
Loading
Loading
@@ -56,7 +56,7 @@ class SessionInitTests(unittest.TestCase):
self.assertEqual(self.obj._pool_manager, pool.PoolManager.instance())
 
def test_sets_uri(self):
self.assertEqual(self.obj._uri, tornado_session.DEFAULT_URI)
self.assertEqual(self.obj._uri, tornado_session.session.DEFAULT_URI)
 
def test_creates_pool_in_manager(self):
self.assertIn(self.obj.pid, self.obj._pool_manager._pools)
Loading
Loading
Loading
Loading
@@ -23,7 +23,7 @@ class PYPYDetectionTests(unittest.TestCase):
 
def test_pypy_flag(self):
"""PYPY flag is set properly"""
self.assertEqual(queries.PYPY,
self.assertEqual(queries.utils.PYPY,
platform.python_implementation() == 'PyPy')
 
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment