Skip to content
This repository has been archived by the owner on Mar 15, 2022. It is now read-only.

Commit

Permalink
move deprecated_test to _compat_test (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsung authored Apr 2, 2020
1 parent 0813351 commit 5e7e6ae
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
25 changes: 1 addition & 24 deletions openfermioncirq/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]):
Expand Down
24 changes: 23 additions & 1 deletion openfermioncirq/_compat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion openfermioncirq/gates/common_gates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion openfermioncirq/gates/three_qubit_gates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5e7e6ae

Please sign in to comment.