diff options
-rw-r--r-- | absl/BUILD | 17 | ||||
-rw-r--r-- | absl/testing/BUILD | 5 | ||||
-rw-r--r-- | absl/testing/_parameterized_async.py | 33 | ||||
-rw-r--r-- | absl/testing/parameterized.py | 17 |
4 files changed, 11 insertions, 61 deletions
@@ -21,23 +21,6 @@ py_library( visibility = ["//visibility:public"], ) -# NOTE: Because of how Bazel's Python support works, its possible (quite likely, -# actually) to be running Python 3 without this config setting being matched, -# so be careful about assuming or requiring it to match for a target to -# correctly work under Python 3. -# See: https://github.com/bazelbuild/bazel/issues/4815 -config_setting( - name = "py3_mode", - flag_values = {"@bazel_tools//tools/python:python_version": "PY3"}, - visibility = [":__subpackages__"], -) - -config_setting( - name = "py2_mode", - flag_values = {"@bazel_tools//tools/python:python_version": "PY2"}, - visibility = [":__subpackages__"], -) - py_library( name = "_collections_abc", srcs = ["_collections_abc.py"], diff --git a/absl/testing/BUILD b/absl/testing/BUILD index e63e966..d85b84c 100644 --- a/absl/testing/BUILD +++ b/absl/testing/BUILD @@ -30,10 +30,7 @@ py_library( name = "parameterized", srcs = [ "parameterized.py", - ] + select({ - "//absl:py2_mode": [], - "//absl:py3_mode": ["_parameterized_async.py"], - }), + ], srcs_version = "PY2AND3", visibility = ["//visibility:public"], deps = [ diff --git a/absl/testing/_parameterized_async.py b/absl/testing/_parameterized_async.py deleted file mode 100644 index 1dc32d2..0000000 --- a/absl/testing/_parameterized_async.py +++ /dev/null @@ -1,33 +0,0 @@ -# Lint as: python3 -# Copyright 2020 The Abseil Authors. -# -# 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. -"""Private module implementing async_wrapped method for wrapping async tests. - -This is a separate private module so that parameterized still optionally -supports Python 2 syntax. -""" - -import functools -import inspect - - -def async_wrapped(func): - @functools.wraps(func) - async def wrapper(*args, **kwargs): - return await func(*args, **kwargs) - return wrapper - - -def iscoroutinefunction(func): - return inspect.iscoroutinefunction(func) diff --git a/absl/testing/parameterized.py b/absl/testing/parameterized.py index c96d842..4d02c4e 100644 --- a/absl/testing/parameterized.py +++ b/absl/testing/parameterized.py @@ -209,6 +209,7 @@ from __future__ import division from __future__ import print_function import functools +import inspect import itertools import re import types @@ -218,10 +219,6 @@ from absl._collections_abc import abc from absl.testing import absltest import six -try: - from absl.testing import _parameterized_async -except (ImportError, SyntaxError): - _parameterized_async = None _ADDR_RE = re.compile(r'\<([a-zA-Z0-9_\-\.]+) object at 0x[a-fA-F0-9]+\>') _NAMED = object() @@ -265,6 +262,13 @@ def _format_parameter_list(testcase_params): return _format_parameter_list((testcase_params,)) +def _async_wrapped(func): + @functools.wraps(func) + async def wrapper(*args, **kwargs): + return await func(*args, **kwargs) + return wrapper + + class _ParameterizedTestIter(object): """Callable and iterable class for producing new test cases.""" @@ -369,9 +373,8 @@ class _ParameterizedTestIter(object): bound_param_test.__name__, _format_parameter_list(testcase_params)) if test_method.__doc__: bound_param_test.__doc__ += '\n%s' % (test_method.__doc__,) - if (_parameterized_async and - _parameterized_async.iscoroutinefunction(test_method)): - return _parameterized_async.async_wrapped(bound_param_test) + if inspect.iscoroutinefunction(test_method): + return _async_wrapped(bound_param_test) return bound_param_test return (make_bound_param_test(c) for c in self.testcases) |