summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2021-10-30 22:00:25 +0200
committerMike Bayer <mike_mp@zzzcomputing.com>2021-11-01 15:11:25 -0400
commit36e7aebd8d6faac77570403e99f9aa7b2330fa59 (patch)
treef45950f61a4b27f128518be52157021ca4f4e8f7 /lib/sqlalchemy/testing
parenta99ea884403de1e1f762e9b1eb635d7fc6ef8e6f (diff)
downloadsqlalchemy-36e7aebd8d6faac77570403e99f9aa7b2330fa59.tar.gz
First round of removal of python 2
References: #4600 Change-Id: I61e35bc93fe95610ae75b31c18a3282558cd4ffe
Diffstat (limited to 'lib/sqlalchemy/testing')
-rw-r--r--lib/sqlalchemy/testing/exclusions.py8
-rw-r--r--lib/sqlalchemy/testing/plugin/bootstrap.py4
-rw-r--r--lib/sqlalchemy/testing/plugin/pytestplugin.py43
-rw-r--r--lib/sqlalchemy/testing/plugin/reinvent_fixtures_py2k.py112
-rw-r--r--lib/sqlalchemy/testing/requirements.py39
-rw-r--r--lib/sqlalchemy/testing/suite/test_dialect.py8
-rw-r--r--lib/sqlalchemy/testing/suite/test_types.py10
-rw-r--r--lib/sqlalchemy/testing/suite/test_unicode_ddl.py31
-rw-r--r--lib/sqlalchemy/testing/util.py24
9 files changed, 24 insertions, 255 deletions
diff --git a/lib/sqlalchemy/testing/exclusions.py b/lib/sqlalchemy/testing/exclusions.py
index d5522289b..e8fce5a4c 100644
--- a/lib/sqlalchemy/testing/exclusions.py
+++ b/lib/sqlalchemy/testing/exclusions.py
@@ -139,16 +139,10 @@ class compound(object):
def _expect_failure(self, config, ex, name="block"):
for fail in self.fails:
if fail(config):
- if util.py2k:
- str_ex = unicode(ex).encode( # noqa: F821
- "utf-8", errors="ignore"
- )
- else:
- str_ex = str(ex)
print(
(
"%s failed as expected (%s): %s "
- % (name, fail._as_string(config), str_ex)
+ % (name, fail._as_string(config), ex)
)
)
break
diff --git a/lib/sqlalchemy/testing/plugin/bootstrap.py b/lib/sqlalchemy/testing/plugin/bootstrap.py
index b4691c57d..1220561e8 100644
--- a/lib/sqlalchemy/testing/plugin/bootstrap.py
+++ b/lib/sqlalchemy/testing/plugin/bootstrap.py
@@ -41,10 +41,6 @@ def load_file_as_module(name):
if to_bootstrap == "pytest":
sys.modules["sqla_plugin_base"] = load_file_as_module("plugin_base")
sys.modules["sqla_plugin_base"].bootstrapped_as_sqlalchemy = True
- if sys.version_info < (3, 0):
- sys.modules["sqla_reinvent_fixtures"] = load_file_as_module(
- "reinvent_fixtures_py2k"
- )
sys.modules["sqla_pytestplugin"] = load_file_as_module("pytestplugin")
else:
raise Exception("unknown bootstrap: %s" % to_bootstrap) # noqa
diff --git a/lib/sqlalchemy/testing/plugin/pytestplugin.py b/lib/sqlalchemy/testing/plugin/pytestplugin.py
index 6c6287060..36aaa5d2a 100644
--- a/lib/sqlalchemy/testing/plugin/pytestplugin.py
+++ b/lib/sqlalchemy/testing/plugin/pytestplugin.py
@@ -25,14 +25,6 @@ except ImportError:
has_xdist = False
-py2k = sys.version_info < (3, 0)
-if py2k:
- try:
- import sqla_reinvent_fixtures as reinvent_fixtures_py2k
- except ImportError:
- from . import reinvent_fixtures_py2k
-
-
def pytest_addoption(parser):
group = parser.getgroup("sqlalchemy")
@@ -238,10 +230,6 @@ def pytest_collection_modifyitems(session, config, items):
else:
newitems.append(item)
- if py2k:
- for item in newitems:
- reinvent_fixtures_py2k.scan_for_fixtures_to_use_for_class(item)
-
# seems like the functions attached to a test class aren't sorted already?
# is that true and why's that? (when using unittest, they're sorted)
items[:] = sorted(
@@ -340,9 +328,7 @@ def _parametrize_cls(module, cls):
for arg, val in zip(argname_split, param.values):
cls_variables[arg] = val
parametrized_name = "_".join(
- # token is a string, but in py2k pytest is giving us a unicode,
- # so call str() on it.
- str(re.sub(r"\W", "", token))
+ re.sub(r"\W", "", token)
for param in full_param_set
for token in param.id.split("-")
)
@@ -457,14 +443,8 @@ def setup_class_methods(request):
if hasattr(cls, "setup_test_class"):
asyncio._maybe_async(cls.setup_test_class)
- if py2k:
- reinvent_fixtures_py2k.run_class_fixture_setup(request)
-
yield
- if py2k:
- reinvent_fixtures_py2k.run_class_fixture_teardown(request)
-
if hasattr(cls, "teardown_test_class"):
asyncio._maybe_async(cls.teardown_test_class)
@@ -484,9 +464,7 @@ def setup_test_methods(request):
# 1. function level "autouse" fixtures under py3k (examples: TablesTest
# define tables / data, MappedTest define tables / mappers / data)
- # 2. run homegrown function level "autouse" fixtures under py2k
- if py2k:
- reinvent_fixtures_py2k.run_fn_fixture_setup(request)
+ # 2. was for p2k. no longer applies
# 3. run outer xdist-style setup
if hasattr(self, "setup_test"):
@@ -529,9 +507,7 @@ def setup_test_methods(request):
if hasattr(self, "teardown_test"):
asyncio._maybe_async(self.teardown_test)
- # 11. run homegrown function-level "autouse" fixtures under py2k
- if py2k:
- reinvent_fixtures_py2k.run_fn_fixture_teardown(request)
+ # 11. was for p2k. no longer applies
# 12. function level "autouse" fixtures under py3k (examples: TablesTest /
# MappedTest delete table data, possibly drop tables and clear mappers
@@ -778,17 +754,8 @@ class PytestFixtureFunctions(plugin_base.FixtureFunctions):
fn = asyncio._maybe_async_wrapper(fn)
# other wrappers may be added here
- if py2k and "autouse" in kw:
- # py2k workaround for too-slow collection of autouse fixtures
- # in pytest 4.6.11. See notes in reinvent_fixtures_py2k for
- # rationale.
-
- # comment this condition out in order to disable the
- # py2k workaround entirely.
- reinvent_fixtures_py2k.add_fixture(fn, fixture)
- else:
- # now apply FixtureFunctionMarker
- fn = fixture(fn)
+ # now apply FixtureFunctionMarker
+ fn = fixture(fn)
return fn
diff --git a/lib/sqlalchemy/testing/plugin/reinvent_fixtures_py2k.py b/lib/sqlalchemy/testing/plugin/reinvent_fixtures_py2k.py
deleted file mode 100644
index 36b68417b..000000000
--- a/lib/sqlalchemy/testing/plugin/reinvent_fixtures_py2k.py
+++ /dev/null
@@ -1,112 +0,0 @@
-"""
-invent a quick version of pytest autouse fixtures as pytest's unacceptably slow
-collection/high memory use in pytest 4.6.11, which is the highest version that
-works in py2k.
-
-by "too-slow" we mean the test suite can't even manage to be collected for a
-single process in less than 70 seconds or so and memory use seems to be very
-high as well. for two or four workers the job just times out after ten
-minutes.
-
-so instead we have invented a very limited form of these fixtures, as our
-current use of "autouse" fixtures are limited to those in fixtures.py.
-
-assumptions for these fixtures:
-
-1. we are only using "function" or "class" scope
-
-2. the functions must be associated with a test class
-
-3. the fixture functions cannot themselves use pytest fixtures
-
-4. the fixture functions must use yield, not return
-
-When py2k support is removed and we can stay on a modern pytest version, this
-can all be removed.
-
-
-"""
-import collections
-
-
-_py2k_fixture_fn_names = collections.defaultdict(set)
-_py2k_class_fixtures = collections.defaultdict(
- lambda: collections.defaultdict(set)
-)
-_py2k_function_fixtures = collections.defaultdict(
- lambda: collections.defaultdict(set)
-)
-
-_py2k_cls_fixture_stack = []
-_py2k_fn_fixture_stack = []
-
-
-def add_fixture(fn, fixture):
- assert fixture.scope in ("class", "function")
- _py2k_fixture_fn_names[fn.__name__].add((fn, fixture.scope))
-
-
-def scan_for_fixtures_to_use_for_class(item):
- test_class = item.parent.parent.obj
-
- for name in _py2k_fixture_fn_names:
- for fixture_fn, scope in _py2k_fixture_fn_names[name]:
- meth = getattr(test_class, name, None)
- if meth and meth.im_func is fixture_fn:
- for sup in test_class.__mro__:
- if name in sup.__dict__:
- if scope == "class":
- _py2k_class_fixtures[test_class][sup].add(meth)
- elif scope == "function":
- _py2k_function_fixtures[test_class][sup].add(meth)
- break
- break
-
-
-def run_class_fixture_setup(request):
-
- cls = request.cls
- self = cls.__new__(cls)
-
- fixtures_for_this_class = _py2k_class_fixtures.get(cls)
-
- if fixtures_for_this_class:
- for sup_ in cls.__mro__:
- for fn in fixtures_for_this_class.get(sup_, ()):
- iter_ = fn(self)
- next(iter_)
-
- _py2k_cls_fixture_stack.append(iter_)
-
-
-def run_class_fixture_teardown(request):
- while _py2k_cls_fixture_stack:
- iter_ = _py2k_cls_fixture_stack.pop(-1)
- try:
- next(iter_)
- except StopIteration:
- pass
-
-
-def run_fn_fixture_setup(request):
- cls = request.cls
- self = request.instance
-
- fixtures_for_this_class = _py2k_function_fixtures.get(cls)
-
- if fixtures_for_this_class:
- for sup_ in reversed(cls.__mro__):
- for fn in fixtures_for_this_class.get(sup_, ()):
- iter_ = fn(self)
- next(iter_)
-
- _py2k_fn_fixture_stack.append(iter_)
-
-
-def run_fn_fixture_teardown(request):
- while _py2k_fn_fixture_stack:
- iter_ = _py2k_fn_fixture_stack.pop(-1)
- try:
- next(iter_)
- except StopIteration:
- pass
diff --git a/lib/sqlalchemy/testing/requirements.py b/lib/sqlalchemy/testing/requirements.py
index 3cf5c853e..8b385b5d2 100644
--- a/lib/sqlalchemy/testing/requirements.py
+++ b/lib/sqlalchemy/testing/requirements.py
@@ -1218,45 +1218,6 @@ class SuiteRequirements(Requirements):
return exclusions.only_if(check)
@property
- def python2(self):
- return exclusions.skip_if(
- lambda: sys.version_info >= (3,),
- "Python version 2.xx is required.",
- )
-
- @property
- def python3(self):
- return exclusions.skip_if(
- lambda: sys.version_info < (3,), "Python version 3.xx is required."
- )
-
- @property
- def pep520(self):
- return self.python36
-
- @property
- def insert_order_dicts(self):
- return self.python37
-
- @property
- def python36(self):
- return exclusions.skip_if(
- lambda: sys.version_info < (3, 6),
- "Python version 3.6 or greater is required.",
- )
-
- @property
- def python37(self):
- return exclusions.skip_if(
- lambda: sys.version_info < (3, 7),
- "Python version 3.7 or greater is required.",
- )
-
- @property
- def dataclasses(self):
- return self.python37
-
- @property
def cpython(self):
return exclusions.only_if(
lambda: util.cpython, "cPython interpreter needed"
diff --git a/lib/sqlalchemy/testing/suite/test_dialect.py b/lib/sqlalchemy/testing/suite/test_dialect.py
index c2c17d0dd..32dfdedad 100644
--- a/lib/sqlalchemy/testing/suite/test_dialect.py
+++ b/lib/sqlalchemy/testing/suite/test_dialect.py
@@ -19,7 +19,6 @@ from ... import Integer
from ... import literal_column
from ... import select
from ... import String
-from ...util import compat
class ExceptionTest(fixtures.TablesTest):
@@ -77,12 +76,7 @@ class ExceptionTest(fixtures.TablesTest):
assert str(err.orig) in str(err)
- # test that we are actually getting string on Py2k, unicode
- # on Py3k.
- if compat.py2k:
- assert isinstance(err_str, str)
- else:
- assert isinstance(err_str, str)
+ assert isinstance(err_str, str)
class IsolationLevelTest(fixtures.TestBase):
diff --git a/lib/sqlalchemy/testing/suite/test_types.py b/lib/sqlalchemy/testing/suite/test_types.py
index 22b85f398..93d37d4d5 100644
--- a/lib/sqlalchemy/testing/suite/test_types.py
+++ b/lib/sqlalchemy/testing/suite/test_types.py
@@ -873,8 +873,11 @@ class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest):
("numeric", 1234567.89),
# this one "works" because the float value you see here is
# lost immediately to floating point stuff
- ("numeric", 99998969694839.983485848, requirements.python3),
- ("numeric", 99939.983485848, requirements.python3),
+ (
+ "numeric",
+ 99998969694839.983485848,
+ ),
+ ("numeric", 99939.983485848),
("_decimal", decimal.Decimal("1234567.89")),
(
"_decimal",
@@ -991,8 +994,7 @@ class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest):
roundtrip = conn.scalar(select(expr))
eq_(roundtrip, compare_value)
- if util.py3k: # skip py2k to avoid comparing unicode to str etc.
- is_(type(roundtrip), type(compare_value))
+ is_(type(roundtrip), type(compare_value))
@_index_fixtures(True)
@testing.emits_warning(r".*does \*not\* support Decimal objects natively")
diff --git a/lib/sqlalchemy/testing/suite/test_unicode_ddl.py b/lib/sqlalchemy/testing/suite/test_unicode_ddl.py
index a4ae3348e..1334eb8db 100644
--- a/lib/sqlalchemy/testing/suite/test_unicode_ddl.py
+++ b/lib/sqlalchemy/testing/suite/test_unicode_ddl.py
@@ -6,7 +6,6 @@ from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy import MetaData
from sqlalchemy import testing
-from sqlalchemy import util
from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures
from sqlalchemy.testing.schema import Column
@@ -183,24 +182,12 @@ class UnicodeSchemaTest(fixtures.TablesTest):
t = Table(
ue("\u6e2c\u8a66"), meta, Column(ue("\u6e2c\u8a66_id"), Integer)
)
-
- if util.py2k:
- eq_(
- repr(t),
- (
- "Table('\\u6e2c\\u8a66', MetaData(), "
- "Column('\\u6e2c\\u8a66_id', Integer(), "
- "table=<\u6e2c\u8a66>), "
- "schema=None)"
- ),
- )
- else:
- eq_(
- repr(t),
- (
- "Table('測試', MetaData(), "
- "Column('測試_id', Integer(), "
- "table=<測試>), "
- "schema=None)"
- ),
- )
+ eq_(
+ repr(t),
+ (
+ "Table('測試', MetaData(), "
+ "Column('測試_id', Integer(), "
+ "table=<測試>), "
+ "schema=None)"
+ ),
+ )
diff --git a/lib/sqlalchemy/testing/util.py b/lib/sqlalchemy/testing/util.py
index a4d55a8f2..982e57517 100644
--- a/lib/sqlalchemy/testing/util.py
+++ b/lib/sqlalchemy/testing/util.py
@@ -27,7 +27,6 @@ from ..util import decorator
from ..util import defaultdict
from ..util import has_refcount_gc
from ..util import inspect_getfullargspec
-from ..util import py2k
if not has_refcount_gc:
@@ -47,14 +46,6 @@ else:
def picklers():
picklers = set()
- if py2k:
- try:
- import cPickle
-
- picklers.add(cPickle)
- except ImportError:
- pass
-
import pickle
picklers.add(pickle)
@@ -65,19 +56,8 @@ def picklers():
yield pickle_.loads, lambda d: pickle_.dumps(d, protocol)
-if py2k:
-
- def random_choices(population, k=1):
- pop = list(population)
- # lame but works :)
- random.shuffle(pop)
- return pop[0:k]
-
-
-else:
-
- def random_choices(population, k=1):
- return random.choices(population, k=k)
+def random_choices(population, k=1):
+ return random.choices(population, k=k)
def round_decimal(value, prec):