-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove most of qiskit.test
#11445
Remove most of qiskit.test
#11445
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,68 +13,12 @@ | |
|
||
"""Decorator for using with Qiskit unit tests.""" | ||
|
||
import collections.abc | ||
import functools | ||
import socket | ||
import sys | ||
from typing import Union, Callable, Type, Iterable | ||
import os | ||
import unittest | ||
from typing import Union, Callable, Type, Iterable | ||
|
||
from qiskit.utils import wrap_method | ||
from .testing_options import get_test_options | ||
|
||
HAS_NET_CONNECTION = None | ||
|
||
|
||
def _has_connection(hostname, port): | ||
"""Checks if internet connection exists to host via specified port. | ||
|
||
If any exception is raised while trying to open a socket this will return | ||
false. | ||
|
||
Args: | ||
hostname (str): Hostname to connect to. | ||
port (int): Port to connect to | ||
|
||
Returns: | ||
bool: Has connection or not | ||
|
||
""" | ||
try: | ||
host = socket.gethostbyname(hostname) | ||
socket.create_connection((host, port), 2).close() | ||
return True | ||
except Exception: # pylint: disable=broad-except | ||
return False | ||
|
||
|
||
def is_aer_provider_available(): | ||
"""Check if the C++ simulator can be instantiated. | ||
|
||
Returns: | ||
bool: True if simulator executable is available | ||
""" | ||
# TODO: HACK FROM THE DEPTHS OF DESPAIR AS AER DOES NOT WORK ON MAC | ||
if sys.platform == "darwin": | ||
return False | ||
try: | ||
import qiskit.providers.aer # pylint: disable=unused-import | ||
except ImportError: | ||
return False | ||
return True | ||
|
||
|
||
def requires_aer_provider(test_item): | ||
"""Decorator that skips test if qiskit aer provider is not available | ||
|
||
Args: | ||
test_item (callable): function or class to be decorated. | ||
|
||
Returns: | ||
callable: the decorated function. | ||
""" | ||
reason = "Aer provider not found, skipping test" | ||
return unittest.skipIf(not is_aer_provider_available(), reason)(test_item) | ||
|
||
|
||
def slow_test(func): | ||
|
@@ -89,10 +33,8 @@ def slow_test(func): | |
|
||
@functools.wraps(func) | ||
def _wrapper(*args, **kwargs): | ||
skip_slow = not TEST_OPTIONS["run_slow"] | ||
if skip_slow: | ||
if "run_slow" in os.environ.get("QISKIT_TESTS", ""): | ||
raise unittest.SkipTest("Skipping slow tests") | ||
|
||
return func(*args, **kwargs) | ||
|
||
return _wrapper | ||
|
@@ -192,31 +134,3 @@ def decorator(cls): | |
return cls | ||
|
||
return decorator | ||
|
||
|
||
class _TestOptions(collections.abc.Mapping): | ||
"""Lazy-loading view onto the test options retrieved from the environment.""" | ||
|
||
__slots__ = ("_options",) | ||
|
||
def __init__(self): | ||
self._options = None | ||
|
||
def _load(self): | ||
if self._options is None: | ||
self._options = get_test_options() | ||
|
||
def __getitem__(self, key): | ||
self._load() | ||
return self._options[key] | ||
|
||
def __iter__(self): | ||
self._load() | ||
return iter(self._options) | ||
|
||
def __len__(self): | ||
self._load() | ||
return len(self._options) | ||
|
||
|
||
TEST_OPTIONS = _TestOptions() | ||
Comment on lines
-197
to
-222
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inlined the one use of this still in use - checking if |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't used.