From 404e69426b05a82d905cbb3ad33adafccddb00dd Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 5 Jan 2019 22:42:08 -0500 Subject: Assorted pre-Black fixes Fixes to the test suite, a few errant imports, and setup.py: - mysql and postgresql have unused 'json' imports; remove - postgresql is exporting the 'json' symbol, remove - make sure setup.py can find __version__ using " or ' - retry logic in provision create database for postgresql fixed - refactor test_magazine to use cls.tables rather than globals - remove unused class in test_scoping - add a comment to test_deprecations that this test suite itself is deprecated - don't use mapper() and orm_mapper() in test_unitofwork, just use mapper() - remove dupe test_scalar_set_None test in test_attributes - Python 2.7 and above includes unittest.SkipTest, remove pre-2.7 fallback - use imported SkipTest in profiling - declarative test_reflection tests with "reflectable_autoincrement" already don't run on oracle or firebird; remove conditional logic for these, which also removes an "id" symbol - clean up test in test_functions, remove print statement - remove dupe test_literal_processor_coercion_native_int_out_of_range in test/sql/test_types.py - fix psycopg2_hstore ref Change-Id: I7b3444f8546aac82be81cd1e7b6d8b2ad6834fe6 --- lib/sqlalchemy/dialects/mysql/base.py | 1 - lib/sqlalchemy/dialects/mysql/json.py | 2 -- lib/sqlalchemy/dialects/postgresql/__init__.py | 4 ++-- lib/sqlalchemy/dialects/postgresql/json.py | 2 -- lib/sqlalchemy/dialects/postgresql/psycopg2.py | 2 +- lib/sqlalchemy/testing/config.py | 6 +----- lib/sqlalchemy/testing/profiling.py | 2 +- lib/sqlalchemy/testing/provision.py | 9 ++++++--- 8 files changed, 11 insertions(+), 17 deletions(-) (limited to 'lib/sqlalchemy') diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index d633c2f65..673d4b9ff 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -736,7 +736,6 @@ output:: from collections import defaultdict import re import sys -import json from ... import schema as sa_schema from ... import exc, log, sql, util diff --git a/lib/sqlalchemy/dialects/mysql/json.py b/lib/sqlalchemy/dialects/mysql/json.py index 84dcefc88..534fb989d 100644 --- a/lib/sqlalchemy/dialects/mysql/json.py +++ b/lib/sqlalchemy/dialects/mysql/json.py @@ -7,8 +7,6 @@ from __future__ import absolute_import -import json - from ...sql import elements from ... import types as sqltypes from ... import util diff --git a/lib/sqlalchemy/dialects/postgresql/__init__.py b/lib/sqlalchemy/dialects/postgresql/__init__.py index d2f8057b6..84f720028 100644 --- a/lib/sqlalchemy/dialects/postgresql/__init__.py +++ b/lib/sqlalchemy/dialects/postgresql/__init__.py @@ -14,7 +14,7 @@ from .base import \ TIMESTAMP, TIME, DATE, BYTEA, BOOLEAN, INTERVAL, ENUM, TSVECTOR, \ DropEnumType, CreateEnumType from .hstore import HSTORE, hstore -from .json import JSON, JSONB, json +from .json import JSON, JSONB from .array import array, ARRAY, Any, All from .ext import aggregate_order_by, ExcludeConstraint, array_agg from .dml import insert, Insert @@ -31,7 +31,7 @@ __all__ = ( 'REGCLASS', 'DOUBLE_PRECISION', 'TIMESTAMP', 'TIME', 'DATE', 'BYTEA', 'BOOLEAN', 'INTERVAL', 'ARRAY', 'ENUM', 'dialect', 'array', 'HSTORE', 'hstore', 'INT4RANGE', 'INT8RANGE', 'NUMRANGE', 'DATERANGE', - 'TSRANGE', 'TSTZRANGE', 'json', 'JSON', 'JSONB', 'Any', 'All', + 'TSRANGE', 'TSTZRANGE', 'JSON', 'JSONB', 'Any', 'All', 'DropEnumType', 'CreateEnumType', 'ExcludeConstraint', 'aggregate_order_by', 'array_agg', 'insert', 'Insert' ) diff --git a/lib/sqlalchemy/dialects/postgresql/json.py b/lib/sqlalchemy/dialects/postgresql/json.py index 1a1367f1b..e9256daf3 100644 --- a/lib/sqlalchemy/dialects/postgresql/json.py +++ b/lib/sqlalchemy/dialects/postgresql/json.py @@ -6,8 +6,6 @@ # the MIT License: http://www.opensource.org/licenses/mit-license.php from __future__ import absolute_import -import json - from .base import ischema_names, colspecs from ... import types as sqltypes from ...sql import operators diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index 2a949c443..baa0e00d5 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -300,7 +300,7 @@ The psycopg2 dialect will log PostgreSQL NOTICE messages via the import logging logging.getLogger('sqlalchemy.dialects.postgresql').setLevel(logging.INFO) -.. _psycopg2_hstore:: +.. _psycopg2_hstore: HSTORE type ------------ diff --git a/lib/sqlalchemy/testing/config.py b/lib/sqlalchemy/testing/config.py index dfe0da94b..e9cfb3de9 100644 --- a/lib/sqlalchemy/testing/config.py +++ b/lib/sqlalchemy/testing/config.py @@ -6,6 +6,7 @@ # the MIT License: http://www.opensource.org/licenses/mit-license.php import collections +from unittest import SkipTest as _skip_test_exception requirements = None db = None @@ -16,11 +17,6 @@ test_schema = None test_schema_2 = None _current = None -try: - from unittest import SkipTest as _skip_test_exception -except ImportError: - _skip_test_exception = None - class Config(object): def __init__(self, db, db_opts, options, file_config): diff --git a/lib/sqlalchemy/testing/profiling.py b/lib/sqlalchemy/testing/profiling.py index 42265f7cb..fab99b186 100644 --- a/lib/sqlalchemy/testing/profiling.py +++ b/lib/sqlalchemy/testing/profiling.py @@ -206,7 +206,7 @@ def function_call_count(variance=0.05): @contextlib.contextmanager def count_functions(variance=0.05): if cProfile is None: - raise SkipTest("cProfile is not installed") + raise config._skip_test_exception("cProfile is not installed") if not _profile_stats.has_stats() and not _profile_stats.write: config.skip_test( diff --git a/lib/sqlalchemy/testing/provision.py b/lib/sqlalchemy/testing/provision.py index 4c749d382..c0ca7c1cb 100644 --- a/lib/sqlalchemy/testing/provision.py +++ b/lib/sqlalchemy/testing/provision.py @@ -170,11 +170,16 @@ def _pg_create_db(cfg, eng, ident): pass if not template_db: template_db = conn.scalar("select current_database()") - for attempt in range(3): + + attempt = 0 + while True: try: conn.execute( "CREATE DATABASE %s TEMPLATE %s" % (ident, template_db)) except exc.OperationalError as err: + attempt += 1 + if attempt >= 3: + raise if "accessed by other users" in str(err): log.info( "Waiting to create %s, URI %r, " @@ -183,8 +188,6 @@ def _pg_create_db(cfg, eng, ident): time.sleep(.5) else: break - else: - raise err @_create_db.for_db("mysql") -- cgit v1.2.1