Skip to content
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

Move tests outside src #209

Merged
merged 2 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ output-format = "colorized"
omit = ["src/qibojit/backends/clifford_operations*"]

[tool.pytest.ini_options]
testpaths = ['src/qibojit/tests/']
testpaths = ['tests/']
addopts = ['--cov=qibojit', '--cov-report=xml', '--cov-report=html']
env = ["D:NUMBA_DISABLE_JIT=1"]
2 changes: 1 addition & 1 deletion selfhosted
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

TMP_DIR=$(mktemp -d selfhosted.qibojit.XXXXXXX)

cp -r src/qibojit/tests "$TMP_DIR"
cp -r tests "$TMP_DIR"
cp pyproject.toml "$TMP_DIR/"
cd "$TMP_DIR/tests"

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/qibojit/tests/conftest.py → tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def pytest_addoption(parser):

@pytest.fixture
def backend(backend_name, request):
if request.config.getoption("--gpu-only"): # pragma: no cover
if request.config.getoption("--gpu-only"):
if backend_name not in ("cupy", "cuquantum"):
pytest.skip("Skipping non-gpu backend.")
yield BACKENDS.get(backend_name)()
Expand Down
7 changes: 3 additions & 4 deletions src/qibojit/tests/test_backends.py → tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
def test_device_setter(backend):
if backend.platform == "numba":
device = "/CPU:0"
else: # pragma: no cover
# CI does not have GPUs
else:
device = "/GPU:0"
backend.set_device(device)
assert backend.device == device
Expand Down Expand Up @@ -42,7 +41,7 @@ def test_sparse_cast(backend, array_type, format):
final = backend.to_numpy(backend.cast(sptarget))
target = sptarget.toarray()
backend.assert_allclose(final, target)
if backend.platform != "numba": # pragma: no cover
if backend.platform != "numba":
sptarget = getattr(backend.sparse, sptarget.__class__.__name__)(sptarget)
assert backend.is_sparse(sptarget)
final = backend.to_numpy(backend.cast(sptarget))
Expand All @@ -54,7 +53,7 @@ def test_to_numpy(backend):
target = backend.to_numpy(backend.cast(x))
if backend.platform == "numba":
final = backend.to_numpy(x)
else: # pragma: no cover
else:
final = backend.to_numpy(np.array(x))
backend.assert_allclose(final, target)

Expand Down
2 changes: 1 addition & 1 deletion src/qibojit/tests/test_gates.py → tests/test_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
random_unitary,
)

from qibojit.tests.utils import qubits_tensor, random_complex, set_precision
from .utils import qubits_tensor, random_complex, set_precision

ATOL = {"complex64": 1e-4, "complex128": 1e-10}

Expand Down
8 changes: 4 additions & 4 deletions src/qibojit/tests/test_ops.py → tests/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from qibo.quantum_info import random_density_matrix, random_statevector

from qibojit.tests.utils import qubits_tensor, random_complex, set_precision
from .utils import qubits_tensor, random_complex, set_precision


@pytest.mark.parametrize("is_matrix", [False, True])
Expand Down Expand Up @@ -112,7 +112,7 @@ def generate_transpose_qubits(nqubits):
@pytest.mark.parametrize("nqubits,qubits", CONFIG)
@pytest.mark.parametrize("ndevices", [2, 4, 8])
def test_transpose_state(backend, nqubits, qubits, ndevices, dtype):
if backend.platform != "numba": # pragma: no cover
if backend.platform != "numba":
pytest.skip(
f"``transpose_state`` op is not available for {backend.platform} platform."
)
Expand All @@ -133,7 +133,7 @@ def test_transpose_state(backend, nqubits, qubits, ndevices, dtype):

@pytest.mark.parametrize("nqubits,local", CONFIG)
def test_swap_pieces_zero_global(backend, nqubits, local, dtype):
if backend.platform != "numba": # pragma: no cover
if backend.platform != "numba":
pytest.skip(
f"``swap_pieces`` op is not available for {backend.platform} platform."
)
Expand Down Expand Up @@ -165,7 +165,7 @@ def test_swap_pieces_zero_global(backend, nqubits, local, dtype):

@pytest.mark.parametrize("nqubits,qlocal,qglobal", CONFIG)
def test_swap_pieces(backend, nqubits, qlocal, qglobal, dtype):
if backend.platform != "numba": # pragma: no cover
if backend.platform != "numba":
pytest.skip(
f"``swap_pieces`` op is not available for {backend.platform} platform."
)
Expand Down
File renamed without changes.