From 5e7e6ae9ad641e13710a99827384103d9173b8db Mon Sep 17 00:00:00 2001 From: "Kevin J. Sung" Date: Thu, 2 Apr 2020 13:40:58 -0700 Subject: [PATCH] move deprecated_test to _compat_test (#378) --- openfermioncirq/_compat.py | 25 +------------------ openfermioncirq/_compat_test.py | 24 +++++++++++++++++- openfermioncirq/gates/common_gates_test.py | 2 +- .../gates/three_qubit_gates_test.py | 2 +- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/openfermioncirq/_compat.py b/openfermioncirq/_compat.py index 2916ffed..d604feae 100644 --- a/openfermioncirq/_compat.py +++ b/openfermioncirq/_compat.py @@ -9,33 +9,10 @@ # 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. -from typing import Any, Callable, Dict, Tuple +from typing import Dict, Tuple from types import ModuleType -import functools import warnings -import pytest - - -def deprecated_test(test: Callable) -> Callable: - """Marks a test as using deprecated functionality. - - Ensures the test is executed within the `pytest.deprecated_call()` context. - - Args: - test: The test. - - Returns: - The decorated test. - """ - - @functools.wraps(test) - def decorated_test(*args, **kwargs) -> Any: - with pytest.deprecated_call(): - test(*args, **kwargs) - - return decorated_test - def wrap_module(module: ModuleType, deprecated_attributes: Dict[str, Tuple[str, str]]): diff --git a/openfermioncirq/_compat_test.py b/openfermioncirq/_compat_test.py index 336d63ec..05da00c4 100644 --- a/openfermioncirq/_compat_test.py +++ b/openfermioncirq/_compat_test.py @@ -9,13 +9,35 @@ # 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. +from typing import Any, Callable +import functools import warnings import pytest import deprecation import openfermioncirq as ofc -from openfermioncirq._compat import deprecated_test, wrap_module +from openfermioncirq._compat import wrap_module + + +def deprecated_test(test: Callable) -> Callable: + """Marks a test as using deprecated functionality. + + Ensures the test is executed within the `pytest.deprecated_call()` context. + + Args: + test: The test. + + Returns: + The decorated test. + """ + + @functools.wraps(test) + def decorated_test(*args, **kwargs) -> Any: + with pytest.deprecated_call(): + test(*args, **kwargs) + + return decorated_test @deprecation.deprecated() diff --git a/openfermioncirq/gates/common_gates_test.py b/openfermioncirq/gates/common_gates_test.py index fe4292f8..f6b78188 100644 --- a/openfermioncirq/gates/common_gates_test.py +++ b/openfermioncirq/gates/common_gates_test.py @@ -18,7 +18,7 @@ import cirq import openfermioncirq as ofc -from openfermioncirq._compat import deprecated_test +from openfermioncirq._compat_test import deprecated_test def test_fswap_interchangeable(): diff --git a/openfermioncirq/gates/three_qubit_gates_test.py b/openfermioncirq/gates/three_qubit_gates_test.py index 83ce71be..113feb5f 100644 --- a/openfermioncirq/gates/three_qubit_gates_test.py +++ b/openfermioncirq/gates/three_qubit_gates_test.py @@ -19,7 +19,7 @@ from cirq.testing import EqualsTester import openfermioncirq as ofc -from openfermioncirq._compat import deprecated_test +from openfermioncirq._compat_test import deprecated_test @deprecated_test